From 8a2c44245e10cfc595ceb2d742373bc6678a34ec Mon Sep 17 00:00:00 2001 From: Anthony Gargiulo Date: Sat, 23 Jun 2012 15:48:44 -0400 Subject: [PATCH] moved the setup of the parser to a function --- github-backup.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/github-backup.py b/github-backup.py index a7a2763..bf16258 100755 --- a/github-backup.py +++ b/github-backup.py @@ -9,12 +9,8 @@ import os def main(): # A sane way to handle command line args. - parser = ArgumentParser(description="makes a local backup copy of all of a github user's repositories") - parser.add_argument("username", help="A Github username") - parser.add_argument("backupdir", help="The folder where you want your backups to go", default="./backups") - parser.add_argument("-v","--verbose", help="Produces more output", action="store_true") - # Now actually store the args + parser = init_parser() args = parser.parse_args() # Make the connection to Github here. @@ -22,10 +18,23 @@ def main(): # Get all of the given user's repos user_repos = gh.repos.list(args.username).all() - #print user_repos[0].__dict__ for repo in user_repos: - os.system('git clone {} {}/{}'.format(repo.git_url, args.backupdir, repo.name)) + process_repo(repo, args) + +def init_parser(): + """ + set up the argument parser + """ + parser = ArgumentParser( + description="makes a backup of all of a github user's repositories") + parser.add_argument("username", help="A Github username") + parser.add_argument("backupdir", + help="The folder where you want your backups to go") + parser.add_argument("-c","--cron", help="Use this when running from a cron job", + action="store_true") + return parser + + if __name__ == "__main__": main() - print("foobar")