Unbreak --payload usage.
CL:175283 unfortunately broke devserver's --payload option. Fix this
by gracefully handling the case when we don't generate the payload
ourselves.
BUG=chromium:318557
TEST=Manually checked that './devserver.py --payload=<payload>' works again.
Change-Id: I2d20dcbab80e440072c1e4dba0b7e92c1f1879cd
Reviewed-on: https://chromium-review.googlesource.com/176614
Reviewed-by: Yu-Ju Hong <yjhong@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
diff --git a/autoupdate.py b/autoupdate.py
index c9f807d..fe930cb 100644
--- a/autoupdate.py
+++ b/autoupdate.py
@@ -533,15 +533,18 @@
@staticmethod
def _GetMetadataHash(payload_dir):
- """Gets the metadata hash.
+ """Gets the metadata hash, if it exists.
Args:
payload_dir: The payload directory.
Returns:
- The metadata hash, base-64 encoded.
+ The metadata hash, base-64 encoded or None if there is no metadata hash.
"""
path = os.path.join(payload_dir, constants.METADATA_HASH_FILE)
- return base64.b64encode(open(path, 'rb').read())
+ if os.path.exists(path):
+ return base64.b64encode(open(path, 'rb').read())
+ else:
+ return None
@staticmethod
def _GetMetadataSize(payload_filename):