Build versioning -- so we can rebuild if data version is updated
@@ -14,10 +14,30 @@ import requests
import shutil
-def built(path):
- """Checks if '.built' flag has been set for that task."""
+def built(path, version_string=None):
+ """Checks if '.built' flag has been set for that task.
+ If a version_string is provided, this has to match, or the version
+ is regarded as not built.
+ """
+ if version_string:
+ fname = os.path.join(path, '.built')
+ if not os.path.isfile(fname):
+ return False
+ else:
+ with open(fname, 'r') as read:
+ text = read.read().split('\n')
+ return (len(text) == 2 and text[1] == version_string)
+ else:
return os.path.isfile(os.path.join(path, '.built'))
+def mark_done(path, version_string=None):
+ """Marks the path as done by adding a '.built' file with the current
+ timestamp plus a version description string if specified.
+ """
+ with open(os.path.join(path, '.built'), 'w') as write:
+ write.write(str(datetime.datetime.today()))
+ if version_string:
+ write.write('\n' + version_string)
def log_progress(curr, total, width=40):
"""Displays a bar showing the current progress."""
@@ -65,14 +85,6 @@ def make_dir(path):
os.makedirs(path, exist_ok=True)
-def mark_done(path):
- """Marks the path as done by adding a '.built' file with the current
- timestamp.
- """
- with open(os.path.join(path, '.built'), 'w') as write:
- write.write(str(datetime.datetime.today()))
-
-
def move(path1, path2):
"""Renames the given file."""
shutil.move(path1, path2)
