Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #1876 - Handles when data/milestones.json doesn't exist. #1878

Merged
merged 1 commit into from
Nov 16, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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