{"action":"created","comment":{"url":"https://api.github.com/repos/mitodl/xbundle/pulls/comments/30061947","id":30061947,"diff_hunk":"@@ -1,69 +1,72 @@\n #!/usr/bin/env python\n \n-\"\"\"\n-A command-line script to use xbundle.\n+\"\"\"xbundle_convert\n+\n+Description:\n+    Convert between OLX and xbundle XML formats.\n+    If the input format in an XML file, the output will be OLX.\n+    If the input format is a directory, the output will be xbundle.\n+\n+Usage:\n+    xbundle_convert convert [--force-studio] <input> <output>\n+    xbundle_convert test\n+    xbundle_convert --help | -h\n+    xbundle_convert --version\n+\n+Options:\n+    --force-studio  forces <sequential> to be followed by <vertical> in export\n+    -h --help       show this screen\n \"\"\"\n \n-import sys\n+# stdlib\n+from pkg_resources import get_distribution\n \n+# PyPi\n+from docopt import docopt\n+\n+# local\n from xbundle import XBundle, run_tests\n \n # pylint: disable=star-args\n \n-def usage():\n-    \"\"\"\n-    print usage\n-    \"\"\"\n-    print \"Usage: python xbundle.py [--force-studio] [cmd] [infn] [outfn]\"\n-    print \"where:\"\n-    print \"  cmd = test:    run unit tests\"\n-    print \"  cmd = convert: convert between xbundle and edX directory format\"\n-    print \"                 the xbundle filename must end with .xml\"\n-    print \"  --force-studio forces <sequential> to always be followed by <vertical> in export\"\n-    print \"                 this makes it compatible with Studio import\"\n-    print \"\"\n-    print \"examples:\"\n-    print \"  python xbundle.py convert ../data/edx4edx edx4edx_xbundle.xml\"\n-    print \"  python xbundle.py convert edx4edx_xbundle.xml ./\"\n-\n def main():\n     \"\"\"\n     Convert between OLX and xbundle XML formats.\n     \"\"\"\n-    if len(sys.argv) < 2:\n-        usage()\n-        sys.exit(0)\n+    # This parses the docstring above and derives all arguments.\n+    # If the required arguments are missing, it prints basic usage\n+    # and exits automatically.\n+    # If required arguments are satisfied, it returns a dict.\n+    args = docopt(__doc__)\n \n-    argc = 1\n     options = dict(keep_urls=True)\n-    if len(sys.argv) > argc and sys.argv[argc] == '--force-studio':\n-        argc += 1\n+    if args['--force-studio']:\n         options['force_studio_format'] = True\n \n-    cmd = sys.argv[argc]\n-\n-    if cmd == 'test':\n+    if args['test']:\n         run_tests()\n+        return\n+    if args['--version']:\n+        print \"xbundle {0}\".format(get_distribution(\"xbundle\").version)","path":"bin/xbundle_convert","position":78,"original_position":78,"commit_id":"db88dcafc6eb822a584f6c4451767d0589991ed5","original_commit_id":"db88dcafc6eb822a584f6c4451767d0589991ed5","user":{"login":"bdero","id":919017,"avatar_url":"https://avatars.githubusercontent.com/u/919017?v=3","gravatar_id":"","url":"https://api.github.com/users/bdero","html_url":"https://github.com/bdero","followers_url":"https://api.github.com/users/bdero/followers","following_url":"https://api.github.com/users/bdero/following{/other_user}","gists_url":"https://api.github.com/users/bdero/gists{/gist_id}","starred_url":"https://api.github.com/users/bdero/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bdero/subscriptions","organizations_url":"https://api.github.com/users/bdero/orgs","repos_url":"https://api.github.com/users/bdero/repos","events_url":"https://api.github.com/users/bdero/events{/privacy}","received_events_url":"https://api.github.com/users/bdero/received_events","type":"User","site_admin":false},"body":"Thanks for finding out how to get the version!\r\n\r\ndocopt can actually handle the version flag, so it isn't actually necessary to check the flag/print the version and exit:\r\n```python\r\nargs = docopt(\r\n    __doc__,\r\n    version=\"xbundle {}\".format(get_distribution(\"xbundle\").version)\r\n)\r\n```","created_at":"2015-05-11T17:35:31Z","updated_at":"2015-05-11T17:35:31Z","html_url":"https://github.com/mitodl/xbundle/pull/24#discussion_r30061947","pull_request_url":"https://api.github.com/repos/mitodl/xbundle/pulls/24","_links":{"self":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/comments/30061947"},"html":{"href":"https://github.com/mitodl/xbundle/pull/24#discussion_r30061947"},"pull_request":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/24"}}},"pull_request":{"url":"https://api.github.com/repos/mitodl/xbundle/pulls/24","id":35145740,"html_url":"https://github.com/mitodl/xbundle/pull/24","diff_url":"https://github.com/mitodl/xbundle/pull/24.diff","patch_url":"https://github.com/mitodl/xbundle/pull/24.patch","issue_url":"https://api.github.com/repos/mitodl/xbundle/issues/24","number":24,"state":"open","locked":false,"title":"replacing manual command-line parsing with docopt","user":{"login":"ShawnMilo","id":130120,"avatar_url":"https://avatars.githubusercontent.com/u/130120?v=3","gravatar_id":"","url":"https://api.github.com/users/ShawnMilo","html_url":"https://github.com/ShawnMilo","followers_url":"https://api.github.com/users/ShawnMilo/followers","following_url":"https://api.github.com/users/ShawnMilo/following{/other_user}","gists_url":"https://api.github.com/users/ShawnMilo/gists{/gist_id}","starred_url":"https://api.github.com/users/ShawnMilo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ShawnMilo/subscriptions","organizations_url":"https://api.github.com/users/ShawnMilo/orgs","repos_url":"https://api.github.com/users/ShawnMilo/repos","events_url":"https://api.github.com/users/ShawnMilo/events{/privacy}","received_events_url":"https://api.github.com/users/ShawnMilo/received_events","type":"User","site_admin":false},"body":"Updates based on comments by @bdero.","created_at":"2015-05-11T16:44:18Z","updated_at":"2015-05-11T17:35:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1f94fed1d65f81c04daed35971bc3d7156dfbfcd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mitodl/xbundle/pulls/24/commits","review_comments_url":"https://api.github.com/repos/mitodl/xbundle/pulls/24/comments","review_comment_url":"https://api.github.com/repos/mitodl/xbundle/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mitodl/xbundle/issues/24/comments","statuses_url":"https://api.github.com/repos/mitodl/xbundle/statuses/db88dcafc6eb822a584f6c4451767d0589991ed5","head":{"label":"mitodl:opts","ref":"opts","sha":"db88dcafc6eb822a584f6c4451767d0589991ed5","user":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":10563275,"name":"xbundle","full_name":"mitodl/xbundle","owner":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/xbundle","description":"xbundle tool for edX courses","fork":false,"url":"https://api.github.com/repos/mitodl/xbundle","forks_url":"https://api.github.com/repos/mitodl/xbundle/forks","keys_url":"https://api.github.com/repos/mitodl/xbundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/xbundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/xbundle/teams","hooks_url":"https://api.github.com/repos/mitodl/xbundle/hooks","issue_events_url":"https://api.github.com/repos/mitodl/xbundle/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/xbundle/events","assignees_url":"https://api.github.com/repos/mitodl/xbundle/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/xbundle/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/xbundle/tags","blobs_url":"https://api.github.com/repos/mitodl/xbundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/xbundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/xbundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/xbundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/xbundle/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/xbundle/languages","stargazers_url":"https://api.github.com/repos/mitodl/xbundle/stargazers","contributors_url":"https://api.github.com/repos/mitodl/xbundle/contributors","subscribers_url":"https://api.github.com/repos/mitodl/xbundle/subscribers","subscription_url":"https://api.github.com/repos/mitodl/xbundle/subscription","commits_url":"https://api.github.com/repos/mitodl/xbundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/xbundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/xbundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/xbundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/xbundle/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/xbundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/xbundle/merges","archive_url":"https://api.github.com/repos/mitodl/xbundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/xbundle/downloads","issues_url":"https://api.github.com/repos/mitodl/xbundle/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/xbundle/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/xbundle/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/xbundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/xbundle/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/xbundle/releases{/id}","created_at":"2013-06-08T03:41:41Z","updated_at":"2015-05-08T12:22:47Z","pushed_at":"2015-05-11T16:44:18Z","git_url":"git://github.com/mitodl/xbundle.git","ssh_url":"git@github.com:mitodl/xbundle.git","clone_url":"https://github.com/mitodl/xbundle.git","svn_url":"https://github.com/mitodl/xbundle","homepage":null,"size":417,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":0,"default_branch":"master"}},"base":{"label":"mitodl:master","ref":"master","sha":"4f57d5a4c7d9b7b1cf3f7ca80209248cc3bd9533","user":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"repo":{"id":10563275,"name":"xbundle","full_name":"mitodl/xbundle","owner":{"login":"mitodl","id":7918516,"avatar_url":"https://avatars.githubusercontent.com/u/7918516?v=3","gravatar_id":"","url":"https://api.github.com/users/mitodl","html_url":"https://github.com/mitodl","followers_url":"https://api.github.com/users/mitodl/followers","following_url":"https://api.github.com/users/mitodl/following{/other_user}","gists_url":"https://api.github.com/users/mitodl/gists{/gist_id}","starred_url":"https://api.github.com/users/mitodl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitodl/subscriptions","organizations_url":"https://api.github.com/users/mitodl/orgs","repos_url":"https://api.github.com/users/mitodl/repos","events_url":"https://api.github.com/users/mitodl/events{/privacy}","received_events_url":"https://api.github.com/users/mitodl/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mitodl/xbundle","description":"xbundle tool for edX courses","fork":false,"url":"https://api.github.com/repos/mitodl/xbundle","forks_url":"https://api.github.com/repos/mitodl/xbundle/forks","keys_url":"https://api.github.com/repos/mitodl/xbundle/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mitodl/xbundle/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mitodl/xbundle/teams","hooks_url":"https://api.github.com/repos/mitodl/xbundle/hooks","issue_events_url":"https://api.github.com/repos/mitodl/xbundle/issues/events{/number}","events_url":"https://api.github.com/repos/mitodl/xbundle/events","assignees_url":"https://api.github.com/repos/mitodl/xbundle/assignees{/user}","branches_url":"https://api.github.com/repos/mitodl/xbundle/branches{/branch}","tags_url":"https://api.github.com/repos/mitodl/xbundle/tags","blobs_url":"https://api.github.com/repos/mitodl/xbundle/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mitodl/xbundle/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mitodl/xbundle/git/refs{/sha}","trees_url":"https://api.github.com/repos/mitodl/xbundle/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mitodl/xbundle/statuses/{sha}","languages_url":"https://api.github.com/repos/mitodl/xbundle/languages","stargazers_url":"https://api.github.com/repos/mitodl/xbundle/stargazers","contributors_url":"https://api.github.com/repos/mitodl/xbundle/contributors","subscribers_url":"https://api.github.com/repos/mitodl/xbundle/subscribers","subscription_url":"https://api.github.com/repos/mitodl/xbundle/subscription","commits_url":"https://api.github.com/repos/mitodl/xbundle/commits{/sha}","git_commits_url":"https://api.github.com/repos/mitodl/xbundle/git/commits{/sha}","comments_url":"https://api.github.com/repos/mitodl/xbundle/comments{/number}","issue_comment_url":"https://api.github.com/repos/mitodl/xbundle/issues/comments{/number}","contents_url":"https://api.github.com/repos/mitodl/xbundle/contents/{+path}","compare_url":"https://api.github.com/repos/mitodl/xbundle/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mitodl/xbundle/merges","archive_url":"https://api.github.com/repos/mitodl/xbundle/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mitodl/xbundle/downloads","issues_url":"https://api.github.com/repos/mitodl/xbundle/issues{/number}","pulls_url":"https://api.github.com/repos/mitodl/xbundle/pulls{/number}","milestones_url":"https://api.github.com/repos/mitodl/xbundle/milestones{/number}","notifications_url":"https://api.github.com/repos/mitodl/xbundle/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mitodl/xbundle/labels{/name}","releases_url":"https://api.github.com/repos/mitodl/xbundle/releases{/id}","created_at":"2013-06-08T03:41:41Z","updated_at":"2015-05-08T12:22:47Z","pushed_at":"2015-05-11T16:44:18Z","git_url":"git://github.com/mitodl/xbundle.git","ssh_url":"git@github.com:mitodl/xbundle.git","clone_url":"https://github.com/mitodl/xbundle.git","svn_url":"https://github.com/mitodl/xbundle","homepage":null,"size":417,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":8,"forks":2,"open_issues":8,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/24"},"html":{"href":"https://github.com/mitodl/xbundle/pull/24"},"issue":{"href":"https://api.github.com/repos/mitodl/xbundle/issues/24"},"comments":{"href":"https://api.github.com/repos/mitodl/xbundle/issues/24/comments"},"review_comments":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/24/comments"},"review_comment":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mitodl/xbundle/pulls/24/commits"},"statuses":{"href":"https://api.github.com/repos/mitodl/xbundle/statuses/db88dcafc6eb822a584f6c4451767d0589991ed5"}}}}