def addsshkey(request): if request.method == 'POST': form = AddKeyForm(request.POST) if form.is_valid(): conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() key_value = form.cleaned_data['key'] key_name = form.cleaned_data['name'].encode('utf-8') if validate_sshkey(key_value) == True: fingerprint = sshKeyFingerprint(key_value) if is_duplicate(request.user.username, fingerprint) == True: form.errors['key'] = u'중복된 SSH Key 값입니다.' template = loader.get_template('account/addsshkey.html') context = Context( {'form': form, } ) return HttpResponse(template.render(context)) conf.addSSHKey(request.user.username, key_name, key_value) if conf.publish() == False: template = loader.get_template('error.html') context = Context( {'error': u'Cannot Publish your SSH key', } ) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/account/setting/sshkey/') else: form.errors['key'] = u'잘못된 SSH Key 값입니다.' else: form = AddKeyForm() template = loader.get_template('account/addsshkey.html') context = Context( {'form': form, } ) return HttpResponse(template.render(context))
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))
def deluser(request, projectid, userid): project = Project.objects.get(id = projectid) user = User.objects.get(id = userid) if user not in project.members.all(): template = loader.get_template('error.html') context = Context( {'error': user.username + u'은 이미 프로젝트 멤버가 아닙니다. 이상하네요. 이 에러는 발생할 수 없는 에러입니다.' ,} ) return HttpResponse(template.render(context)) else: project.members.remove(user) project.save() # 저장소에서 push 권한 빼기 conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() conf.rmUser(project.unix_name, [user.username,]) if conf.publish() == False: template = loader.get_template('error.html') context = Context( {'error': user.username + u'을 프로젝트 저장소에 추가할 수 없습니다.' ,} ) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/project/'+projectid+'/')
def detail(request, id): project = Project.objects.get(id=id) members = project.members.all() conf = Gitolite(settings.GITOLITE_ADMIN) users = [] user = {} for entry in members: user['id'] = entry.id user['username'] = entry.username user['nick'] = entry.get_profile().nick user['avatar'] = entry.get_profile().avatar user['pushable'] = conf.isThereUser(project.unix_name, entry.username) users.append(copy.copy(user)) media_root = settings.MEDIA_URL template = loader.get_template('project/detail.html') context = Context({ 'project': project, 'users': users, 'media': media_root }) return HttpResponse(template.render(context))
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
def deluser2repo(request, projectid, userid): project = Project.objects.get(id = projectid) user = User.objects.get(id = userid) conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() conf.rmUser(project.unix_name, [user.username,]) if conf.publish() == False: template = loader.get_template('error.html') context = Context( {'error': user.username + u'을 프로젝트 저장소에 추가할 수 없습니다.' ,} ) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/project/'+projectid+'/')
def delsshkey(request, name): conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() if conf.rmSSHKey(request.user.username, name) == False: template = loader.get_template('error.html') context = Context({ 'error': u'SSH Key file 을 지우는데 실패 했습니다.', }) return HttpResponse(template.render(context)) conf.publish() conf.unlock() return HttpResponseRedirect('/account/setting/sshkey/')
def delsshkey(request, name): conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() if conf.rmSSHKey(request.user.username, name) == False: template = loader.get_template('error.html') context = Context( {'error': u'SSH Key file 을 지우는데 실패 했습니다.', } ) return HttpResponse(template.render(context)) conf.publish() conf.unlock() return HttpResponseRedirect('/account/setting/sshkey/')
def detail(request, id): project = Project.objects.get(id = id) members = project.members.all() conf = Gitolite(settings.GITOLITE_ADMIN) users = [] user = {} for entry in members: user['id'] = entry.id user['username'] = entry.username user['nick'] = entry.get_profile().nick user['avatar'] = entry.get_profile().avatar user['pushable'] = conf.isThereUser(project.unix_name, entry.username) users.append(copy.copy(user)) media_root = settings.MEDIA_URL template = loader.get_template('project/detail.html') context = Context( {'project': project, 'users': users, 'media': media_root } ) return HttpResponse(template.render(context))
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))
def blob(request, id, path=''): object = Repository.objects.get(id=id) project = object.project repo_conf = Gitolite(settings.GITOLITE_ADMIN) repo_path = settings.GIT_REPO_ROOT + '/' + object.repo_path + '.git' repo = Repo(repo_path, odbt=GitCmdObjectDB) git = repo.git text = git.show('master:' + 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 tpl = loader.get_template('blob.html') ctx = Context({ 'repoid': id, 'reponame': object.reponame, 'path': path_param, 'text': text, }) return HttpResponse(tpl.render(ctx))
def addsshkey(request): if request.method == 'POST': form = AddKeyForm(request.POST) if form.is_valid(): conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() key_value = form.cleaned_data['key'] key_name = form.cleaned_data['name'].encode('utf-8') if validate_sshkey(key_value) == True: fingerprint = sshKeyFingerprint(key_value) if is_duplicate(request.user.username, fingerprint) == True: form.errors['key'] = u'중복된 SSH Key 값입니다.' template = loader.get_template('account/addsshkey.html') context = Context({ 'form': form, }) return HttpResponse(template.render(context)) conf.addSSHKey(request.user.username, key_name, key_value) if conf.publish() == False: template = loader.get_template('error.html') context = Context({ 'error': u'Cannot Publish your SSH key', }) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/account/setting/sshkey/') else: form.errors['key'] = u'잘못된 SSH Key 값입니다.' else: form = AddKeyForm() template = loader.get_template('account/addsshkey.html') context = Context({ 'form': form, }) return HttpResponse(template.render(context))
def deluser2repo(request, projectid, userid): project = Project.objects.get(id=projectid) user = User.objects.get(id=userid) conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() conf.rmUser(project.unix_name, [ user.username, ]) if conf.publish() == False: template = loader.get_template('error.html') context = Context({ 'error': user.username + u'을 프로젝트 저장소에 추가할 수 없습니다.', }) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/project/' + projectid + '/')
def deluser(request, projectid, userid): project = Project.objects.get(id=projectid) user = User.objects.get(id=userid) if user not in project.members.all(): template = loader.get_template('error.html') context = Context({ 'error': user.username + u'은 이미 프로젝트 멤버가 아닙니다. 이상하네요. 이 에러는 발생할 수 없는 에러입니다.', }) return HttpResponse(template.render(context)) else: project.members.remove(user) project.save() # 저장소에서 push 권한 빼기 conf = Gitolite(settings.GITOLITE_ADMIN) conf.lock() conf.rmUser(project.unix_name, [ user.username, ]) if conf.publish() == False: template = loader.get_template('error.html') context = Context({ 'error': user.username + u'을 프로젝트 저장소에 추가할 수 없습니다.', }) conf.unlock() return HttpResponse(template.render(context)) conf.unlock() return HttpResponseRedirect('/project/' + projectid + '/')
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))
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))