7 from datetime
import datetime
9 confFileName =
'popcon2dropbox.json'
10 fileNameForDropBox =
'input_for_dropbox'
11 dbFileForDropBox =
'%s.db' %fileNameForDropBox
12 dbLogFile =
'%s_log.db' %fileNameForDropBox
13 errorInUploadFileFolder =
'upload_errors'
14 dateformatForFolder =
"%y-%m-%d-%H-%M-%S"
15 dateformatForLabel =
"%y-%m-%d %H:%M:%S"
23 with open(fileName)
as jf:
25 self.
md = json.load(jf)
26 except ValueError
as e:
27 errorMessage =
'CondMetaData.__init__: Problem in decoding JSON file. Original error: ' + e.message
28 raise ValueError(errorMessage)
32 if self.md.has_key(
'authenticationPath'):
33 apath = self.md.get(
'authenticationPath')
38 if self.md.has_key(
'authenticationSys'):
39 asys = self.md.get(
'authenticationSystem')
43 return self.md.get(
'destinationDatabase')
46 return self.md.get(
'logDbFileName')
49 return self.md.get(
'records')
56 tags[ desttag ] = tagInfo
57 uploadMd[
'destinationTags'] = tags
58 uploadMd[
'inputTag'] = inputtag
59 uploadMd[
'since'] =
None
60 datelabel = self.datef.strftime(dateformatForLabel)
61 uploadMd[
'userText'] =
'%s : %s' %(datelabel,comment)
62 with open(
'%s.txt' %fileNameForDropBox,
'wb')
as jf:
63 jf.write( json.dumps( uploadMd, sort_keys=
True, indent = 2 ) )
66 def runO2O( cmsswdir, releasepath, release, arch, jobfilename, logfilename, *p ):
68 if os.path.exists(
'%s.db' %fileNameForDropBox ):
69 print "Removing files with name %s" %fileNameForDropBox
70 os.remove(
'%s.db' %fileNameForDropBox )
71 if os.path.exists(
'%s.txt' %fileNameForDropBox ):
72 os.remove(
'%s.txt' %fileNameForDropBox )
73 command =
'export SCRAM_ARCH=%s;' %arch
74 command +=
'CMSSWDIR=%s;' %cmsswdir
75 command +=
'source ${CMSSWDIR}/cmsset_default.sh;'
76 command +=
'cd %s/%s/src;' %(releasepath,release)
77 command +=
'eval `scramv1 runtime -sh`;'
80 command +=
'cmsRun %s ' %jobfilename
81 command +=
' '.
join(p)
83 pipe = subprocess.Popen( command, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
84 stdout_val = pipe.communicate()[0]
91 if not os.path.exists( dbFileForDropBox ):
92 print 'The input sqlite file has not been produced.'
95 if os.path.exists(
'%s.txt' %fileNameForDropBox ):
96 os.remove(
'%s.txt' %fileNameForDropBox )
101 (username, account, password) = netrc.netrc().authenticators(upload_popcon.defaultNetrcHost)
103 print 'Netrc entry "%s" not found.' %upload_popcon.defaultNetrcHost
105 dropBox.signIn(username, password)
107 for k,v
in md.records().
items():
108 destTag = v.get(
"destinationTag")
109 inputTag = v.get(
"sqliteTag")
112 comment = v.get(
"comment")
113 metadata = md.dumpMetadataForUpload( inputTag, destTag, comment )
114 ret &= dropBox.uploadFile(dbFileForDropBox, backend, upload_popcon.defaultTemporaryFile)
117 print 'File %s successfully uploaded.' %dbFileForDropBox
127 if not os.path.exists( dbFileForDropBox ):
128 print 'The input sqlite file has not been produced.'
133 dbcon = sqlite3.connect( dbFileForDropBox )
134 dbcur = dbcon.cursor()
135 dbcur.execute(
'SELECT * FROM IOV')
136 rows = dbcur.fetchall()
141 print 'The input sqlite file produced contains no data. The upload will be skipped.'
143 except Exception
as e:
144 print 'Check on input data failed: %s' %str(e)
148 if os.path.exists(
'%s.txt' %fileNameForDropBox ):
149 os.remove(
'%s.txt' %fileNameForDropBox )
153 for k,v
in md.records().
items():
154 destTag = v.get(
"destinationTag")
155 inputTag = v.get(
"sqliteTag")
158 comment = v.get(
"comment")
159 metadata = md.dumpMetadataForUpload( inputTag, destTag, comment )
160 uploadCommand =
'uploadConditions.py %s' %fileNameForDropBox
161 if not authPath
is None:
162 uploadCommand +=
' -a %s' %authPath
164 pipe = subprocess.Popen( uploadCommand, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
165 stdout = pipe.communicate()[0]
167 retCode = pipe.returncode
170 leafFolderName = md.datef.strftime(dateformatForFolder)
171 fileFolder = os.path.join( errorInUploadFileFolder, leafFolderName)
172 if not os.path.exists(fileFolder):
173 os.makedirs(fileFolder)
174 df=
'%s.db' %fileNameForDropBox
175 mf=
'%s.txt' %fileNameForDropBox
176 dataDestFile = os.path.join( fileFolder, df)
177 if not os.path.exists(dataDestFile):
178 shutil.copy2(df, dataDestFile)
179 shutil.copy2(mf,os.path.join(fileFolder,mf))
180 print "Upload failed. Data file and metadata saved in folder '%s'" %os.path.abspath(fileFolder)
182 except Exception
as e:
187 def run( jobfilename, authPath ):
188 fns = os.path.splitext( jobfilename )
189 confFile =
'%s.json' %fns[0]
190 if os.path.exists(
'%s.db' %fileNameForDropBox ):
191 print "Removing files with name %s" %fileNameForDropBox
192 os.remove(
'%s.db' %fileNameForDropBox )
193 if os.path.exists(
'%s.txt' %fileNameForDropBox ):
194 os.remove(
'%s.txt' %fileNameForDropBox )
195 command =
'cmsRun %s ' %jobfilename
196 command +=
' popconConfigFileName=%s' %confFile
198 pipe = subprocess.Popen( command, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
199 stdout = pipe.communicate()[0]
200 retCode = pipe.returncode
202 print 'Return code is: %s' %retCode
204 print 'O2O job failed. Skipping upload.'
206 return upload( confFile, authPath )
static std::string join(char **cmd)