def get_suite_by_project(app, username, args): path = app.config["AUTO_HOME"] + "/workspace/" + username + "/" + args[ "name"] suites = list_dir(path) children = [] if len(suites) > 1: suites.sort() for d in suites: cases = list_dir(path + "/" + d) icons = "icon-suite" if len(cases) > 1: icons = "icon-suite-open" children.append({ "text": d, "iconCls": icons, "state": "closed", "attributes": { "name": d, "category": "suite" }, "children": [] }) 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_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_list(app, username): work_path = app.config["AUTO_HOME"] + "/workspace/" + username if os.path.exists(work_path): projects = list_dir(work_path) if len(projects) > 1: projects.sort() return projects return []
def load_all_task(app): with app.app_context(): user_path = app.config["AUTO_HOME"] + "/users/" users = list_dir(user_path) for user in users: if os.path.exists(user_path + user): if not os.path.exists(user_path + user + '/config.json'): continue conf = json.load( codecs.open(user_path + user + '/config.json', 'r', 'utf-8')) data = conf['data'] # 遍历项目 for p in data: if p["cron"] == "* * * * * *": continue cron = p["cron"].replace("\n", "").strip().split(" ") if scheduler.get_job("%s_%s" % (user, p["name"])) is None: scheduler.add_job(id="%s_%s" % (user, p["name"]), name=p["name"], func=robot_job, args=(app, p["name"], user), trigger="cron", replace_existing=True, second=cron[0], minute=cron[1], hour=cron[2], day=cron[3], month=cron[4], day_of_week=cron[5]) else: scheduler.remove_job("%s_%s" % (user, p["name"])) scheduler.add_job(id="%s_%s" % (user, p["name"]), name=p["name"], func=robot_job, args=(app, p["name"], user), trigger="cron", replace_existing=True, second=cron[0], minute=cron[1], hour=cron[2], day=cron[3], month=cron[4], day_of_week=cron[5])
def get(self): user_list = {"total": 0, "rows": []} user_path = self.app.config["AUTO_HOME"] + "/users" if exists_path(user_path): users = list_dir(user_path) user_list["total"] = len(users) for user in users: if user == "AutoLink": category = "管理员" else: category = "普通用户" config = json.load( codecs.open(user_path + "/" + user + '/config.json', 'r', 'utf-8')) user_list["rows"].append({ "name": user, "fullname": config["fullname"], "email": config["email"], "category": category }) return user_list
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