How to use list_files method in avocado

Best Python code snippet using avocado_python

TxtDC_limits.py

Source:TxtDC_limits.py Github

copy

Full Screen

1#! /usr/bin/env python2import sys3#sys.argv.append('-b')4import ROOT5import array6ROOT.gROOT.SetStyle("Plain")7ROOT.gStyle.SetOptStat(000000000)8ROOT.gStyle.SetOptTitle(0)9from ROOT import TCanvas, TFile, TH1, THStack, TLegend10list_files = {}11list_textfiles = {}12list_syst = {}13Rootfile = TFile("Limit_template.root")14keys = Rootfile.GetListOfKeys()15channels = []16cnst = 017for key in keys:18 a = key.GetName()19 channels.append(a)20 list_textfiles[cnst] = a+"_muon.txt"21 cnst = cnst + 122dir = Rootfile.GetDirectory(channels[0])23dirs = dir.GetListOfKeys()24proc = []25for di in dirs:26 b = di.GetName()27 if b == 'data_obs':28 continue29 if b[0:2] == 'Zp':30 if b == sys.argv[1]:31 proc.append(b)32 else:33 continue 34 else:35 proc.append(b)36 37proc.sort()38proc = list(dict.fromkeys(proc))39proc.sort()40'''41proc.remove("ZprimeNarrow0500")42proc.remove("ZprimeNarrow0750")43proc.remove("ZprimeNarrow1000")44proc.remove("ZprimeNarrow1250")45proc.remove("ZprimeNarrow1500")46proc.remove("ZprimeNarrow2000")47proc.remove("ZprimeNarrow2500")48proc.remove("ZprimeNarrow3000")49proc.remove("ZprimeNarrow3500")50proc.remove("ZprimeNarrow4000")51proc.remove("ZprimeNarrow4500")52proc.remove("ZprimeNarrow5000")53proc.remove("ZprimeNarrow6000")54proc.remove("ZprimeNarrow6500")55proc.remove("ZprimeNarrow7000")56proc.remove("ZprimeWide0500")57proc.remove("ZprimeWide0750")58proc.remove("ZprimeWide1000")59proc.remove("ZprimeWide1250")60proc.remove("ZprimeWide1500")61proc.remove("ZprimeWide2000")62proc.remove("ZprimeWide2500")63proc.remove("ZprimeWide3000")64proc.remove("ZprimeWide3500")65proc.remove("ZprimeWide4000")66proc.remove("ZprimeWide4500")67proc.remove("ZprimeWide5000")68proc.remove("ZprimeWide6000")69proc.remove("ZprimeWide6500")70proc.remove("ZprimeWide7000")71proc.remove("ZprimeUltraWide1000")72proc.remove("ZprimeUltraWide2000")73proc.remove("ZprimeUltraWide3000")74proc.remove("ZprimeUltraWide4000")75proc.remove("ZprimeUltraWide5000")76proc.remove("ZprimeUltraWide6000")77proc.remove("ZprimeUltraWide6500")78proc.remove("ZprimeUltraWide7000")79proc.remove("ZprimeJets0500")80proc.remove("ZprimeJets0750")81proc.remove("ZprimeJets1000")82proc.remove("ZprimeJets1250")83proc.remove("ZprimeJets1500")84proc.remove("ZprimeJets2000")85proc.remove("ZprimeJets2500")86proc.remove("ZprimeJets3000")87proc.remove("ZprimeJets3500")88proc.remove("ZprimeJets4000")89'''90print(proc)91for element in proc:92 if element.islower():93 index = proc.index(element)94 break95syst = []96for i_c in range(len(channels)): 97 for i_p in range(len(proc)):98 sys1 = Rootfile.GetDirectory(channels[i_c]+'/'+proc[i_p])99 syst1 = sys1.GetListOfKeys()100# print(syst1)101 temp_sys = []102 for obj in syst1:103 objN = obj.GetName()104 if objN.endswith('Down'):105 continue106 objN = objN[:-2]107 syst.append(objN)108 temp_sys.append(objN)109 list_syst[len(proc)*i_c + i_p] = temp_sys110 del sys1 111 del syst1112 del temp_sys113#print(syst)114syst = list(dict.fromkeys(syst))115syst.remove('nomin') 116#print(syst)117#for www in range(len(list_syst)):118# print(list_syst[www])119#print(list_syst)120for x in range(len(channels)):121 list_files["file_{0}".format(x)] = open(list_textfiles[x],"w+")122 list_files["file_{0}".format(x)].write("imax 1 number of categories\n")123 list_files["file_{0}".format(x)].write("jmax * number of samples minus one\n")124 list_files["file_{0}".format(x)].write("kmax * number of nuisance parameters\n")125 list_files["file_{0}".format(x)].write("---------------------------------------------------\n")126 list_files["file_{0}".format(x)].write("shapes * * Limit_template.root $CHANNEL/$PROCESS/nominal $CHANNEL/$PROCESS/$SYSTEMATIC\n")127 list_files["file_{0}".format(x)].write("---------------------------------------------------\n")128 list_files["file_{0}".format(x)].write('bin '+channels[x]+'\n')129 list_files["file_{0}".format(x)].write('observation -1\n')130 list_files["file_{0}".format(x)].write("---------------------------------------------------\n")131 list_files["file_{0}".format(x)].write('bin ')132 for y in range(len(proc)):133 list_files["file_{0}".format(x)].write(channels[x]+' ')134 list_files["file_{0}".format(x)].write('\nprocess ')135 for z in range(-1*index+1,len(proc)-index+1):136 list_files["file_{0}".format(x)].write(str(z)+' ')137 list_files["file_{0}".format(x)].write('\nprocess ') 138 for v in range(len(proc)):139 list_files["file_{0}".format(x)].write(proc[v]+' ')140 list_files["file_{0}".format(x)].write('\nrate ')141 for w in range(-1*index+1,len(proc)-index+1):142 list_files["file_{0}".format(x)].write('-1 ')143 list_files["file_{0}".format(x)].write("\n---------------------------------------------------\n")144 list_files["file_{0}".format(x)].write('lumi lnN ')145 for xx in range(len(proc)):146 list_files["file_{0}".format(x)].write('1.025 ')147 list_files["file_{0}".format(x)].write("\n---------------------------------------------------\n")148 for el in syst:149 if el == 'toptag':150 continue151 list_files["file_{0}".format(x)].write(el+' shape ')152 for xxx in range(len(proc)):153 if el in list_syst[len(proc)*x + xxx]:154 list_files["file_{0}".format(x)].write('1 ')155 else: 156 list_files["file_{0}".format(x)].write('0 ') 157 list_files["file_{0}".format(x)].write('\n')158 list_files["file_{0}".format(x)].write("---------------------------------------------------\n")159 list_files["file_{0}".format(x)].write("ttbar_rate rateParam * ttbar 1\n")160 list_files["file_{0}".format(x)].write("ttbar_rate param 1.0 0.20\n")161 list_files["file_{0}".format(x)].write("wl_rate rateParam * wjets_l 1\n")162 list_files["file_{0}".format(x)].write("wl_rate param 1.0 0.25\n")163 list_files["file_{0}".format(x)].write("ST_rate rateParam * singletop 1\n")164 list_files["file_{0}".format(x)].write("ST_rate param 1.0 0.50\n") 165 list_files["file_{0}".format(x)].write("other_rate rateParam * wjets_b 1\n")166 list_files["file_{0}".format(x)].write("other_rate param 1.0 0.50\n")167 list_files["file_{0}".format(x)].write("other_rate rateParam * wjets_c 1\n")168 list_files["file_{0}".format(x)].write("other_rate param 1.0 0.50\n")169 list_files["file_{0}".format(x)].write("other_rate rateParam * dy 1\n")170 list_files["file_{0}".format(x)].write("other_rate param 1.0 0.50\n")171 list_files["file_{0}".format(x)].write("other_rate rateParam * qcd 1\n")172 list_files["file_{0}".format(x)].write("other_rate param 1.0 0.50\n")173 ...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

