84 def upload( destDb, destTag, comment, authPath ):
86 datef = datetime.now()
89 if not os.path.exists( dbFileForDropBox ):
90 print 'The input sqlite file has not been produced.'
95 dbcon = sqlite3.connect( dbFileForDropBox )
96 dbcur = dbcon.cursor()
97 dbcur.execute(
'SELECT * FROM IOV')
98 rows = dbcur.fetchall()
103 print 'The input sqlite file produced contains no data. The upload will be skipped.'
105 except Exception
as e:
106 print 'Check on input data failed: %s' %str(e)
110 if os.path.exists(
'%s.txt' %fileNameForDropBox ):
111 os.remove(
'%s.txt' %fileNameForDropBox )
116 uploadMd[
'destinationDatabase'] = destDb
119 tags[ destTag ] = tagInfo
120 uploadMd[
'destinationTags'] = tags
121 uploadMd[
'inputTag'] = destTag
122 uploadMd[
'since'] =
None
123 datelabel = datef.strftime(dateformatForLabel)
125 if not comment
is None:
127 uploadMd[
'userText'] =
'%s : %s' %(datelabel,commentStr)
128 with open(
'%s.txt' %fileNameForDropBox,
'wb')
as jf:
129 jf.write( json.dumps( uploadMd, sort_keys=
True, indent = 2 ) )
133 uploadCommand =
'uploadConditions.py %s' %fileNameForDropBox
134 if not authPath
is None:
135 uploadCommand +=
' -a %s' %authPath
137 pipe = subprocess.Popen( uploadCommand, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT )
138 stdout = pipe.communicate()[0]
140 retCode = pipe.returncode
143 leafFolderName = datef.strftime(dateformatForFolder)
144 fileFolder = os.path.join( errorInUploadFileFolder, leafFolderName)
145 if not os.path.exists(fileFolder):
146 os.makedirs(fileFolder)
147 df=
'%s.db' %fileNameForDropBox
148 mf=
'%s.txt' %fileNameForDropBox
149 dataDestFile = os.path.join( fileFolder, df)
150 if not os.path.exists(dataDestFile):
151 shutil.copy2(df, dataDestFile)
152 shutil.copy2(mf,os.path.join(fileFolder,mf))
153 print "Upload failed. Data file and metadata saved in folder '%s'" %os.path.abspath(fileFolder)
155 except Exception
as e: