Пример #1
0
def sshkey(request):
    conf = Gitolite(settings.GITOLITE_ADMIN)
    keys = conf.getSSHKeys()

    try:
        mykeys = keys[request.user.username]
    except KeyError:
        mykeys = []

    mykeys.sort()

    key_data = {}
    data = []
    for name in mykeys:
        key_data['name'] = name
        key = conf.getSSHKeyValue(request.user.username, name)
        key_data['fingerprint'] = sshKeyFingerprint(key)
        data.append(copy.copy(key_data))

    template = loader.get_template('account/sshkey.html')
    context = Context({
        'sshkey': data,
    })

    return HttpResponse(template.render(context))
Пример #2
0
def is_duplicate(username, fingerprint):
    conf = Gitolite(settings.GITOLITE_ADMIN)
    keys = conf.getSSHKeys()

    try:
        mykeys = keys[username]
    except KeyError:
        mykeys = []

    key_data = {}
    data = []
    for name in mykeys:
        key = conf.getSSHKeyValue(username, name)
        if sshKeyFingerprint(key) == fingerprint:
            return True

    return False
Пример #3
0
def is_duplicate(username, fingerprint):
    conf = Gitolite(settings.GITOLITE_ADMIN)
    keys = conf.getSSHKeys()

    try:
        mykeys = keys[username]
    except KeyError:
        mykeys = []

    key_data = {}
    data = []
    for name in mykeys:
        key = conf.getSSHKeyValue(username, name)
        if sshKeyFingerprint(key) == fingerprint:
            return True

    return False
Пример #4
0
def sshkey(request):
    conf = Gitolite(settings.GITOLITE_ADMIN)
    keys = conf.getSSHKeys()

    try:
        mykeys = keys[request.user.username]
    except KeyError:
        mykeys = []

    mykeys.sort()

    key_data = {}
    data = []
    for name in mykeys:
        key_data['name'] = name
        key = conf.getSSHKeyValue(request.user.username, name)
        key_data['fingerprint'] = sshKeyFingerprint(key)
        data.append(copy.copy(key_data))

    template = loader.get_template('account/sshkey.html')
    context = Context( {'sshkey': data, } )

    return HttpResponse(template.render(context))
Пример #5
0
def index(request, id, path=''):
    object = Repository.objects.get(id = id)
    project = object.project

    repo_conf = Gitolite(settings.GITOLITE_ADMIN)

    key_data = repo_conf.getSSHKeys()
    if request.user.username not in key_data:
        repo_user_flag = False
    else:
        repo_user_flag = True

    repo_path = settings.GIT_REPO_ROOT + '/' + object.repo_path + '.git'

    try:
        repo = Repo(repo_path, odbt=GitCmdObjectDB)
    except NoSuchPathError:
        tpl = loader.get_template('error.html')
        ctx = Context( { 'error': u"OOps! Repository path %s is invalid" % repo_path, } )
        return HttpResponse(tpl.render(ctx))

    # 최초 생성 후 접근일 경우, 참조할 refs 가 없다.
    if 'master' not in repo.heads:
        tpl = loader.get_template('tree.html')
        ctx = Context( { 'hostname': request.META['HTTP_HOST'].split(':')[0], 'HEAD': None, 'is_user': repo_user_flag, 'project': project, 'repo': object, 'dirs': None, 'files': None, } )
        return HttpResponse(tpl.render(ctx))
    try:
        tree = repo.heads.master.commit.tree[path.rstrip('/')]
        #tree = repo.head.commit.tree[path.rstrip('/')]
    except KeyError:
        tree = repo.heads.master.commit.tree

    #print repo.commit('').summary
    trees = map(lambda x: { 'path': os.path.basename(x.path),
                            #'summary': repo.commit(x.blobs[0].hexsha),
                            'link': x.path}, tree.trees)
    files = map(lambda x: { 'path': os.path.basename(x.path),
                            #'summary': repo.commit(x.).summary,
                            'link': x.path}, tree.blobs)

    #path = {'dirname': os.path.dirname(path), 'name': os.path.basename(path)}
    link_paths = {}
    path_param = []
    count = 0
    if path != '':
        path = os.path.normpath(path).split(os.sep)
        link = ''
        for entry in path:
            for item in range(0, len(path) - count):
                if count == 0:
                    link = path[count]
                else:
                    link = link + '/' + path[count]
                link_paths['basename'] = path[count]
                link_paths['link'] = link
                path_param.append(copy.copy(link_paths))
                count = count + 1

    # TODO: this has error, why?
    #blob = repo.heads.homework.commit.tree.blobs[0]
    #ff = blob.data_stream()
    
    tpl = loader.get_template('tree.html')
    ctx = Context( { 'hostname': request.META['HTTP_HOST'].split(':')[0], 'HEAD': repo.head, 'is_user': repo_user_flag, 'project': project, 'repo': object, 'path': path_param, 'repoid': id, 'repo': object, 'dirs': trees, 'files': files, } )

    return HttpResponse(tpl.render(ctx))
