-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
63 lines (53 loc) · 2.09 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# -- Unmaintained, please look at the notebook in this repository
# This is a less interactive version of the jupyter notebook,
# but essentially the same functionality
import requests
import json
import git
import string
import yaml
import os
from dbaccessor import DBAccessor
from pythonlinting import lint_file_or_project
def format_filename(s):
"""Take a string and return a valid filename constructed from it."""
valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
filename = ''.join(c for c in s if c in valid_chars)
filename = filename.replace(' ', '_') # I don't like spaces in filenames.
return filename
def main():
with open('config.yml', 'r') as cfg:
config = yaml.load(cfg)
db = DBAccessor(config)
ccandidates = db.get_candidates('cpp', 'python')
jcandidates = db.get_candidates('java', 'python')
candidates = ccandidates + jcandidates
print('{} candidates found.'.format(len(candidates)))
sample_projects = set()
for candidate in candidates:
projects = db.get_projects_for_user(candidate[0], 'python')
if projects:
sample_projects.update(projects)
print('{} projects for these candidates found.'
.format(len(sample_projects)))
token = config['github-token']
ghuser = config['github-user']
existing_projects = []
for project in sample_projects:
r = requests.get(project[0], auth=(ghuser, token))
obj = json.loads(r.text)
if 'clone_url' in obj.keys():
existing_projects.append((obj['clone_url'], project[1]))
print('{} projects are reachable.'
.format(len(existing_projects)))
print('Cloning repositories...')
for clone_url, name in existing_projects:
git.Repo.clone_from(clone_url, config['repo-dir'] +
format_filename(name))
print('Finished cloning.')
print('Linting projects:')
for project_dir in os.listdir(config['repo-dir']):
error_codes, num_files, num_lines = lint_file_or_project(project_dir)
print(error_codes)
if __name__ == '__main__':
main()