def show_blob(usern, repon, branchn, subfile): user = github.get_user(usern) repo = user.get_repo(repon) master = branchn if branchn else repo.master_branch branch = [b for b in repo.get_branches() if b.name == master][0] e = rwt(repo, branch.commit.sha, subfile.strip('/').split('/')) f = repo.get_git_blob(e.sha) if subfile.endswith('.ipynb'): return render_content(base64.decodestring(f.content)) else: return Response(base64.decodestring(f.content), mimetype='text/plain')
def show_blob(usern, repon, branchn, subfile): user = github.get_user(usern) repo = user.get_repo(repon) master = branchn if branchn else repo.master_branch branch = [b for b in repo.get_branches() if b.name == master][0] e = rwt(repo, branch.commit.sha, subfile.strip('/').split('/')) f = repo.get_git_blob(e.sha) if subfile.endswith('.ipynb'): return render_content(base64.decodestring(f.content)) else : return Response(base64.decodestring(f.content), mimetype='text/plain')
def file(usern, repon, tree, branchn, subfile): #we don't care about tree or branch now... #convert names to objects user = github.get_user(usern) repo = user.get_repo(repon) master = branchn if branchn else repo.master_branch branch = [b for b in repo.get_branches() if b.name == master][0] if subfile: atroot = False e = rwt(repo, branch.commit.sha, subfile.strip('/').split('/')) else: atroot = True e = repo.get_git_tree(branch.commit.sha) subfile = '' if hasattr(e, 'type') and e.type == 'blob': f = repo.get_git_blob(e.sha) return render_content(base64.decodestring(f.content)) else: entries = [] subnames = subfile.strip('/').split('/') subpath = [ full_url(usern, repon, 'tree', branchn, '/'.join(subnames[0:i])) for i in range(1, len(subnames) + 1) ] print subnames zero = {'y': repon, 'x': full_url(usern, repon, 'tree', branchn, '/')} parent = [zero] if subfile: for x, y in zip(subpath, subnames): tmp = {} tmp['x'] = x tmp['y'] = y parent.append(tmp) for en in e.tree: var = {} var['path'] = en.path var['type'] = type_for_tree(en) var['class'] = class_for_tree(en) var['url'] = full_url(usern, repon, var['type'], branchn, subfile + '/' + relative_url_for_tree(en)) entries.append(var) return render_template('treelist.html', entries=entries, atroot=atroot, subnames=parent)
def file(usern, repon, tree, branchn, subfile): #we don't care about tree or branch now... #convert names to objects user = github.get_user(usern) repo = user.get_repo(repon) master = branchn if branchn else repo.master_branch branch = [b for b in repo.get_branches() if b.name == master][0] if subfile: atroot = False e = rwt(repo, branch.commit.sha, subfile.strip('/').split('/')) else : atroot = True e = repo.get_git_tree(branch.commit.sha) subfile = '' if hasattr(e, 'type') and e.type == 'blob' : f = repo.get_git_blob(e.sha) return render_content(base64.decodestring(f.content)) else : entries = [] subnames = subfile.strip('/').split('/') subpath = [full_url(usern, repon, 'tree', branchn, '/'.join(subnames[0:i])) for i in range(1, len(subnames)+1)] print subnames zero = {'y' : repon , 'x' : full_url(usern, repon, 'tree', branchn, '/') } parent = [zero] if subfile : for x, y in zip(subpath, subnames): tmp = {} tmp['x'] = x tmp['y'] = y parent.append(tmp) for en in e.tree: var = {} var['path'] = en.path var['type'] = type_for_tree(en) var['class'] = class_for_tree(en) var['url'] = full_url(usern, repon, var['type'], branchn, subfile+'/'+relative_url_for_tree(en)) entries.append(var) return render_template('treelist.html', entries=entries, atroot=atroot, subnames=parent)