Skip to content

Commit

Permalink
Merge pull request #1878 from karlcow/1876/1
Browse files Browse the repository at this point in the history
Fixes #1876 - Handles when data/milestones.json doesn't exist.
  • Loading branch information
Mike Taylor authored Nov 16, 2017
2 parents 42cfdc2 + 6224d06 commit 0d8b423
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
from environment import * # nopep8
from secrets import * # nopep8

MILESTONE_ERROR = '''It failed with {msg}!
MILESTONE_ERROR = """It failed with {msg}!
We will read from data/milestones.json.
'''
"""
MILESTONE_MISSING_FILE = """Oooops.
We can't find {path}
Double check that everything is configured properly
in config/secrets.py and try again. Good luck!
"""


def initialize_status():
Expand Down Expand Up @@ -49,8 +54,7 @@ def initialize_status():
# Not working, let's use the cached copy
# This might fail the first time.
print(MILESTONE_ERROR.format(msg=error))
with open(milestones_path, 'r') as f:
milestones_content = f.read()
milestones_content = milestones_from_file(milestones_path)
finally:
# save in data/ the current version
if milestones_content:
Expand All @@ -62,6 +66,17 @@ def initialize_status():
return False


def milestones_from_file(milestones_path):
"""Attempt to read the milestones data from the filesystem."""
if os.path.isfile(milestones_path):
with open(milestones_path, 'r') as f:
milestones_content = f.read()
return milestones_content
else:
print(MILESTONE_MISSING_FILE.format(path=milestones_path))
return None


def convert_milestones(milestones_content):
"""Convert the JSON milestones from GitHub to a simple dict."""
milestone_full = json.loads(milestones_content)
Expand Down

0 comments on commit 0d8b423

Please sign in to comment.