def view(request, repo_name, branch=REPO_BRANCH, path=None, commit_sha=None ): repo = get_repo( repo_name ) commit, tree = get_commit_tree(repo, commit_sha) dir_path = path.split("/") if commit_sha: template_name = 'commitlog/view_commit_tree.html' else: template_name = 'commitlog/view_tree.html' if path: if path[-1:] == "/": path = path[:-1] try: tree = tree[path] except AttributeError: tree = tree[dir_path[:-1]] if request.method == 'POST': form = FileUploadForm(request.POST, request.FILES) if form.is_valid(): file_path = os.path.join( repo.working_dir, path, request.FILES["file_source"].name) handle_uploaded_file(file_path, request.FILES['file_source']) msg = "file %s uploaded" % file_path result_msg = mk_commit(repo, msg, file_path ) messages.success(request, result_msg ) else: form = FileUploadForm( initial={ "dir_path": path } ) context = dict( GITTER_MEDIA_URL = GITTER_MEDIA_URL, repo_name = repo_name, branch_name = branch, commit = commit, upload_form = form, tree = tree.list_traverse(depth = 1), breadcrumbs = make_crumbs(path), dir_path = dir_path, ) return mix_response( request, template_name, context)
def view(request, repo_name, branch=REPO_BRANCH, path=None, commit_sha=None ): json_convert = None repo = get_repo( repo_name ) commit, tree = get_commit_tree(repo, commit_sha) the_tree = tree dir_path = path.split("/") if commit_sha: template_name = 'stratus/view_commit_tree.html' else: template_name = 'stratus/view_tree.html' if path: the_tree = tree[path] # if its file try to get file directory if the_tree.type != "tree": path = "/".join(dir_path[:-1]) if len(dir_path) == 1: the_tree = tree else: the_tree = tree[path] if request.is_ajax(): json_convert = message_convert context = dict( STRATUS_MEDIA_URL = STRATUS_MEDIA_URL, repo_name = repo_name, branch_name = branch, commit = commit, repo = repo, tree = the_tree.list_traverse(depth = 1), breadcrumbs = make_crumbs(path), parent_dir = dir_path[:-1], dir_path = dir_path, path = path, ) return mix_response( request, template_name, context, )
def get_file(request, repo_name, branch, path, commit_sha=""): """ get file from git tree """ if path in FILE_BLACK_LIST: raise Http404 repo = get_repo(repo_name) commit, tree = get_commit_tree(repo, commit_sha) try: tree = tree[path] except KeyError: raise Http404 if not tree.type is "blob": raise Http404 return HttpResponse(tree.data_stream.read(), mimetype=tree.mime_type)
def view(request, repo_name, branch, path, commit_sha=None): """ view file in the commit """ file_source = diff = "" if path in FILE_BLACK_LIST: msg = MSG_NOT_ALLOWED return error_view(request, msg) file_path = path #!!! FIX security if path[-1:] == "/": path = path[:-1] repo = get_repo(repo_name) commit, tree = get_commit_tree(repo, commit_sha) if commit.parents: diff = get_diff(repo, path, commit.parents[0].hexsha, commit.hexsha) try: tree = tree[path] except KeyError: msg = MSG_NO_FILE_IN_TREE return error_view(request, msg) if not tree.type is "blob": msg = MSG_NO_FILE_IN_TREE return error_view(request, msg) mime = tree.mime_type.split("/") file_source = tree.data_stream[3].read() # import ipdb; ipdb.set_trace() file_meta = dict( STRATUS_MEDIA_URL=STRATUS_MEDIA_URL, abspath=tree.abspath, mime=tree.mime_type, size=tree.size, tree=tree, path=tree.abspath, mime_type=mime[0], type=file_type_from_mime(tree.mime_type), ) context = dict( STRATUS_MEDIA_URL=STRATUS_MEDIA_URL, file_source=file_source, breadcrumbs=make_crumbs(path), commit=commit, diff=diff, file_meta=file_meta, repo_name=repo_name, repo=repo, branch_name=branch, path=path, name=path.split("/")[-1:][0], ) if mime[0] == "image": import base64 context["img_base"] = base64.b64encode(file_source) from getimageinfo import getImageInfo context["img_meta"] = getImageInfo(file_source) return mix_response(request, "stratus/view_file.html", context)