{"action":"created","comment":{"url":"https://api.github.com/repos/shoopio/shoop/pulls/comments/32910142","id":32910142,"diff_hunk":"@@ -25,35 +26,66 @@\n JS_HEADER_LINES = JS_HEADER.encode('utf-8').splitlines()\n \n \n+def get_adders():\n+    return {\n+        '.py': add_header_to_python_file,\n+        '.js': add_header_to_javascript_file\n+    }\n+\n+\n def main():\n-    adders = [\n-        ('.py', add_header_to_python_file),\n-        ('.js', add_header_to_javascript_file),\n-    ]\n-    for (ext, adder) in adders:\n-        for path in find_files(ext):\n-            if os.stat(path).st_size == 0:\n-                print('%s: OK (Empty)' % (path,))\n-            elif not has_header(path):\n+    ap = argparse.ArgumentParser()\n+    ap.add_argument(\"root\", nargs=\"+\", help=\"Directory roots to recurse through\")\n+    ap.add_argument(\"-w\", \"--write\", help=\"Actually write changes\", action=\"store_true\")\n+    ap.add_argument(\"-v\", \"--verbose\", help=\"Log OK files too\", action=\"store_true\")\n+    args = ap.parse_args()\n+    paths = set()\n+    adders = get_adders()\n+    extensions = set(adders.keys())\n+    for root in args.root:\n+        paths |= set(find_files(root, extensions))\n+\n+    width = max(len(s) for s in paths)\n+\n+    for path in sorted(paths):\n+        if os.stat(path).st_size == 0:\n+            if args.verbose:\n+                print('[+]:%-*s: File is empty' % (width, path))\n+        elif not has_header(path):\n+            if args.write:\n+                adder = adders[os.path.splitext(path)[1]]\n                 adder(path)\n-                print('%s: Modified' % (path,))\n+                print('[!]:%-*s: Modified' % (width, path))\n             else:\n-                print('%s: OK' % (path,))\n+                print('[!]:%-*s: Requires license header' % (width, path))\n+        else:\n+            if args.verbose:\n+                print('[+]:%-*s: File has license header' % (width, path))\n \n \n-def find_files(extension):\n-    for (path, dirnames, filenames) in os.walk('.'):\n+def find_files(root, extensions):\n+    for (path, dirnames, filenames) in os.walk(root):\n+        dirnames[:] = [\n+            dirname for dirname in dirnames if not is_file_ignored(os.path.join(path, dirname))\n+            ]\n         for filename in filenames:\n-            if filename.endswith(extension):\n+            if any(filename.endswith(extension) for extension in extensions):\n                 filepath = os.path.join(path, filename)\n                 if not is_file_ignored(filepath):\n                     yield filepath\n \n \n def is_file_ignored(filepath):\n+    filepath = filepath.replace(os.sep, \"/\")\n     return (\n+        ('.git' in filepath) or\n+        ('venv' in filepath) or\n+        ('__pycache__' in filepath) or\n         ('vendor' in filepath) or\n-        os.path.join('doc', '_ext', 'djangodocs.py') in filepath)\n+        ('node_modules' in filepath) or\n+        ('bower_components' in filepath) or\n+        'doc/_ext/djangodocs.py' in filepath","path":"_misc/ensure_license_headers.py","position":85,"original_position":85,"commit_id":"c0d03d8e8159754c635843a58ddd73c7ab7c58e7","original_commit_id":"c0d03d8e8159754c635843a58ddd73c7ab7c58e7","user":{"login":"suutari-ai","id":3531281,"avatar_url":"https://avatars.githubusercontent.com/u/3531281?v=3","gravatar_id":"","url":"https://api.github.com/users/suutari-ai","html_url":"https://github.com/suutari-ai","followers_url":"https://api.github.com/users/suutari-ai/followers","following_url":"https://api.github.com/users/suutari-ai/following{/other_user}","gists_url":"https://api.github.com/users/suutari-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/suutari-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suutari-ai/subscriptions","organizations_url":"https://api.github.com/users/suutari-ai/orgs","repos_url":"https://api.github.com/users/suutari-ai/repos","events_url":"https://api.github.com/users/suutari-ai/events{/privacy}","received_events_url":"https://api.github.com/users/suutari-ai/received_events","type":"User","site_admin":false},"body":"why all others are in parenthesis, but this is not?","created_at":"2015-06-22T07:26:41Z","updated_at":"2015-06-22T07:26:41Z","html_url":"https://github.com/shoopio/shoop/pull/18#discussion_r32910142","pull_request_url":"https://api.github.com/repos/shoopio/shoop/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/comments/32910142"},"html":{"href":"https://github.com/shoopio/shoop/pull/18#discussion_r32910142"},"pull_request":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/shoopio/shoop/pulls/18","id":37887311,"html_url":"https://github.com/shoopio/shoop/pull/18","diff_url":"https://github.com/shoopio/shoop/pull/18.diff","patch_url":"https://github.com/shoopio/shoop/pull/18.patch","issue_url":"https://api.github.com/repos/shoopio/shoop/issues/18","number":18,"state":"open","locked":false,"title":"Improve `ensure_license_headers`","user":{"login":"akx","id":58669,"avatar_url":"https://avatars.githubusercontent.com/u/58669?v=3","gravatar_id":"","url":"https://api.github.com/users/akx","html_url":"https://github.com/akx","followers_url":"https://api.github.com/users/akx/followers","following_url":"https://api.github.com/users/akx/following{/other_user}","gists_url":"https://api.github.com/users/akx/gists{/gist_id}","starred_url":"https://api.github.com/users/akx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akx/subscriptions","organizations_url":"https://api.github.com/users/akx/orgs","repos_url":"https://api.github.com/users/akx/repos","events_url":"https://api.github.com/users/akx/events{/privacy}","received_events_url":"https://api.github.com/users/akx/received_events","type":"User","site_admin":false},"body":"* Faster file discovery\r\n* Better output\r\n* Dry-run by default","created_at":"2015-06-17T10:43:15Z","updated_at":"2015-06-22T07:26:41Z","closed_at":null,"merged_at":null,"merge_commit_sha":"31fa5cf596a6431cbcfac663da8ef3cda1cfc678","assignee":{"login":"suutari-ai","id":3531281,"avatar_url":"https://avatars.githubusercontent.com/u/3531281?v=3","gravatar_id":"","url":"https://api.github.com/users/suutari-ai","html_url":"https://github.com/suutari-ai","followers_url":"https://api.github.com/users/suutari-ai/followers","following_url":"https://api.github.com/users/suutari-ai/following{/other_user}","gists_url":"https://api.github.com/users/suutari-ai/gists{/gist_id}","starred_url":"https://api.github.com/users/suutari-ai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/suutari-ai/subscriptions","organizations_url":"https://api.github.com/users/suutari-ai/orgs","repos_url":"https://api.github.com/users/suutari-ai/repos","events_url":"https://api.github.com/users/suutari-ai/events{/privacy}","received_events_url":"https://api.github.com/users/suutari-ai/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/shoopio/shoop/pulls/18/commits","review_comments_url":"https://api.github.com/repos/shoopio/shoop/pulls/18/comments","review_comment_url":"https://api.github.com/repos/shoopio/shoop/pulls/comments{/number}","comments_url":"https://api.github.com/repos/shoopio/shoop/issues/18/comments","statuses_url":"https://api.github.com/repos/shoopio/shoop/statuses/c0d03d8e8159754c635843a58ddd73c7ab7c58e7","head":{"label":"akx:embetter-licenser","ref":"embetter-licenser","sha":"c0d03d8e8159754c635843a58ddd73c7ab7c58e7","user":{"login":"akx","id":58669,"avatar_url":"https://avatars.githubusercontent.com/u/58669?v=3","gravatar_id":"","url":"https://api.github.com/users/akx","html_url":"https://github.com/akx","followers_url":"https://api.github.com/users/akx/followers","following_url":"https://api.github.com/users/akx/following{/other_user}","gists_url":"https://api.github.com/users/akx/gists{/gist_id}","starred_url":"https://api.github.com/users/akx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akx/subscriptions","organizations_url":"https://api.github.com/users/akx/orgs","repos_url":"https://api.github.com/users/akx/repos","events_url":"https://api.github.com/users/akx/events{/privacy}","received_events_url":"https://api.github.com/users/akx/received_events","type":"User","site_admin":false},"repo":{"id":37119193,"name":"shoop","full_name":"akx/shoop","owner":{"login":"akx","id":58669,"avatar_url":"https://avatars.githubusercontent.com/u/58669?v=3","gravatar_id":"","url":"https://api.github.com/users/akx","html_url":"https://github.com/akx","followers_url":"https://api.github.com/users/akx/followers","following_url":"https://api.github.com/users/akx/following{/other_user}","gists_url":"https://api.github.com/users/akx/gists{/gist_id}","starred_url":"https://api.github.com/users/akx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akx/subscriptions","organizations_url":"https://api.github.com/users/akx/orgs","repos_url":"https://api.github.com/users/akx/repos","events_url":"https://api.github.com/users/akx/events{/privacy}","received_events_url":"https://api.github.com/users/akx/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/akx/shoop","description":"","fork":true,"url":"https://api.github.com/repos/akx/shoop","forks_url":"https://api.github.com/repos/akx/shoop/forks","keys_url":"https://api.github.com/repos/akx/shoop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/akx/shoop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/akx/shoop/teams","hooks_url":"https://api.github.com/repos/akx/shoop/hooks","issue_events_url":"https://api.github.com/repos/akx/shoop/issues/events{/number}","events_url":"https://api.github.com/repos/akx/shoop/events","assignees_url":"https://api.github.com/repos/akx/shoop/assignees{/user}","branches_url":"https://api.github.com/repos/akx/shoop/branches{/branch}","tags_url":"https://api.github.com/repos/akx/shoop/tags","blobs_url":"https://api.github.com/repos/akx/shoop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/akx/shoop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/akx/shoop/git/refs{/sha}","trees_url":"https://api.github.com/repos/akx/shoop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/akx/shoop/statuses/{sha}","languages_url":"https://api.github.com/repos/akx/shoop/languages","stargazers_url":"https://api.github.com/repos/akx/shoop/stargazers","contributors_url":"https://api.github.com/repos/akx/shoop/contributors","subscribers_url":"https://api.github.com/repos/akx/shoop/subscribers","subscription_url":"https://api.github.com/repos/akx/shoop/subscription","commits_url":"https://api.github.com/repos/akx/shoop/commits{/sha}","git_commits_url":"https://api.github.com/repos/akx/shoop/git/commits{/sha}","comments_url":"https://api.github.com/repos/akx/shoop/comments{/number}","issue_comment_url":"https://api.github.com/repos/akx/shoop/issues/comments{/number}","contents_url":"https://api.github.com/repos/akx/shoop/contents/{+path}","compare_url":"https://api.github.com/repos/akx/shoop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/akx/shoop/merges","archive_url":"https://api.github.com/repos/akx/shoop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/akx/shoop/downloads","issues_url":"https://api.github.com/repos/akx/shoop/issues{/number}","pulls_url":"https://api.github.com/repos/akx/shoop/pulls{/number}","milestones_url":"https://api.github.com/repos/akx/shoop/milestones{/number}","notifications_url":"https://api.github.com/repos/akx/shoop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/akx/shoop/labels{/name}","releases_url":"https://api.github.com/repos/akx/shoop/releases{/id}","created_at":"2015-06-09T08:11:10Z","updated_at":"2015-06-09T08:11:11Z","pushed_at":"2015-06-22T07:18:31Z","git_url":"git://github.com/akx/shoop.git","ssh_url":"git@github.com:akx/shoop.git","clone_url":"https://github.com/akx/shoop.git","svn_url":"https://github.com/akx/shoop","homepage":null,"size":1672,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"shoopio:master","ref":"master","sha":"f1b9bcffe12e208f63b5f088e33b05cc74a00192","user":{"login":"shoopio","id":12714852,"avatar_url":"https://avatars.githubusercontent.com/u/12714852?v=3","gravatar_id":"","url":"https://api.github.com/users/shoopio","html_url":"https://github.com/shoopio","followers_url":"https://api.github.com/users/shoopio/followers","following_url":"https://api.github.com/users/shoopio/following{/other_user}","gists_url":"https://api.github.com/users/shoopio/gists{/gist_id}","starred_url":"https://api.github.com/users/shoopio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoopio/subscriptions","organizations_url":"https://api.github.com/users/shoopio/orgs","repos_url":"https://api.github.com/users/shoopio/repos","events_url":"https://api.github.com/users/shoopio/events{/privacy}","received_events_url":"https://api.github.com/users/shoopio/received_events","type":"Organization","site_admin":false},"repo":{"id":36803364,"name":"shoop","full_name":"shoopio/shoop","owner":{"login":"shoopio","id":12714852,"avatar_url":"https://avatars.githubusercontent.com/u/12714852?v=3","gravatar_id":"","url":"https://api.github.com/users/shoopio","html_url":"https://github.com/shoopio","followers_url":"https://api.github.com/users/shoopio/followers","following_url":"https://api.github.com/users/shoopio/following{/other_user}","gists_url":"https://api.github.com/users/shoopio/gists{/gist_id}","starred_url":"https://api.github.com/users/shoopio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shoopio/subscriptions","organizations_url":"https://api.github.com/users/shoopio/orgs","repos_url":"https://api.github.com/users/shoopio/repos","events_url":"https://api.github.com/users/shoopio/events{/privacy}","received_events_url":"https://api.github.com/users/shoopio/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/shoopio/shoop","description":"","fork":false,"url":"https://api.github.com/repos/shoopio/shoop","forks_url":"https://api.github.com/repos/shoopio/shoop/forks","keys_url":"https://api.github.com/repos/shoopio/shoop/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shoopio/shoop/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shoopio/shoop/teams","hooks_url":"https://api.github.com/repos/shoopio/shoop/hooks","issue_events_url":"https://api.github.com/repos/shoopio/shoop/issues/events{/number}","events_url":"https://api.github.com/repos/shoopio/shoop/events","assignees_url":"https://api.github.com/repos/shoopio/shoop/assignees{/user}","branches_url":"https://api.github.com/repos/shoopio/shoop/branches{/branch}","tags_url":"https://api.github.com/repos/shoopio/shoop/tags","blobs_url":"https://api.github.com/repos/shoopio/shoop/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shoopio/shoop/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shoopio/shoop/git/refs{/sha}","trees_url":"https://api.github.com/repos/shoopio/shoop/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shoopio/shoop/statuses/{sha}","languages_url":"https://api.github.com/repos/shoopio/shoop/languages","stargazers_url":"https://api.github.com/repos/shoopio/shoop/stargazers","contributors_url":"https://api.github.com/repos/shoopio/shoop/contributors","subscribers_url":"https://api.github.com/repos/shoopio/shoop/subscribers","subscription_url":"https://api.github.com/repos/shoopio/shoop/subscription","commits_url":"https://api.github.com/repos/shoopio/shoop/commits{/sha}","git_commits_url":"https://api.github.com/repos/shoopio/shoop/git/commits{/sha}","comments_url":"https://api.github.com/repos/shoopio/shoop/comments{/number}","issue_comment_url":"https://api.github.com/repos/shoopio/shoop/issues/comments{/number}","contents_url":"https://api.github.com/repos/shoopio/shoop/contents/{+path}","compare_url":"https://api.github.com/repos/shoopio/shoop/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shoopio/shoop/merges","archive_url":"https://api.github.com/repos/shoopio/shoop/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shoopio/shoop/downloads","issues_url":"https://api.github.com/repos/shoopio/shoop/issues{/number}","pulls_url":"https://api.github.com/repos/shoopio/shoop/pulls{/number}","milestones_url":"https://api.github.com/repos/shoopio/shoop/milestones{/number}","notifications_url":"https://api.github.com/repos/shoopio/shoop/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shoopio/shoop/labels{/name}","releases_url":"https://api.github.com/repos/shoopio/shoop/releases{/id}","created_at":"2015-06-03T12:53:21Z","updated_at":"2015-06-17T18:03:14Z","pushed_at":"2015-06-22T07:18:31Z","git_url":"git://github.com/shoopio/shoop.git","ssh_url":"git@github.com:shoopio/shoop.git","clone_url":"https://github.com/shoopio/shoop.git","svn_url":"https://github.com/shoopio/shoop","homepage":null,"size":1889,"stargazers_count":20,"watchers_count":20,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":7,"forks":9,"open_issues":7,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/18"},"html":{"href":"https://github.com/shoopio/shoop/pull/18"},"issue":{"href":"https://api.github.com/repos/shoopio/shoop/issues/18"},"comments":{"href":"https://api.github.com/repos/shoopio/shoop/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/shoopio/shoop/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/shoopio/shoop/statuses/c0d03d8e8159754c635843a58ddd73c7ab7c58e7"}}}}