示例#1
0
def update_repo_stats(git_repo_id, git_repo_path, git_repo):
    """
    Accumulates the information about 'git_repo_id' repository
    and puts it into DB.
    """
    # real disk usage as 'du' says, faster than 'pythonic' ways of calculation:
    disk_usage = check_output(('du', '-sh',
                               git_repo_path)).split()[0].decode('utf-8')

    # human-readable time format according to rfc2822 e-mail standard:
    checkout_time = strftime("%a, %d %b %Y %H:%M:%S", localtime())

    # get 5 recent commits:
    recent_commits = list(git_repo.iter_commits(max_count=5))

    if recent_commits:  # empty if it's a new 'git init' repo only
        last_author = recent_commits[0].committer
        last_hash = recent_commits[0].binsha.encode('hex')
    else:
        last_author = last_hash = None
    last_msgs = []

    # repository files as in current revision/state.
    all_repo_files = git_repo.git.ls_files().split()

    for commit in recent_commits:
        last_msgs.append(commit.message.encode('utf8', 'ignore'))

    repo_stats = {"recent_committer": last_author,
                  "current_revision": last_hash,
                  "last_5_messages": last_msgs,
                  "total_files": len(all_repo_files),
                  "disk_usage": disk_usage,
                  "last_checkout": checkout_time}

    # update DB record:
    redis.hmset(git_repo_id, repo_stats)
示例#2
0
 def test_get_non_empty_not_existing_resources(self):
     redis.hmset('git_repo_id:1', self.test_repo_stats)
     rv = self.app.get('/resources/', data=json.dumps('{"id": [2,3]}'))
     assert '{2: {}}, {3: {}}' in rv.data
     assert rv.status_code == 200
示例#3
0
 def test_delete_existing_not_cloned_resources(self):
     redis.hmset('git_repo_id:1', self.test_repo_stats)
     rv = self.app.delete('/resources/', data=json.dumps('{"id": [1]}'))
     assert 'error' in rv.data
     assert 'Bad Request' in rv.data
     assert rv.status_code == 400
示例#4
0
 def test_get_non_empty_existing_resources(self):
     redis.hmset('git_repo_id:1', self.test_repo_stats)
     rv = self.app.get('/resources/')
     assert 'git_repo_id:1' in rv.data
     assert 'https://github.com/galkindmitrii/openstack_swift_s3' in rv.data
     assert rv.status_code == 200