-
Notifications
You must be signed in to change notification settings - Fork 1
/
scan.py
78 lines (70 loc) · 2.32 KB
/
scan.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
file: readRepo.py
author: Ben Grawi <bjg1568@rit.edu>
date: October 2013
description: The base script to call
"""
from caslogging import logging
import sys
from datetime import datetime, timedelta
from commit import Commit
from repository import *
from metrics import *
from localrepository import *
logging.info('Starting CASReader')
# Read the first argument and pass it in as a string
if len(sys.argv) > 1:
arg = sys.argv[1]
else:
arg = ''
if arg == "initDb":
# Init the database
logging.info('Initializing the Database...')
Base.metadata.create_all(engine)
logging.info('Done')
elif arg == "testRepos":
logging.info('Making Test Repos')
# Make Test Repos
testRepos = [{'name':'Ghost',
'url':'https://github.com/TryGhost/Ghost.git',
'path':None,
'ingestion_date':None,
'analysis_date':None
},
{'name':'Bootstrap',
'url':'https://github.com/twbs/bootstrap.git',
'path':None,
'ingestion_date':None,
'analysis_date':None
},
]
session = Session()
for repo in testRepos:
session.merge(Repository(repo))
session.commit()
logging.info('Done.')
elif arg == '':
# No args, just do scan
logging.info('Starting Scan...')
repoSession = Session()
# Latest time to get new repo data (1 day ago)
refresh_date = str(datetime.utcnow() - timedelta(days=1))
# Get un-injested repos or repos not been updated since the refresh_date
reposToGet = (repoSession.query(Repository)
.filter( (Repository.ingestion_date==None) |
(Repository.ingestion_date < refresh_date)
)
.all()
)
#TODO: This: (downloading and parsing commit logs
if len(reposToGet) > 0:
for repo in reposToGet:
localRepo = LocalRepository(repo)
localRepo.sync()
repoSession.merge(repo)
repoSession.commit()
logging.info('Done, finished everything.')
else:
logging.info('Nothing to do. Done.')
else:
logging.error('Invalid Command')