Skip to content

Commit

Permalink
Merge pull request #10289 from mapellidario/8-10132-py2py3
Browse files Browse the repository at this point in the history
[py2py3] Migration at level scr/python/A/B/C - slice 8
  • Loading branch information
amaltaro authored Feb 19, 2021
2 parents 4c61834 + c026ff1 commit ab26072
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/python/WMCore/MicroService/Service/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def validate(self, apiobj, method, api, param, safe):
"""
if method == 'GET':
for prop in param.kwargs.keys():
for prop in list(param.kwargs):
safe.kwargs[prop] = param.kwargs.pop(prop)
safe.kwargs['API'] = api
if param.args:
Expand Down Expand Up @@ -112,7 +112,7 @@ def post(self):
result = {'status': 'Not supported, %s' % msg, 'request': None}
try:
data = json.load(cherrypy.request.body)
if 'request' in data.keys():
if 'request' in data:
reqName = data['request']
result = self.mgr.info(reqName)
return results(result)
Expand Down
6 changes: 4 additions & 2 deletions src/python/WMCore/ProcessPool/ProcessPool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
"""
from __future__ import print_function

from builtins import range, object

import zmq
import subprocess
import sys
Expand Down Expand Up @@ -38,7 +40,7 @@ class ProcessPoolException(WMException):
"""


class ProcessPoolWorker:
class ProcessPoolWorker(object):
"""
_ProcessPoolWorker_
Expand All @@ -61,7 +63,7 @@ def __call__(self, input):
return


class ProcessPool:
class ProcessPool(object):
def __init__(self, slaveClassName, totalSlaves, componentDir,
config, namespace='WMComponent', inPort='5555',
outPort='5558'):
Expand Down
22 changes: 12 additions & 10 deletions src/python/WMCore/Services/DBS/DBS3Reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"""
from __future__ import print_function, division

from builtins import object, str, bytes
from future.utils import viewitems

from Utils.Utilities import encodeUnicodeToBytes, decodeBytesToUnicode

import logging
from collections import defaultdict

Expand Down Expand Up @@ -37,8 +42,8 @@ def remapDBS3Keys(data, stringify=False, **others):
'block_name': 'BlockName', 'lumi_section_num': 'LumiSectionNumber'}

mapping.update(others)
formatFunc = lambda x: str(x) if stringify and isinstance(x, unicode) else x
for name, newname in mapping.iteritems():
formatFunc = lambda x: encodeUnicodeToBytes(x) if stringify else x
for name, newname in viewitems(mapping):
if name in data:
data[newname] = formatFunc(data[name])
return data
Expand Down Expand Up @@ -212,10 +217,8 @@ def listRunLumis(self, dataset=None, block=None):
)
"""
# Pointless code in python3
if isinstance(block, str):
block = unicode(block)
if isinstance(dataset, str):
dataset = unicode(dataset)
block = decodeBytesToUnicode(block)
dataset = decodeBytesToUnicode(dataset)

