def get_case_by_suite(app, username, args): path = app.config["AUTO_HOME"] + "/workspace/" + username + "/%s/%s" % ( args["project"], args["name"]) cases = list_dir(path) if len(cases) > 1: cases.sort() children = [] for t in cases: text = get_splitext(t) if text[1] in ICONS: icons = ICONS[text[1]] else: icons = "icon-file-default" children.append({ "text": t, "iconCls": icons, "state": "open", "attributes": { "name": text[0], "category": "case", "splitext": text[1] } }) return children
def get_case_by_suite(app, username, args): path = app.config["AUTO_HOME"] + "/workspace/" + username + "/%s/%s" % ( args["project"], args["name"]) cases = list_dir(path) if len(cases) > 1: cases.sort() children = [] for t in cases: text = get_splitext(t) if text[1] == ".robot": icons = "icon-robot" elif text[1] == ".txt": icons = "icon-resource" elif text[1] in (".bmp", ".jpg", ".jpeg", ".png", ".gif"): icons = "icon-image" else: icons = "icon-file-default" children.append({ "text": t, "iconCls": icons, "state": "open", "attributes": { "name": text[0], "category": "case", "splitext": text[1] } }) return children
def get_project_detail(app, username, p_name): path = app.config["AUTO_HOME"] + "/workspace/" + username + "/" + p_name projects = [] # raw_suites = list_dir(path) # suites = sorted(raw_suites, key=lambda x: os.stat(path + "/" + x).st_ctime) suites = list_dir(path) if len(suites) > 1: suites.sort() for d in suites: children = [] # cases = sorted(list_dir(path + "/" + d), key=lambda x: os.stat(path + "/" + d + "/" + x).st_ctime) cases = list_dir(path + "/" + d) if len(cases) > 1: cases.sort() for t in cases: text = get_splitext(t) if text[1] == ".robot": icons = "icon-robot" elif text[1] == ".txt": icons = "icon-resource" else: icons = "icon-file-default" children.append({ "text": t, "iconCls": icons, "attributes": { "name": text[0], "category": "case", "splitext": text[1] } }) if len(children) == 0: icons = "icon-suite" else: icons = "icon-suite-open" projects.append({ "text": d, "iconCls": icons, "attributes": { "name": d, "category": "suite" }, "children": children }) return projects
def get(self): args = self.parser.parse_args() result = {"status": "success", "msg": "读取文件成功"} ext = get_splitext(args["path"]) result["ext"] = ext[1] path = self.app.config["AUTO_HOME"] + "/workspace/%s%s" % (session["username"], args["path"]) data = read_file(path) if not data["status"]: result["status"] = "fail" result["msg"] = "读取文件失败" result["data"] = data["data"] return result, 201
def runall(self, args): cases = args['key'] if not os.path.isdir(cases): fext = get_splitext(cases)[1] if not fext in (".robot"): return {"status": "fail", "msg": "失败:暂不支持运行此类型的文件 :" + fext} case_name = os.path.basename(cases) if not is_run(self.app, case_name): p = multiprocessing.Process(target=robot_run, args=(self.app, cases, '')) p.start() self.app.config["AUTO_ROBOT"].append({ "name": "%s" % case_name, "process": p }) else: return {"status": "fail", "msg": "失败:超过最大进程数,请等待."} return {"status": "success", "msg": "运行:" + case_name}
def get(self): args = self.parser.parse_args() key = args["key"].replace( "--", "/") if args["key"] else args["path"].replace("--", "/") self.log.debug("Get args:{}".format(args)) result = {"status": "success", "msg": "读取文件成功."} ext = get_splitext(key) result["ext"] = ext[1] #path = self.app.config["AUTO_HOME"] + "/workspace/%s%s" % (session["username"], args["path"]) #path = args["key"] data = read_file(key) if not data["status"]: result["status"] = "fail" result["msg"] = "读取文件失败." result["data"] = data["data"] return result, 201
def editor(key): rpkey = key.replace("--", "/") t = get_splitext(rpkey) log.info("*RPKEY:" + rpkey) log.info("*KEY:" + key) log.info("*File ext:" + t[1]) default = "default.html" if t[1] in (".html", ".htm"): if os.path.exists(rpkey): default = rpkey return send_file(default) if t[1] in (".txt", ".robot", ".resource", ".py", ".js", ".yaml", ".conf", ".ini", ".sh", ".md", ".tplt"): default = "editor.html" if t[1] == ".yaml": mode = 'yaml' elif t[1] == '.py': mode = 'python' elif t[1] == '.md': mode = 'textile' else: mode = 'python' return render_template(default, key=rpkey, mode=mode) if t[1] in (".bmp", ".jpg", ".jpeg", ".png", ".gif"): return send_file(rpkey) if t[1] in (".tmd"): res = read_file(rpkey) return render_template("test_design.html", key=rpkey, value=res["data"]) return render_template(default)
def get(self): args = self.parser.parse_args() #log.info("get projectList: args:{}".format(args)) if args["key"] == "root": return get_projects(self.app, session["username"]) else: path = args["key"] if os.path.isfile(path): # 单个文件 return get_step_by_case(self.app, path) files = list_dir(path) # Omit the hidden file files = [f for f in files if not f.startswith('.')] if len(files) > 1: files.sort() children = [] for d in files: ff = path + '/' + d if os.path.isdir(ff): # 目录:Dir icons = "icon-suite-open" stat = "closed" text = d # For performance concern, False. if self.app.config['SHOW_DIR_DETAIL']: td = self.app.config['DB'].get_testdata(ff) if td[0] > 0: # [suites,cases,passed,Failed,unknown] icons = "icon-suite-open_case" text = d + ':' + " ".join([str(ss) for ss in td]) children.append({ "text": text, "iconCls": icons, "state": stat, "attributes": { "name": d, "category": "suite", "key": ff, }, "children": [] }) else: # 单个文件:single file text = get_splitext(ff) if text[1] in ICONS: icons = ICONS[text[1]] else: icons = "icon-file-default" if text[1] in (".robot"): if self.app.config['SHOW_DIR_DETAIL']: # [suites,cases,passed,Failed,unknown] td = self.app.config['DB'].get_testdata(ff) if td[1] == td[2]: icons = 'icon-robot_pass' if td[3] > 0: icons = 'icon-robot_fail' lb = d.replace('.robot', ':') + \ ' '.join([str(ss) for ss in td[1:]]) else: suite_status = self.app.config[ 'DB'].get_suitestatus(ff) if suite_status == 'PASS': icons = 'icon-robot_pass' if suite_status == 'FAIL': icons = 'icon-robot_fail' lb = d.replace('.robot', '') children.append({ "text": lb, "iconCls": icons, "state": "closed", "attributes": { "name": d, "category": "case", "key": ff, "splitext": text[1] }, "children": [] }) elif text[1] in (".resource"): children.append({ "text": d, "iconCls": icons, "state": "closed", "attributes": { "name": d, "category": "case", "key": ff, "splitext": text[1] } }) else: children.append({ "text": d, "iconCls": icons, "state": "open", "attributes": { "name": d, "category": "case", "key": ff, "splitext": text[1] } }) return children