From 50259703f19bdec23cfa2b9f07098661a928c370 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sat, 11 Feb 2017 13:29:20 +0800 Subject: manifest.py: Handle empty manifest file --- scripts/manifest.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/manifest.py b/scripts/manifest.py index 2bdb862..bee8e5c 100755 --- a/scripts/manifest.py +++ b/scripts/manifest.py @@ -31,6 +31,8 @@ class Manifest: self.filepath = filepath self.manifest = ruamel.yaml.load( open(filepath), Loader=ruamel.yaml.RoundTripLoader) + if self.manifest is None: + self.manifest = ruamel.yaml.comments.CommentedMap() def save(self): with open(self.filepath, "w") as f: @@ -43,9 +45,9 @@ class Manifest: If the specified item doesn't exist, raise a ``KeyError``. """ - try: + if key in self.manifest: return self.manifest[key] - except KeyError: + else: raise KeyError("manifest doesn't have item: '%s'" % key) def set(self, key, value): -- cgit v1.2.2