예제 #1
0
def _standard_response(repo, commit):
    tree = commit.tree
    transcription_info, _ = repos.json_file_at_commit(
        repo, 'transcription.json', commit, required=True)
    return dict(
        _progress_dicts(tree, transcription_info),
        latest_revision=repos.latest_revision(repo),
        custom_css_revision=repos.most_recent_revision(repo, 'custom.css'),
        custom_js_revision=repos.most_recent_revision(repo, 'custom.js'),
        speakers=repos.file_at_commit(repo, 'speakers.txt', commit)[0],
        tracking_html=repos.file_at_commit(repo, 'tracking.html', commit)[0],
        transcription_info=transcription_info,
        transcription_info_json=json.dumps(transcription_info),
    )
예제 #2
0
def snippets_updated(request):
    """Return formatted snippets that have been updated since the given revision."""
    repo, request_commit = repos.repo_from_request(request)
    since_rev = request.GET.getone('since')
    # Return cached if found.
    cache_key = 'updated-{0}-{1}'.format(request_commit.hexsha, since_rev)
    content, mtime = cache.get_cached_content(cache_key)
    if content is None or request.GET.has_key('nocache'):
        since_commit = repo.commit(since_rev)
        files_updated = set()
        for commit in repo.iter_commits(request_commit):
            # Have we reached the end?
            if commit == since_commit:
                break
            # Look for snippet changes.
            for filename in commit.stats.files:
                if len(filename) == 20 and filename.endswith('.txt'):
                    files_updated.add(filename)
        tree = request_commit.tree
        speakers_map = repos.speakers_map(repo, request_commit)
        snippets = []
        for filename in files_updated:
            starting_point = int(filename[:16])
            snippet = dict(
                starting_point=starting_point,
            )
            text = tree[filename].data_stream.read().strip()
            snippet['lines'] = _split_lines_and_expand_abbreviations(text, speakers_map)
            snippets.append(snippet)
        data = dict(
            latest_revision=repos.latest_revision(repo),
            snippets=snippets,
        )
        content = json.dumps(data)
        mtime = request_commit.authored_date
        cache.cache_content(cache_key, content, mtime)
    return Response(content, content_type='application/json', date=mtime)