Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/python/T0/ConditionUpload/ConditionUploadAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def uploadPayload(filenamePrefix, sqliteFile, metaFile, dropboxHost, validationM
p = subprocess.Popen(command, shell = True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = p.communicate()[0]
output = p.communicate()[0].decode('utf-8')
if p.returncode > 0:
logging.error("Failure during copy from EOS: %s" % output)
logging.error(" ==> Upload failed for payload %s" % filenamePrefix)
Expand All @@ -234,7 +234,7 @@ def uploadPayload(filenamePrefix, sqliteFile, metaFile, dropboxHost, validationM
p = subprocess.Popen(command, shell = True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = p.communicate()[0]
output = p.communicate()[0].decode('utf-8')
if p.returncode > 0:
logging.error("Failure during copy from EOS: %s" % output)
logging.error(" ==> Upload failed for payload %s" % filenamePrefix)
Expand All @@ -247,11 +247,13 @@ def uploadPayload(filenamePrefix, sqliteFile, metaFile, dropboxHost, validationM
if inputCopied:
with open(filenameTXT) as fin:
lines = fin.readlines()
fin.close()
with open(filenameTXT, 'w') as fout:
if validationMode:
fout.writelines( [ line.replace('prepMetaData ', '', 1) for line in lines if 'prodMetaData ' not in line] )
else:
fout.writelines( [ line.replace('prodMetaData ', '', 1) for line in lines if 'prepMetaData ' not in line] )
fout.close()

os.chmod(filenameDB, stat.S_IREAD | stat.S_IWRITE | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)
os.chmod(filenameTXT, stat.S_IREAD | stat.S_IWRITE | stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IWOTH)
Expand All @@ -274,7 +276,7 @@ def uploadPayload(filenamePrefix, sqliteFile, metaFile, dropboxHost, validationM
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output = p.communicate()[0]
output = p.communicate()[0].decode('utf-8')
if p.returncode > 0:
logging.error("Failure during copy of .uploaded file to EOS: %s" % output)
logging.error(" ==> Upload failed for payload %s" % filenamePrefix)
Expand Down
33 changes: 20 additions & 13 deletions src/python/T0/ConditionUpload/upload.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
'''Script that uploads to the new CMS conditions uploader.
Adapted to the new infrastructure from v6 of the upload.py script for the DropBox from Miguel Ojeda.
'''
Expand Down Expand Up @@ -334,7 +334,7 @@ def getToken(self, username, password):
# self.curl.setopt( self.curl.POST, {})
self.curl.setopt(self.curl.HTTPGET, 0)

response = io.StringIO()
response = io.BytesIO()
self.curl.setopt(pycurl.WRITEFUNCTION, response.write)
self.curl.setopt(pycurl.USERPWD, '%s:%s' % (username, password) )

Expand All @@ -345,7 +345,7 @@ def getToken(self, username, password):
logging.debug('got: %s ', str(code))

try:
self.token = json.loads( response.getvalue() )['token']
self.token = json.loads( response.getvalue().decode('UTF-8') )['token']
except Exception as e:
logging.error('http::getToken> got error from server: %s ', str(e) )
if 'No JSON object could be decoded' in str(e):
Expand All @@ -354,9 +354,9 @@ def getToken(self, username, password):
return None

logging.debug('token: %s', self.token)
logging.debug('returning: %s', response.getvalue())
logging.debug('returning: %s', response.getvalue().decode('UTF-8'))

return response.getvalue()
return response.getvalue().decode('UTF-8')

def query(self, url, data = None, files = None, keepCookies = True):
'''Queries a URL, optionally with some data (dictionary).
Expand Down Expand Up @@ -413,7 +413,7 @@ def query(self, url, data = None, files = None, keepCookies = True):

self.curl.setopt(pycurl.VERBOSE, 0)

response = io.StringIO()
response = io.BytesIO()
self.curl.setopt(self.curl.WRITEFUNCTION, response.write)
self.curl.perform()

Expand All @@ -424,9 +424,9 @@ def query(self, url, data = None, files = None, keepCookies = True):
continue

if code != 200:
raise HTTPError(code, response.getvalue())
raise HTTPError(code, response.getvalue().decode('UTF-8'))

return response.getvalue()
return response.getvalue().decode('UTF-8')

except pycurl.error as e:
if len(retries) == 0:
Expand Down Expand Up @@ -509,7 +509,7 @@ def _checkForUpdates(self):

def getDestDbFromMetaData(self, filename):

with open(filename, 'r') as jFile:
with open(filename, 'rb') as jFile:
md = json.load( jFile )

destDb = 'prod'
Expand Down Expand Up @@ -553,13 +553,20 @@ def uploadFile(self, filename, backend = defaultBackend, temporaryFile = default
logging.error(msg)
raise Exception(msg)

with tempfile.NamedTemporaryFile() as metadata:
logging.debug('Adding to tar file for upload ...')
with tempfile.NamedTemporaryFile(mode = "w") as metadata:
with open('%s.txt' % basepath, 'rb') as originalMetadata:
json.dump(json.load(originalMetadata), metadata, sort_keys = True, indent = 4)
originalMetadata_dic = json.load(originalMetadata)
try:
json.dump(originalMetadata_dic, metadata, sort_keys = True, indent = 4)
except TypeError as err:
msg = 'raised a %s ' % err.__repr__()
logging.error(msg)

metadata.seek(0)
addToTarFile(tarFile, metadata, 'metadata.txt')

metadataReader=open(metadata.name,'rb')
addToTarFile(tarFile, metadataReader, 'metadata.txt')

tarFile.close()

logging.debug('%s: %s: Calculating hash...', self.hostname, basename)
Expand Down