def perform_operation_get(self, op, repo_id): repo = get_repo(repo_id) if not repo: raise web.seeother('/repos/') if op == 'sync': try: seafile_rpc.sync(repo.props.id, None) except: pass elif op == 'open' and repo.props.worktree: try: open_dir(repo.props.worktree.encode('utf-8')) except: pass referer = web.ctx.env.get('HTTP_REFERER', '/home/') raise web.seeother(referer) elif op == 'open_file': quote_file_path = web.webapi.input(quote_file_path='').file_path file_path = quote_file_path.encode('utf-8') dir_path = file_path if os.path.exists(file_path) and os.path.isfile(file_path): dir_path = os.path.dirname(file_path) try: open_dir(dir_path) except: pass return render.checkout_msg(repo=repo, file_path=file_path, **default_options) elif op == 'diff': inputs = web.webapi.input(old='', new='') new_commit = seafile_rpc.get_commit(inputs.new) if inputs.old != '': old_commit = seafile_rpc.get_commit(inputs.old) else: old_commit = None (new, removed, renamed, modified, newdir, deldir) = get_diff(repo_id, inputs.old, inputs.new) return render.repo_diff(repo=repo, new=new, removed=removed, renamed=renamed, modified=modified, newdir=newdir, deldir=deldir, new_commit=new_commit, old_commit=old_commit, **default_options) elif op == 'lsch': inputs = web.webapi.input(old='', new='') (new, removed, renamed, modified, newdir, deldir) = get_diff(repo_id, inputs.old, inputs.new) ch = {} ch['new'] = new ch['removed'] = removed ch['renamed'] = renamed ch['modified'] = modified ch['newdir'] = newdir ch['deldir'] = deldir return json.dumps(ch) elif op == 'dir': inputs = web.webapi.input(commit_id='', path='/') dirs = seafile_rpc.list_dir_by_path(inputs.commit_id, inputs.path.encode('utf-8')) navs = get_dir_nav_links(repo, inputs.commit_id, inputs.path) try: commit = seafile_rpc.get_commit(inputs.commit_id) except SearpcError: raise web.seeother('/repo/?repo=%s' % repo_id) return render.repo_dir(repo=repo, dirs=dirs, commit_id=inputs.commit_id, commit=commit, navs=navs, path=inputs.path, **default_options) elif op == 'remove': try: seafile_rpc.remove_repo(repo_id) except: pass raise web.seeother('/repos/') elif op == 'set-auto-sync': auto_sync = {} try: seafile_rpc.set_repo_property(repo_id, "auto-sync", "true") except: pass auto_sync['start'] = True return json.dumps(auto_sync) elif op == 'set-manual-sync': auto_sync = {} try: seafile_rpc.set_repo_property(repo_id, "auto-sync", "false") except: pass auto_sync['start'] = False return json.dumps(auto_sync) referer = web.ctx.env.get('HTTP_REFERER', '/home/') raise web.seeother(referer)
def perform_operation_get(self, op, repo_id): repo = get_repo(repo_id) if not repo: raise web.seeother("/repos/") if op == "sync": try: seafile_rpc.sync(repo.props.id, None) except: pass elif op == "open" and repo.props.worktree: try: open_dir(repo.props.worktree.encode("utf-8")) except: pass referer = web.ctx.env.get("HTTP_REFERER", "/home/") raise web.seeother(referer) elif op == "open_file": quote_file_path = web.webapi.input(quote_file_path="").file_path file_path = quote_file_path.encode("utf-8") dir_path = file_path if os.path.exists(file_path) and os.path.isfile(file_path): dir_path = os.path.dirname(file_path) try: open_dir(dir_path) except: pass return render.checkout_msg(repo=repo, file_path=file_path, **default_options) elif op == "diff": inputs = web.webapi.input(old="", new="") new_commit = seafile_rpc.get_commit(inputs.new) if inputs.old != "": old_commit = seafile_rpc.get_commit(inputs.old) else: old_commit = None (new, removed, renamed, modified, newdir, deldir) = get_diff(repo_id, inputs.old, inputs.new) return render.repo_diff( repo=repo, new=new, removed=removed, renamed=renamed, modified=modified, newdir=newdir, deldir=deldir, new_commit=new_commit, old_commit=old_commit, **default_options ) elif op == "lsch": inputs = web.webapi.input(old="", new="") (new, removed, renamed, modified, newdir, deldir) = get_diff(repo_id, inputs.old, inputs.new) ch = {} ch["new"] = new ch["removed"] = removed ch["renamed"] = renamed ch["modified"] = modified ch["newdir"] = newdir ch["deldir"] = deldir return json.dumps(ch) elif op == "dir": inputs = web.webapi.input(commit_id="", path="/") dirs = seafile_rpc.list_dir_by_path(inputs.commit_id, inputs.path.encode("utf-8")) navs = get_dir_nav_links(repo, inputs.commit_id, inputs.path) try: commit = seafile_rpc.get_commit(inputs.commit_id) except SearpcError: raise web.seeother("/repo/?repo=%s" % repo_id) return render.repo_dir( repo=repo, dirs=dirs, commit_id=inputs.commit_id, commit=commit, navs=navs, path=inputs.path, **default_options ) elif op == "remove": try: seafile_rpc.remove_repo(repo_id) except: pass raise web.seeother("/repos/") elif op == "set-auto-sync": auto_sync = {} try: seafile_rpc.set_repo_property(repo_id, "auto-sync", "true") except: pass auto_sync["start"] = True return json.dumps(auto_sync) elif op == "set-manual-sync": auto_sync = {} try: seafile_rpc.set_repo_property(repo_id, "auto-sync", "false") except: pass auto_sync["start"] = False return json.dumps(auto_sync) referer = web.ctx.env.get("HTTP_REFERER", "/home/") raise web.seeother(referer)