Пример #6
0
def index(request, id, path=''):
    object = Repository.objects.get(id=id)
    project = object.project

    repo_conf = Gitolite(settings.GITOLITE_ADMIN)

    key_data = repo_conf.getSSHKeys()
    if request.user.username not in key_data:
        repo_user_flag = False
    else:
        repo_user_flag = True

    repo_path = settings.GIT_REPO_ROOT + '/' + object.repo_path + '.git'

    try:
        repo = Repo(repo_path, odbt=GitCmdObjectDB)
    except NoSuchPathError:
        tpl = loader.get_template('error.html')
        ctx = Context({
            'error':
            u"OOps! Repository path %s is invalid" % repo_path,
        })
        return HttpResponse(tpl.render(ctx))

    # 최초 생성 후 접근일 경우, 참조할 refs 가 없다.
    if 'master' not in repo.heads:
        tpl = loader.get_template('tree.html')
        ctx = Context({
            'hostname': request.META['HTTP_HOST'].split(':')[0],
            'HEAD': None,
            'is_user': repo_user_flag,
            'project': project,
            'repo': object,
            'dirs': None,
            'files': None,
        })
        return HttpResponse(tpl.render(ctx))
    try:
        tree = repo.heads.master.commit.tree[path.rstrip('/')]
        #tree = repo.head.commit.tree[path.rstrip('/')]
    except KeyError:
        tree = repo.heads.master.commit.tree

    #print repo.commit('').summary
    trees = map(
        lambda x: {
            'path': os.path.basename(x.path),
            #'summary': repo.commit(x.blobs[0].hexsha),
            'link': x.path
        },
        tree.trees)
    files = map(
        lambda x: {
            'path': os.path.basename(x.path),
            #'summary': repo.commit(x.).summary,
            'link': x.path
        },
        tree.blobs)

    #path = {'dirname': os.path.dirname(path), 'name': os.path.basename(path)}
    link_paths = {}
    path_param = []
    count = 0
    if path != '':
        path = os.path.normpath(path).split(os.sep)
        link = ''
        for entry in path:
            for item in range(0, len(path) - count):
                if count == 0:
                    link = path[count]
                else:
                    link = link + '/' + path[count]
                link_paths['basename'] = path[count]
                link_paths['link'] = link
                path_param.append(copy.copy(link_paths))
                count = count + 1

    # TODO: this has error, why?
    #blob = repo.heads.homework.commit.tree.blobs[0]
    #ff = blob.data_stream()

    tpl = loader.get_template('tree.html')
    ctx = Context({
        'hostname': request.META['HTTP_HOST'].split(':')[0],
        'HEAD': repo.head,
        'is_user': repo_user_flag,
        'project': project,
        'repo': object,
        'path': path_param,
        'repoid': id,
        'repo': object,
        'dirs': trees,
        'files': files,
    })

    return HttpResponse(tpl.render(ctx))