try:
if block:
Expand Down Expand Up @@ -516,7 +519,7 @@ def listFilesInBlockWithParents(self, fileBlockName, lumis=True, validFileOnly=1
for fp in f['parent_logical_file_name']:
childByParents[fp].append(f['logical_file_name'])

parentsLFNs = childByParents.keys()
parentsLFNs = list(childByParents)

if len(parentsLFNs) == 0:
msg = "Error in "
Expand Down Expand Up @@ -578,7 +581,7 @@ def listFileBlockLocation(self, fileBlockNames):
"""

singleBlockName = None
if isinstance(fileBlockNames, basestring):
if isinstance(fileBlockNames, (str, bytes)):
singleBlockName = fileBlockNames
fileBlockNames = [fileBlockNames]

Expand Down Expand Up @@ -637,8 +640,7 @@ def getFileBlockWithParents(self, fileBlockName):
"Files" : { LFN : Events },
"IsOpen" : True|False}
"""
if isinstance(fileBlockName, str):
fileBlockName = unicode(fileBlockName)
fileBlockName = decodeBytesToUnicode(fileBlockName)

if not self.blockExists(fileBlockName):
msg = "DBSReader.getFileBlockWithParents(%s): No matching data"
Expand Down
23 changes: 12 additions & 11 deletions src/python/WMCore/Services/DBS/DBSWriterObjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
"""
from __future__ import print_function

from builtins import int

import logging

from DBSAPI.dbsApi import DbsApi
from DBSAPI.dbsException import *
from DBSAPI.dbsApiException import *
from DBSAPI.dbsPrimaryDataset import DbsPrimaryDataset
Expand Down Expand Up @@ -48,7 +49,7 @@ def createPrimaryDataset(datasetInfo, apiRef = None):
else:
PrimaryDatasetType = 'mc'

logging.debug("Inserting PrimaryDataset %s with Type %s"%(datasetInfo["PrimaryDataset"],PrimaryDatasetType))
logging.debug("Inserting PrimaryDataset %s with Type %s", datasetInfo["PrimaryDataset"], PrimaryDatasetType)
primary = DbsPrimaryDataset(Name = datasetInfo["PrimaryDataset"], Type=PrimaryDatasetType)

if apiRef != None:
Expand Down Expand Up @@ -240,7 +241,7 @@ def createProcessedDataset(primaryDataset, algorithm, datasetInfo,
if apiRef != None:
apiRef.insertProcessedDataset(processedDataset)
#
logging.debug("PrimaryDataset: %s ProcessedDataset: %s DataTierList: %s requested by PhysicsGroup: %s "%(primaryDataset['Name'],name,tierList,physicsGroup))
logging.debug("PrimaryDataset: %s ProcessedDataset: %s DataTierList: %s requested by PhysicsGroup: %s ", primaryDataset['Name'], name, tierList, physicsGroup)
return processedDataset


Expand Down Expand Up @@ -292,7 +293,7 @@ def createDBSFiles(fjrFileInfo, jobType = None, apiRef = None):
for runinfo in fjrFileInfo.runs:

run = DbsRun(
RunNumber = long(runinfo),
RunNumber = int(runinfo),
NumberOfEvents = 0,
NumberOfLumiSections = 0,
TotalLuminosity = 0,
Expand All @@ -310,12 +311,12 @@ def createDBSFiles(fjrFileInfo, jobType = None, apiRef = None):
for lumiinfo in fjrFileInfo.getLumiSections():

lumi = DbsLumiSection(
LumiSectionNumber = long(lumiinfo['LumiSectionNumber']),
LumiSectionNumber = int(lumiinfo['LumiSectionNumber']),
StartEventNumber = 0,
EndEventNumber = 0,
LumiStartTime = 0,
LumiEndTime = 0,
RunNumber = long(lumiinfo['RunNumber']),
RunNumber = int(lumiinfo['RunNumber']),
)

# Isnt needed, causes monster slowdown
Expand All @@ -324,7 +325,7 @@ def createDBSFiles(fjrFileInfo, jobType = None, apiRef = None):

lumiList.append(lumi)

logging.debug("Lumi associated to file is: %s"%([x for x in lumiList]))
logging.debug("Lumi associated to file is: %s" % ([x for x in lumiList]))

# //
# // Dataset info related to files and creation of DbsFile object
Expand Down Expand Up @@ -389,16 +390,16 @@ def getDBSFileBlock(dbsApiRef, procDataset, pnn):
return that
"""
logging.warning("getDBSFileBlocks(): dset, pnn: %s, %s" % (procDataset, pnn))
logging.warning("getDBSFileBlocks(): dset, pnn: %s, %s", procDataset, pnn)

allBlocks = dbsApiRef.listBlocks(procDataset, block_name = "*",
phedex_node_name = "*")

logging.warning("getDBSFileBlock(): all blocks %s" % allBlocks)
logging.warning("getDBSFileBlock(): all blocks %s", allBlocks)

openBlocks = [b for b in allBlocks if str(b['OpenForWriting']) == "1"]

logging.warning("getDBSFileBlocks(): open blocks %s" % openBlocks)
logging.warning("getDBSFileBlocks(): open blocks %s", openBlocks)

blockRef = None
if len(openBlocks) > 1:
Expand Down Expand Up @@ -448,5 +449,5 @@ def getDBSFileBlock(dbsApiRef, procDataset, pnn):



logging.warning("Open FileBlock located at PNN: %s to use is FileBlock: %s "%(pnn,blockRef['Name']))
logging.warning("Open FileBlock located at PNN: %s to use is FileBlock: %s ", pnn, blockRef['Name'])
return blockRef
27 changes: 13 additions & 14 deletions src/python/WMCore/Services/DBS/ProdException.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"""



from future.utils import viewitems

import exceptions
import inspect
Expand Down Expand Up @@ -47,29 +46,29 @@ def __init__(self, message, errorNo=1000,**data):
# //
# // Automatically determine the module name
#// if not set
if self['ModuleName'] == None:
if self.data['ModuleName'] == None:
frame = inspect.currentframe()
lastframe = inspect.getouterframes(frame)[1][0]
excepModule = inspect.getmodule(lastframe)
if excepModule != None:
modName = excepModule.__name__
self['ModuleName'] = modName
self.data['ModuleName'] = modName


# //
# // Find out where the exception came from
#//
stack = inspect.stack(1)[1]
self['FileName'] = stack[1]
self['LineNumber'] = stack[2]
self['MethodName'] = stack[3]
self.data['FileName'] = stack[1]
self.data['LineNumber'] = stack[2]
self.data['MethodName'] = stack[3]

# //
# // ClassName if ClassInstance is passed
#//
if self['ClassInstance'] != None:
self['ClassName'] = \
self['ClassInstance'].__class__.__name__
if self.data['ClassInstance'] != None:
self.data['ClassName'] = \
self.data['ClassInstance'].__class__.__name__

logging.error(str(self))

Expand All @@ -92,8 +91,8 @@ def addInfo(self, **data):
Add key=value information pairs to an
exception instance
"""
for key, value in data.items():
self[key] = value
for key, value in viewitems(data):
self.data[key] = value
return

def xml(self):
Expand All @@ -106,7 +105,7 @@ def xml(self):
strg += self.message
strg +="</Message>\n"
strg +="<DataItems>\n"
for key, value in self.data.items():
for key, value in viewitems(self.data):
strg +="<DataItem>\n"
strg += "<Key>\n"
strg += str(key)
Expand All @@ -124,6 +123,6 @@ def __str__(self):
"""create a string rep of this exception"""
strg = "%s\n" % self.name
strg += "Message: %s\n" % self.message
for key, value in self.data.items():
for key, value in viewitems(self.data):
strg += "\t%s : %s\n" % (key, value, )
return strg
3 changes: 2 additions & 1 deletion src/python/WMQuality/TestInitCouchApp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Copyright (c) 2010 Fermilab. All rights reserved.
"""

from builtins import object
from future import standard_library
standard_library.install_aliases()

Expand All @@ -23,7 +24,7 @@

from WMQuality.TestInit import TestInit

class CouchAppTestHarness:
class CouchAppTestHarness(object):
"""
Test Harness for installing a couch database instance with several couchapps
in a unittest.setUp and wiping it out in a unittest.tearDown
Expand Down
1 change: 1 addition & 0 deletions test/python/WMCore_t/ProcessPool_t/ProcessPool_t.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Unit tests for the ProcessPool class.
"""

from builtins import range
import unittest
import nose

Expand Down

0 comments on commit ab26072

Please sign in to comment.