Skip to content

Instantly share code, notes, and snippets.

@zekroTJA
Last active May 4, 2018 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zekroTJA/74c8795e9fc07065a2cf854bb2d44c8d to your computer and use it in GitHub Desktop.
Save zekroTJA/74c8795e9fc07065a2cf854bb2d44c8d to your computer and use it in GitHub Desktop.
script to cloc all repositroies from a specific github user
--exclude-lang=XML,Markdown,JSON,TOML,YAML,"MSBuild script","Qt Project","Windows Resource File" --not-match-f \w+.Designer.cs
import urllib.request
import json
import subprocess
import os
CLONE_TO = './repos'
CLOC_ARGS_FILE = 'cloc_args.txt'
cloc_args = []
print('Please enter the name of the github user you want to cloc repos:')
user = input()
if os.path.isfile(CLOC_ARGS_FILE):
with open(CLOC_ARGS_FILE, 'r') as f:
cloc_args = f.read().split()
else:
print('Input cloc args:')
inpt_args = input()
if len(inpt_args) > 0:
with open(CLOC_ARGS_FILE, 'w') as f:
f.write(inpt_args)
cloc_args = inpt_args.split()
print('Cloc args: ' + ' '.join(cloc_args))
if len(user) < 1:
print('Please enter a valid user name!')
exit()
url = 'https://api.github.com/users/' + user + '/repos?type=owner&per_page=1000'
print('Requesting repositories from user %s...' % user)
req = urllib.request.urlopen(url)
data = json.loads(req.read())
repos = [r for r in data if not r['fork']]
print('Got %d repositories (forks excluded).\nNow cloning them into %s...' % (len(repos), CLONE_TO))
if not os.path.exists(CLONE_TO):
os.makedirs(CLONE_TO)
cloned = 1
for repo in repos:
print("\nCloning repo %d of %d..." % (cloned, len(repos)))
subprocess.call(['git', 'clone', repo['clone_url'], CLONE_TO + '/' + repo['name']])
cloned += 1
out = subprocess.check_output(['cloc', CLONE_TO] + cloc_args)
with open('result.txt', 'wb') as f:
f.write(out)
f.close()
print('\nFinished. Results written to file "result.txt".')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment