Best Python code snippet using localstack_python
electronStore.py
Source:electronStore.py
1#!/usr/bin/env python2#========================================================================3#4# This script is used to copy a root file of histograms,5# together with its log files, in a destination directory.6# Log files will be automatically compressed.7#8# Command-line options :9#10# -f : force the copy, even if the destination file already exists.11# -r <name> : name of this set of histograms.12# -m <message> : specific comment about this set of histograms.13# -a <analyzers> : slash separated list of analyzers.14# -c <config> : slash separated list of cmsRun configurations.15# 16# Command-line arguments :17#18# $1 : path of the ROOT file containing the histograms.19# $... : path of log files.20# $n : destination directory.21#22#=========================================================================23import os, sys, datetime, shutil, optparse24#============================================25# display a command and eventually executes26#============================================27def mysystem(command,apply=1):28 print command29 if apply==1: return os.system(command)30 elif apply==0: return 031 else:32 print '[electronStore.py] UNSUPPORTED ARGUMENT VALUE FOR mysystem(,apply):',apply33 exit(1)34 35#============================================36# force immediate flushing of stdout37#============================================38class flushfile(object):39 def __init__(self,f):40 self.f = f41 def write(self,x):42 self.f.write(x)43 self.f.flush()44sys.stdout = flushfile(sys.stdout)45#===================================================================46# when called as an independant executable47#===================================================================48if __name__ == "__main__":49 #============================================50 # command-line arguments51 #============================================52 53 parser = optparse.OptionParser()54 parser.add_option("-f", "--force", dest="force", action="store_true", default=False,55 help="force the copy, even if the destination file already exists.") 56 parser.add_option("-r", "--release", dest="release", action="store", default="current",57 help="release name of this set of histograms.") 58 parser.add_option("-m", "--message", dest="message", action="store", default="",59 help="specific comment about this set of histograms") 60 parser.add_option("-a", "--analyzers", dest="analyzers", action="store", default="",61 help="slash separated list of analyzers") 62 parser.add_option("-c", "--configs", dest="configs", action="store", default="",63 help="slash separated list of cmsRun configurations") 64 (options, args) = parser.parse_args()65 66 if len(args)<2:67 print "[electronStore.py] I NEED AT LEAST TWO ARGUMENTS."68 exit(2)69 store_file = args.pop(0)70 store_dir = args.pop()71 if len(args)>0: store_logs = ' '.join(args)72 else: store_logs = ''73 74 analyzers = options.analyzers.split('/') ;75 configs = options.configs.split('/') ; 76 77 78 #============================================79 # prepare output directory80 #============================================81 if os.path.exists(store_dir)==False:82 os.makedirs(store_dir)83 #============================================84 # check data files85 #============================================86 if os.path.isfile(store_file)==True :87 print "STORE_FILE =",store_file88 else :89 print "[electronStore.py] FILE DOES NOT EXIST :",store_file90 exit(3)91 92 if ( store_logs != '' ) :93 print "STORE_LOGS =",store_logs94 #============================================95 # check if already done96 #============================================97 98 output_file = store_dir+'/'+store_file99 if ( options.force==False and os.path.isfile(output_file)==True ) :100 print "[electronStore.py] ERROR: "+store_file+" ALREADY STORED IN "+store_dir+" !"101 exit(4)102 #============================================103 # copy104 #============================================105 files = [ store_file ]106 for analyzer in analyzers:107 files.append('../plugins/'+analyzer+'.h')108 files.append('../plugins/'+analyzer+'.cc')109 for config in configs:110 files.append(config+'.py')111 mysystem('cp '+' '.join(files)+' '+store_dir)112 113 if ( store_logs != '' ) :114 mysystem('cp '+store_logs+' '+store_dir)115 mysystem('cd '+store_dir+' && gzip -f *.olog')116 #============================================117 # comment118 #============================================119 store_url = store_dir.replace('/afs/cern.ch/cms/','http://cmsdoc.cern.ch/',1)120 links = []121 for analyzer in analyzers:122 links.append('<a href="'+store_url+'/'+analyzer+'.h">'+analyzer+'.h</a>')123 links.append('<a href="'+store_url+'/'+analyzer+'.cc">'+analyzer+'.cc</a>')124 for config in configs:125 links.append('<a href="'+store_url+'/'+config+'.py">'+config+'.py</a>')126 comment_file = open(store_dir+'/'+store_file+'.comment','w')127 print >>comment_file, 'The <a href="'+store_url+'/'+store_file+'">'+options.release+' histograms</a>',128 if (options.message!=''):129 print >>comment_file, ' ('+options.message+')',130 print >>comment_file, ' have been prepared with those analyzers and configurations: '+', '.join(links)+'.',131 print >>comment_file132 comment_file.close()133 134 #============================================135 # fin136 #============================================137 138 exit(0)139 ...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!