def setWallpaper(apodPath) -> int: print(" apodwallpaper.py -> setWallpaper - Running feh") # Run feh command using the photo local path res = subRun(['feh', '--no-fehbg', '--bg-scale', apodPath]).returncode # Check return code to print error message if res != 0: print(" apodwallpaper.py -> setWallpaper - ERROR: feh failed") print(" apodwallpaper.py -> setWallpaper - ERROR CODE:", res) return res
def robot_run(app, case_key, args='', user='', driver='USER'): username = user if user != '' else session['username'] project = get_projectnamefromkey(case_key) output = app.config["AUTO_HOME"] + "/jobs/%s/%s" % (username, project) if not exists_path(output): mk_dirs(output) (out, index) = reset_next_build_numb(output) mk_dirs(out) if not exists_path(out) else None cmd = 'robot ' + args + ' --outputdir=' + out + ' ' + case_key log.info("Robot_run CMD:{}".format(cmd)) with open(out + "/cmd.txt", 'w') as f: f.write("{}|robot|{}|--outputdir={}|{}\n".format( driver, args, out, case_key)) cp = subRun(cmd, shell=True, stdout=PIPE, stderr=STDOUT, text=True, timeout=7200) # timeout: sec 2hrs with open(out + "/debug.txt", 'w') as f: f.write(cp.stdout) app.config['DB'].insert_loginfo(username, 'task', 'run', case_key, 'OK') # Report and xUnit files can be generated based on the result object. # ResultWriter(result).write_results(report=out + '/report.html', log=out + '/log.html') try: detail_result = ExecutionResult(out + "/output.xml") except Exception as e: log.error( "Open output.xml Exception:{},\n May robot run fail, console:{}". format(e, cp.stdout)) return # detail_result.save(out + "/output_new.xml") reset_last_status(detail_result, output, index) # Report and xUnit files can be generated based on the result object. ResultWriter(detail_result).write_results(report=out + '/report.html', log=out + '/log.html') s = detail_result.suite dealwith_source(app, username, s)
def checkConn() -> int: print(" apodwallpaper.py -> checkConn - Checking internet connectivity") res = 0 pingCount = 0 # Check internet connectivity while pingCount < 5 and subRun(['ping', '-c1', 'google.com' ]).returncode != 0: pingCount += 1 sleep(5) if pingCount == 5: res = 1 print( " apodwallpaper.py -> checkConn - ERROR: No internet connectivity") return res
def bzt_debugrun(app, yamlfile): projectdir = get_projectdirfromkey(yamlfile) os.environ["ROBOT_DIR"] = projectdir os.environ["PROJECT_DIR"] = projectdir cmd = 'bzt ' + yamlfile cp = subRun(cmd, shell=True, stdout=PIPE, stderr=STDOUT, text=True, timeout=180) # timeout: sec app.config['DB'].insert_loginfo(session['username'], 'case', 'debug', yamlfile, 'OK') return cp.stdout
def py_debugrun(app, pyfile): projectdir = get_projectdirfromkey(pyfile) os.environ["ROBOT_DIR"] = projectdir os.environ["PROJECT_DIR"] = projectdir cmd = 'python ' + pyfile cp = subRun(cmd, shell=True, stdout=PIPE, stderr=STDOUT, text=True, timeout=120) # timeout: sec app.config['DB'].insert_loginfo(session['username'], 'lib', 'debug', pyfile, 'OK') return cp.stdout
def robot_debugrun(app, cases): out = app.config['AUTO_TEMP'] if not exists_path(out): mk_dirs(out) cmd = 'robot --outputdir=' + out + ' ' + cases cp = subRun(cmd, shell=True, stdout=PIPE, stderr=STDOUT, text=True, timeout=60) # timeout: sec app.config['DB'].insert_loginfo(session['username'], 'case', 'debug', cases, 'OK') return cp.stdout
def generate_resource_xml(srcfile, desfile): if not os.path.isfile(srcfile) and srcfile.endswith('.resource'): log.warning("无法生成 xml file of " + srcfile) return '' log.info("生成 xml file of :" + srcfile) try: cmd = 'python -m robot.libdoc -f xml ' + srcfile + ' ' + desfile cp = subRun(cmd, shell=True, stdout=PIPE, stderr=STDOUT, text=True, timeout=180) # timeout: sec except SyntaxError as e: log.error("生成资源文件异常:{} {}".format(srcfile, e)) return '' except Exception as e: log.error("生成资源文件异常:{} {}".format(srcfile, e)) return '' return cp.stdout