def saveContext(browser): callerFonctionName = inspect.stack()[1][3] contexteDirectory = os.path.join('report', 'debug', callerFonctionName) print 'Save contexte to ', contexteDirectory if not os.path.exists(contexteDirectory): os.makedir(contexteDirectory) browser.save_screenshot(os.path.join(contexteDirectory, 'screenshot.png')) if os.path.exists(yadomsServer.databasePath()): shutil.copyfile(yadomsServer.databasePath(), os.path.join(contexteDirectory, os.path.basename(yadomsServer.databasePath()))) if os.path.exists(yadomsServer.scriptsPath()): shutil.copytree(yadomsServer.scriptsPath(), os.path.join(contexteDirectory))
def checkLocalRuleCodeById(id, expectedCode): """Check the local rule for expected code""" rulePath = os.path.join(yadomsServer.scriptsPath(), "locals", "rule_" + str(id)) if not os.path.isdir(rulePath): return False ruleFilePath = os.path.join(rulePath, "yadomsScript.py") if not os.path.isfile(ruleFilePath): return False readCode = [] with open(ruleFilePath, 'r') as ruleFile: for line in ruleFile: readCode.append(line.rstrip()) # Remove BOM if len(readCode) > 0 and readCode[0][0] == '\xef' and readCode[0][ 1] == '\xbb' and readCode[0][2] == '\xbf': readCode[0] = readCode[0][3:] if (readCode != expectedCode): print ">>>>>>>>>>> Read code : " print readCode print ">>>>>>>>>>> Expected code : " print expectedCode return False return True
def checkLocalRuleCodeById(id, expectedCode): """Check the local rule for expected code""" rulePath = os.path.join(yadomsServer.scriptsPath(), "locals", "rule_" + str(id)) if not os.path.isdir(rulePath): return False ruleFilePath = os.path.join(rulePath, "yadomsScript.py") if not os.path.isfile(ruleFilePath): return False readCode = [] with open(ruleFilePath, 'r') as ruleFile: for line in ruleFile: readCode.append(line.rstrip()) # Remove BOM if len(readCode) > 0 and readCode[0][0] == '\xef' and readCode[0][1] == '\xbb' and readCode[0][2] == '\xbf': readCode[0] = readCode[0][3:] if (readCode != expectedCode): print ">>>>>>>>>>> Read code : " print readCode print ">>>>>>>>>>> Expected code : " print expectedCode return False return True
def deploy(scripts): deleteAll() print 'Deploy scripts ', scripts for index, script in enumerate(scripts): ruleTargetPath = os.path.join(yadomsServer.scriptsPath(), "locals", "rule_" + str(index + 1)) os.makedirs(ruleTargetPath) shutil.copyfile(os.path.join("resources", "scripts", script + ".py"), os.path.join(ruleTargetPath, "yadomsScript.py"))
def deleteAll(): print 'Remove all scripts and associated logs' resources.deleteTree(yadomsServer.scriptsPath()) resources.deleteTree(yadomsServer.scriptLogsPath())
def ruleFullPath(id): """Get the rule full path for rule id""" rulePath = os.path.join(yadomsServer.scriptsPath(), "locals", "rule_" + str(id)) ruleFilePath = os.path.join(rulePath, "yadomsScript.py") return ruleFilePath