Browse Source

allow for missing resource file

Change-Id: Iad0fcb07a942cadd6851196b52d640ebf4308f8c
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
Doug Hellmann 2 years ago
parent
commit
67134ff7f0
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      downpour/resources.py

+ 9
- 4
downpour/resources.py View File

@@ -19,7 +19,7 @@ import munch
19 19
 LOG = logging.getLogger(__name__)
20 20
 
21 21
 
22
-def load(filename):
22
+def load(filename, missing_ok=False):
23 23
     "Read the file and return the parsed data in a consistent format."
24 24
     LOG.info('loading resource list from %s', filename)
25 25
 
@@ -31,9 +31,14 @@ def load(filename):
31 31
         images=[],
32 32
     )
33 33
 
34
-    with open(filename, 'r', encoding='utf-8') as fd:
35
-        contents = munch.Munch.fromYAML(fd.read())
36
-    to_return.update(contents)
34
+    try:
35
+        with open(filename, 'r', encoding='utf-8') as fd:
36
+            contents = munch.Munch.fromYAML(fd.read())
37
+    except FileNotFoundError:
38
+        if not missing_ok:
39
+            raise
40
+    else:
41
+        to_return.update(contents)
37 42
 
38 43
     # Ensure all entries have consistent sets of keys so the rest of
39 44
     # the app doesn't have to check every time it wants to use a

Loading…
Cancel
Save