def main(): parser = argparse.ArgumentParser() parser.add_argument("-c", "--colors", help="add colors to shell", nargs=1) parser.add_argument("-f", "--file", help="add configuration file", nargs=1) args = parser.parse_args() fd = None if (args.file != None): fd = check_fileExistance(args.file[0]) if (fd is not None): global progs progs = ProgramList(fd) progs.launch() print "BEGIN TASKMASTER" logger.log("BEGIN TASKMASTER") signal.signal(signal.SIGINT, signal_handler) if os.path.exists(historyPath): readline.read_history_file(historyPath) global progs_lock progs_lock = threading.Lock() # launch a thread to test progs t = threading.Thread(target=thread_check_progs) t.daemon = True t.start() shell(progs, args.colors)
def main(): parser = argparse.ArgumentParser() parser.add_argument("-c", "--colors", help="add colors to shell", nargs=1) parser.add_argument("-f", "--file", help="add configuration file", nargs=1) args = parser.parse_args() fd = None if (args.file != None): fd = check_fileExistance(args.file[0]) if (fd is not None): global progs progs = ProgramList(fd) progs.launch() print "BEGIN TASKMASTER" logger.log("BEGIN TASKMASTER") signal.signal(signal.SIGINT, signal_handler) if os.path.exists(historyPath): readline.read_history_file(historyPath) global progs_lock progs_lock = threading.Lock() # launch a thread to test progs t = threading.Thread(target = thread_check_progs) t.daemon = True t.start() shell(progs, args.colors)
def Make_zip_docker(ZIP_URL='https://iptables.cn/file/demo-mgr.zip', DOCKER_TAG='younglinuxer/xxxx:v1'): """ 下载zip 镜像并编译成docker镜像 推送至远程仓库 :param ZIP_URL: 压缩包下载地址 注意命名以zip包命名 :param APP_NAME: app_name :param DOCKER_TAG: docker镜像 命名 :return: """ print("下载文件并编译") file_name = os.path.basename(ZIP_URL) # 获取 zip名 unzip_dir = os.path.splitext(file_name)[0] # 获取zip解压后的文件名 cmd_build_docker = 'docker build -t %s ./docker_file/%s' % (DOCKER_TAG, unzip_dir) cmd_push_docker = 'docker push %s' % (DOCKER_TAG) # 用app_name 命名 防止zip传入的命名有问题 # wget.download(ZIP_URL, '../zip_file/%s.zip' % APP_NAME) # 如果原文件存在 则删除该文件 后在下载 if os.path.exists('./zip_file/%s' % file_name): os.remove('./zip_file/%s' % file_name) wget.download(ZIP_URL, './zip_file/%s' % file_name) print('删除解压文件夹') # if os.path.exists('./docker_file/%s' % unzip_dir): os.remove('./docker_file/%s' % unzip_dir) zipF = zipfile.ZipFile('./zip_file/%s' % file_name, 'r') zipF.extractall('./docker_file/') zipF.close() shell(cmd_build_docker) shell(cmd_push_docker)
def pweave(self, container, nowebpath, markuppath, urlprefix): shell(container, 'Pweave', '--format=pygment', '--no-python', '--markup-file=' + os.path.abspath(markuppath), '--url-prefix=' + urlprefix, os.path.abspath(nowebpath) )
def authentificationserveur(client): identification = 0 buf = 1024 client.send( "=====================================\n----Authentification ---\n=====================================\n" ) while identification == 0: nom = "" prenom = "" mdp = "" data = "recu" nom = client.recv(buf) print "message recu : ", nom client.send(data) prenom = client.recv(buf) print "message recu : ", prenom client.send(data) mdp = client.recv(buf) print "message recu : ", mdp client.send(data) ################################################################ # identification return 0 pour false, et 1 pour true identification = isintable(nom, prenom, mdp, "employees") if identification == 0: client.send("nok") else: data = "entre une action ..." client.send(data) ################################################################## """ data = client.recv(buf) while 1: print(data) if data.upper() == 'FIN': break data = "action traité... \n(pas vraiment j'ai pas encore codé cette partie mais\nbon bref entre une autre ou fin pour finir)" client.send(data) data = client.recv(buf) client.send("fin") break""" shell(client) print("c'est fini molami") return 0
def running(job, worktype, tgz): fails = None dti = 'None' serial_number = None sn = re.findall(CONFIG['sn_read']['read_rule'], job) path = os.path.dirname(job) txt = glob.glob(path + '/*.txt') if len(txt) > 0: with open(txt[0]) as f: for line in f: if CONFIG['report_dti_rule'] in line: dti = line.replace('\n', '') if len(sn) > 0: serial_number = sn[0] print "Doning [%s] -- Thread (%s) " % (serial_number, worktype) if tgz is False: csv_path = job else: name = os.path.basename(job) a, b = shell(CONFIG['test_logs']['cmd'] % (path, name)) csv_path = '/'.join([path, name.replace(CONFIG['test_logs']['format'], ''), 'bridgeOS/private/var/logs/Earthbound/Earthbound/failures.csv']) mylock.acquire() fails = read_csv(csv_path, CONFIG['csv_read']['read_key']) write_result(serial_number, fails, dti, result_file) if tgz is True: os.system('rm -rf %s' % os.path.join(path, name.replace(CONFIG['test_logs']['format'], ''))) mylock.release()
def status_dd(path, testfile_mb=1000, progressFN=emptyFN): progressFN(' Start: DD') if os.path.exists(path): raise Exception('Path already exists: '+path) # Starting write progressFN(' Start: DD WRITE') result_write = shell('dd if=/dev/zero of={filename} bs=1M count={filesize} 2>&1'.format(filename=path, filesize=testfile_mb)) progressFN('Finish: DD WRITE') #Starting read progressFN(' Start: DD READ') result_read = shell('dd if={filename} of=/dev/null 2>&1'.format(filename=path, filesize=testfile_mb)) progressFN('Finish: DD READ') # Parsing reults speed_write = re.search(RE_DD, result_write).groups() speed_read = re.search(RE_DD, result_read).groups() rm_rf(path) progressFN('Finish: DD') return { 'read' : inByte(*speed_read), 'write' : inByte(*speed_write), }
def fetch_repo(self, repo_url): repo_name = self.escape_url(repo_url) repo_path = self.root_path + '/' + repo_name if not os.path.exists(repo_path): try: shell(self.root_path, 'git', 'clone', repo_url, repo_name) except: raise GitError('Failed to clone {0} in {1}' .format(repo_url, self.root_path) ) shell(repo_path, 'git', 'remote', 'update') shell(repo_path, 'git', 'checkout', 'origin') return repo_path
def fetch_commit(self, repo_url, commit): path = self.fetch_repo(repo_url) shell(path, 'git', 'checkout', commit) return path
def aalc(file, use_shell: bool = False, check: bool = False, monodic: bool = False, compile: bool = False, libs_path="libs/aal/", root_path=None, recompile: bool = False, to_ltl: bool = False, show_ast: bool = False, timeout=20, no_exec=False, web=False): """ Parse AAL. :param file: The AAL input file :param use_shell: Run an interactive shell after parsing :param check: Perform a various checks :param monodic: Perform the monodic test :param compile: Compile the AAL file into aalc :param libs_path: The standard library path :param root_path: Base path :param recompile: Recompile the file :param to_ltl: Transform AAL code into FOTL formula :param show_ast: Show an interactive AST graph in a web page :param no_exec: disable macro calls and exec :param web : if aalc is called from a web server :return: {"res": the result, "mm": the metamodel instance} """ from AALCompiler import AALCompilerListener print("-------- aalc " + " starting at : " + str(datetime.datetime.now()) + " File : " + str(file) + " --------\n") inputfile = FileStream(file) lexer = AALLexer(inputfile) stream = CommonTokenStream(lexer) parser = AALParser(stream) desec = DescriptiveErrorListener() parser.addParseListener( AALCompilerListener(file=file, libs_path=libs_path, recompile=recompile, no_exec=no_exec, root_path=root_path, errors_listener=desec, tspass_timeout=timeout, web=web)) parser.addErrorListener(desec) parser.buildParseTrees = True # TODO : important prediction mode optimization (we gain x5 speed up with SLL) # use SLL for the first pass, if an error detected we probably have to make a second pass # using LL mode (to check, see the doc) # parser._interp.predictionMode = PredictionMode.LL # ~2.5 parser._interp.predictionMode = PredictionMode.SLL # ~0.4 # parser._interp.predictionMode = PredictionMode.LL_EXACT_AMBIG_DETECTION # ~2.5 start_time = time.time() tr = parser.main() exec_time = time.time() - start_time print("\nExecution time : " + str(exec_time)) bt = Trees.toStringTree(tr, recog=parser) #print(bt) l = parser.getParseListeners().pop(0) res = "" if monodic or check: # Monodic test res += check_aal(l, verbose=check) if to_ltl: # FOTL translation ltl_trans = AALtoFOTL(l) res += "\n------------------------- FOTL Translation start -------------------------\n" res += ltl_trans # Write in disk with open(file.replace("aal", "tspass"), mode='w') as f: f.write(ltl_trans) res += "\n-------------------------- FOTL Translation end --------------------------\n" if compile: # Compile aal file to aalc sys.setrecursionlimit(3000) with open(file + "c", "wb") as f: pickle.dump(l, f, pickle.HIGHEST_PROTOCOL) if show_ast: # Show AST from tools.visu import Visu Visu.show_ast(l.aalprog) if use_shell: # Run the shell shell(l) return {"res": str(Color(res)), "mm": l}
def main(argv): """ Main aalc :param argv: console arguments :return: """ global ACCLAB_PATH inputfile = "" outputfile = "" help_str_extended = "AAL tools set V 2.3 . aalc is a part of Acclab tool.\n" + \ "For more information see AccLab home page\n Usage : aalc.py [OPTIONS]" + \ "\n -h \t--help " + "\t display this help and exit" + \ "\n -i \t--input= [file] " + "\t the input file" + \ "\n -o \t--output= [path]" + "\t the output file" + \ "\n -c \t--compile " + "\t compile the file, that can be loaded after using -l" + \ "\n -m \t--monodic " + "\t apply monodic check on aal file" + \ "\n -s \t--shell " + "\t run a shell after handling aal program" + \ "\n -k \t--check " + "\t perform a verbose check" + \ "\n -l \t--load " + "\t load a compiled aal file (.aalc) and run a shell" + \ "\n -t \t--fotl " + "\t translate the aal program into FOTL" + \ "\n -r \t--reparse " + "\t reparse tspass file" + \ "\n -r \t--recompile " + "\t recompile the external files " + \ "\n -b \t--no-colors " + "\t disable colors in output" + \ "\n -x \t--compile-stdlib" + "\t compile the standard library" + \ "\n -d \t--hotswap " + "\t enable hotswaping (for development only)" + \ "\n -a \t--ast " + "\t show ast tree" + \ "\n -u \t--gui= [port] " + "\t run the gui on the specified port" + \ "\n -n \t--no-browser " + "\t don't start the web browser" + \ "\n -q \t--timeout= [n] " + "\t TSPASS prover timeout (in seconds)" + \ "\n\nReport aalc bugs to [email protected]" + \ "\nAccLab home page: <http://www.emn.fr/z-info/acclab/>" + \ "\naalc is a free software released under GPL 3" compile = False use_shell = False monodic = False check = False load = False recompile = False initialize = False to_ltl = False hotswaping = False show_ast = False synth = False reparse = False nobrowser = False run_gui = False outputfile = "tmp.tspass" server_port = 8000 timeout = 20 # Check libs path install_path = os.environ.get('ACCLAB_PATH') ACCLAB_PATH = install_path libs_path = (install_path + "/" if install_path is not None else "") + "libs/aal/" # Checking options try: opts, args = getopt.getopt(argv[1:], "hi:o:cmsktlrbxdaSru:nq:", [ "help", "input=", "output=", "compile", "monodic", "check", "shell", "load", "fotl", "recompile", "init", "no-colors", "compile-stdlib", "hotswap", "ast", "synth", "reparse", "gui=", "no-browser", "timeout=" ]) except getopt.GetoptError: print(help_str_extended) sys.exit(2) if len(opts) == 0: print(help_str_extended) # Handling options for opt, arg in opts: if opt in ("-h", "--help"): print(help_str_extended) sys.exit() elif opt in ("-i", "--input"): inputfile = arg elif opt in ("-o", "--output"): outputfile = arg elif opt in ("-c", "--compile"): compile = True elif opt in ("-m", "--monodic"): monodic = True elif opt in ("-k", "--check"): check = True elif opt in ("-s", "--shell"): use_shell = True elif opt in ("-l", "--load"): load = True elif opt in ("-t", "--fotl"): to_ltl = True elif opt in ("-r", "--recompile"): recompile = True elif opt in ("-z", "--init"): initialize = True elif opt in ("-b", "--no-colors"): disable_all_colors() elif opt in ("-x", "--compile-stdlib"): compile_stdlib(libs_path) return elif opt in ("-d", "--hotswap"): hotswaping = True elif opt in ("-a", "--ast"): show_ast = True elif opt in ("-S", "--synth"): synth = True elif opt in ("-r", "--reparse"): reparse = True elif opt in ("-n", "--no-browser"): nobrowser = True elif opt in ("-q", "--timeout"): timeout = int(arg) elif opt in ("-u", "--gui"): run_gui = True try: server_port = int(arg) except: print("Warning invalid port number, running on port 8000") server_port = 8000 if run_gui: # Start server from ui.Server import start_ui start_ui(server_port, nobrowser=nobrowser) # Use hot swapping decoration on all AALMetaModel classes # use this option for debug only if hotswaping: import inspect import AALMetaModel for name, obj in inspect.getmembers(AALMetaModel): if inspect.isclass(obj): if "AALMetaModel" in str(obj): obj = hot(obj) if initialize: check_env() elif load and inputfile.endswith(".aalc"): # Load a compiled AAL file sys.setrecursionlimit(3000) with open(inputfile, "rb") as f: l = pickle.load(f) shell(l) elif inputfile.endswith(".aal"): # Use AAL compiler res = aalc(inputfile, use_shell=use_shell, check=check, monodic=monodic, compile=compile, recompile=recompile, to_ltl=to_ltl, show_ast=show_ast, libs_path=libs_path, timeout=timeout) print(res["res"]) elif inputfile.endswith(".tspass"): # Use tspass compiler res = tspassc(inputfile, output=outputfile, use_shell=False, debug=False, synth=synth, reparse=reparse, timeout=timeout) print(res["print"])