def update_repo(user, repo_name, working_date): repo = GitRepo(user, repo_name) repo.clone() repo.load_commits() doc = collection.find_one({'_id': '%s/%s' % (user, repo_name)}) if doc is None: raise Exception('%s/%s not in db!!!!!' % (user, repo_name)) popularity.run(repo, doc, working_date) for c in repo.commits: if c['date'] <= working_date: logger.info('Checking out %s (%s)' % (c['rev'], c['date'])) repo.checkout(c['rev']) # weekly probes commits.run(repo, doc, working_date) line_count.run(repo, doc, working_date) pep8.run(repo, doc, working_date) pyflakes.run(repo, doc, working_date) swearing.run(repo, doc, working_date) break if 'pending' in doc: del doc['pending'] collection.save(doc) repo.cleanup() print 'Finished %s/%s' % (user, repo_name)
class GitDirectoryTest(TestCase): def setUp(self): self.repo = GitRepo('mjp', 'pycheckup') def test_hash_user_and_repo_name(self): self.assertEqual(len(self.repo._working_dir_hash()), 40) def test_working_dir_is_in_tmp(self): self.assertTrue(self.repo.working_dir.startswith('./tmp')) def test_github_url(self): self.assertEqual(self.repo.github_url, 'https://github.com/mjp/pycheckup.git')
def setUp(self): self.repo = GitRepo('mjp', 'pycheckup')
def bootstrap_repo(user, repo_name): logger.info('Bootstraping %s/%s' % (user, repo_name)) repo = GitRepo(user, repo_name) repo.clone() repo.load_commits() doc = document.empty(user, repo_name) # doc = collection.find_one({'_id': '%s/%s' % (user, repo_name)}) # if doc is None: # raise Exception('%s/%s not in db!!!!!' % (user, repo_name)) working_date = datetime.utcnow().replace(hour=0, minute=0, second=0, microsecond=0) one_week = timedelta(days=7) # one-time probes license.run(repo, doc) readme.run(repo, doc) setup_py.run(repo, doc) tabs_or_spaces.run(repo, doc) popularity.run(repo, doc, working_date) current_rev = None if len(repo.commits) == 0: doc['empty'] = True print 'No commits in time period, skipping...' # range(31) means the script will grab 31 weeks of history else: for _ in range(31): for c in repo.commits: if c['date'] <= working_date: # Only check it out if we need to if c['rev'] != current_rev: logger.info('Checking out %s (%s)' % (c['rev'], c['date'])) repo.checkout(c['rev']) current_rev = c['rev'] # weekly probes commits.run(repo, doc, working_date) line_count.run(repo, doc, working_date) pep8.run(repo, doc, working_date) pyflakes.run(repo, doc, working_date) swearing.run(repo, doc, working_date) break working_date -= one_week doc['commits'].reverse() doc['swearing'].reverse() doc['line_count'].reverse() doc['pep8'].reverse() doc['pyflakes'].reverse() repo_collection = mongo.db().repositories repo_collection.save(doc) repo.cleanup() print 'Finished %s/%s' % (user, repo_name)