1import codecs2import os3import subprocess4from enum import Enum5from flask_cors import CORS6from flask import Flask, render_template, request7app = Flask(__name__)8# cors = CORS(app, resource={9# r"/*":{10# "origins":"*"11# }12# })13CORS(app)14# @blueprint.after_request # blueprint can also be app~~15# def after_request(response):16# header = response.headers17# header['Access-Control-Allow-Headers'] = 'Content-Type'18# header['Access-Control-Allow-Origin'] = '*'19# return response20@app.route('/')21def init(): # put application's code here22 return redirect("http://www.example.com", code=302)23@app.route('/ggg')24def hello_world(): # put application's code here25 return 'Hello World!'26@app.route('/abc')27def abc(): # put application's code here28 return 'abc!'29@app.route('/aaa')30def index():31 return render_template('index.html')32class EtatTv(Enum):33 Demarre=134 Arrete=235 Erreur=336def lance_command(s):37 s2 = s.encode("utf-8")38 # s2.encode="utf-8"39 s2 = s2.decode('utf-8')40 list_files = subprocess.run(41 "cec-client -s",42 # ["echo", "\"on 0\"", "|", "cec-client", "-s"],43 shell=True, # , text=True#,44 # capture_output=True45 capture_output=True, text=True, timeout=60,46 input=s2, encoding="utf-8"47 )48 return list_files49def alume_tv():50 print('alume TV')51 s="on 0"52 list_files=lance_command(s)53 # s2=s.encode("utf-8")54 # #s2.encode="utf-8"55 # s2=s2.decode('utf-8')56 # list_files = subprocess.run(57 # "cec-client -s",58 # # ["echo", "\"on 0\"", "|", "cec-client", "-s"],59 # shell=True, # , text=True#,60 # # capture_output=True61 # capture_output=True, text=True,timeout=60,62 # input=s2,encoding="utf-8"63 # )64 # list_files = subprocess.run(65 # "echo \"on0\" | cec-client -s",66 # #["echo", "\"on 0\"", "|", "cec-client", "-s"],67 # shell=True, #, text=True#,68 # #capture_output=True69 # capture_output = True, text = True70 # )71 #print("The exit code was: %d" % list_files)72 print("The exit code was: %d" % list_files.returncode)73 print("stdout:", list_files.stdout)74 print("stderr:", list_files.stderr)75 #res = os.system('echo "on 0" | cec-client -s')76 #print("The exit code was: %d" % res)77 if list_files.returncode==0 and "powering on 'TV'" in list_files.stdout:78 return EtatTv.Demarre79 else:80 return EtatTv.Erreur81def eteint_tv():82 print('eteint TV')83 list_files = lance_command("standby 0")84 # list_files = subprocess.run(["echo", "\"standby 0\"", "|", "cec-client", "-s"])85 #res = os.system('echo "standby 0" | cec-client -s')86 #print("The exit code was: %d" % res)87 print("The exit code was: %d" % list_files.returncode)88 print("stdout:", list_files.stdout)89 print("stderr:", list_files.stderr)90 # res = os.system('echo "on 0" | cec-client -s')91 # print("The exit code was: %d" % res)92 if list_files.returncode == 0 and "putting 'TV' (0) in standby mode" in list_files.stdout:93 return EtatTv.Arrete94 else:95 return EtatTv.Erreur96def status_tv():97 print('status TV')98 # list_files = subprocess.run(["echo", "\"pow 0\"", "|", "cec-client", "-s"])99 #res = os.system('echo "pow 0" | cec-client -s')100 #print("The exit code was: %d" % res)101 list_files = lance_command("pow 0")102 # list_files = subprocess.run(["echo", "\"standby 0\"", "|", "cec-client", "-s"])103 #res = os.system('echo "standby 0" | cec-client -s')104 #print("The exit code was: %d" % res)105 print("The exit code was: %d" % list_files.returncode)106 print("stdout:", list_files.stdout)107 print("stderr:", list_files.stderr)108 # res = os.system('echo "on 0" | cec-client -s')109 # print("The exit code was: %d" % res)110 if list_files.returncode == 0:111 if "power status: on" in list_files.stdout:112 return EtatTv.Demarre113 elif "power status: in transition from on to standby" in list_files.stdout or "power status: standby" in list_files.stdout:114 return EtatTv.Arrete115 else:116 return EtatTv.Erreur117 else:118 return EtatTv.Erreur119@app.route('/tv')120def tv():121 args = request.args122 print(args)123 action = ''124 if "action" in args:125 action = args["action"]126 print('action:', action)127 if action == 'on':128 res=alume_tv()129 if res==EtatTv.Demarre:130 return "ok", 200131 else:132 return "Error", 201133 elif action == 'off':134 res=eteint_tv()135 if res==EtatTv.Demarre:136 return "ok", 200137 else:138 return "Error", 201139 elif action == 'status':140 res=status_tv()141 if res==EtatTv.Demarre:142 return "demarre", 201143 elif res==EtatTv.Arrete:144 return "arrete", 202145 else:146 return "Error", 203147 else:148 print(f'action {action} inconnue')149 return "No query string received", 200150if __name__ == '__main__':151 # app.run(host="0.0.0.0", ssl_context='adhoc')...

Full Screen

Full Screen

file.py

Source:file.py Github

copy

Full Screen

...34 text.flush()35 text.close()36 list_content.append(content)37 return list_content38 def list_files(self, path_current):39 list_files = os.listdir(path_current)40 for i in list_files:41 if i[-4] != '.':42 list_files.remove(i)43 return list_files44 def bkp_files(self, list_files, path_bkp):45 # list_files = self.list_files(path)46 if len(os.listdir(path_bkp)) == 0:47 for i in list_files:48 shutil.copy(i, path_bkp)49 def open_file_split_words(self, list_files):50 list_content = []51 for i in list_files:52 text = open(i, 'r')53 content = text.read().split(' ')54 text.flush()55 text.close()56 list_content.append(content)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run avocado automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful