Permalink
Browse files

encapsulated program logic away from main

  • Loading branch information...
1 parent a934dfb commit c0230a7e257e395a056a08e053d608098d38cbad @brosner brosner committed Dec 6, 2009
Showing with 23 additions and 12 deletions.
  1. +23 −12 dev_release_builder.py
View
@@ -142,23 +142,23 @@ def build_release(user, repository, commit):
logger.indent -= 2
-def main():
- # setup
- if not os.path.exists(DATA_DIR):
- os.makedirs(DATA_DIR)
- if os.path.exists(WORK_DIR):
- shutil.rmtree(WORK_DIR)
- os.makedirs(WORK_DIR)
+def run(data_dir, work_dir, repositories_file, completed_file):
+ if not os.path.exists(data_dir):
+ os.makedirs(data_dir)
+
+ if os.path.exists(work_dir):
+ shutil.rmtree(work_dir)
+ os.makedirs(work_dir)
- repositories = read_repositories(REPOSITORIES_FILE)
+ repositories = read_repositories(repositories_file)
commits = []
for kind, user, repository in repositories:
if kind == "github":
head = find_head_github(user, repository)
commits.append((user, repository, head))
- completed = read_json_file(COMPLETED_FILE)
+ completed = read_json_file(completed_file)
completed_cache = dict([(c, True) for u, r, c in completed])
try:
@@ -178,10 +178,21 @@ def main():
completed.append((user, repository, commit))
logger.indent -= 2
finally:
- if os.path.exists(WORK_DIR):
- shutil.rmtree(WORK_DIR)
+ if os.path.exists(work_dir):
+ shutil.rmtree(work_dir)
+
+ dump_json_items(completed_file, completed)
+
+
+def main():
+
+ # @@@ optparse
+ data_dir = DATA_DIR
+ work_dir = WORK_DIR
+ repositories_file = REPOSITORIES_FILE
+ completed_file = COMPLETED_FILE
- dump_json_items(COMPLETED_FILE, completed)
+ run(data_dir, work_dir, repositories_file, completed_file)
if __name__ == "__main__":

0 comments on commit c0230a7

Please sign in to comment.