Skip to content

Commit

Permalink
Convert bin/ scripts to python3-only
Browse files Browse the repository at this point in the history
Remove future and __future__ imports
  • Loading branch information
amaltaro committed Dec 30, 2022
1 parent fb39cd4 commit a2d28d5
Show file tree
Hide file tree
Showing 38 changed files with 37 additions and 112 deletions.
2 changes: 0 additions & 2 deletions bin/HWMon/wmcore-SysStat
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ wmcore-SysStat
Hardware monitoring utility for launched sensor daemons.
"""
from __future__ import print_function

import sys
import os
import getopt
Expand Down
2 changes: 1 addition & 1 deletion bin/adhoc-scripts/ParseSpecCmsswdist.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"""

from __future__ import division # Jenkins CI
# Jenkins CI

import argparse
import os
Expand Down
14 changes: 6 additions & 8 deletions bin/adhoc-scripts/checkDsetFileCount.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
using both DBS and Rucio services. It prints any inconsistency among
those two.
"""
from __future__ import print_function, division


import logging
import sys
from collections import Counter

from future.utils import viewkeys, viewvalues

from WMCore.Services.DBS.DBS3Reader import DBS3Reader
from WMCore.Services.Rucio.Rucio import Rucio

Expand Down Expand Up @@ -95,20 +93,20 @@ def main():
dbsOutput, dbsFilesCounter = getFromDBS(datasetName, logger)

logger.info("*** Dataset: %s", datasetName)
logger.info("Rucio file count : %s", sum(viewvalues(rucioOutput)))
logger.info("Rucio file count : %s", sum(rucioOutput.values()))
logger.info("DBS file count : %s", dbsFilesCounter['valid'] + dbsFilesCounter['invalid'])
logger.info(" - valid files : %s", dbsFilesCounter['valid'])
logger.info(" - invalid files : %s", dbsFilesCounter['invalid'])
logger.info("Blocks in Rucio but not in DBS: %s", set(viewkeys(rucioOutput)) - set(viewkeys(dbsOutput)))
logger.info("Blocks in DBS but not in Rucio: %s", set(viewkeys(dbsOutput)) - set(viewkeys(rucioOutput)))
logger.info("Blocks in Rucio but not in DBS: %s", set(rucioOutput.keys()) - set(dbsOutput.keys()))
logger.info("Blocks in DBS but not in Rucio: %s", set(dbsOutput.keys()) - set(rucioOutput.keys()))

for blockname in rucioOutput:
if blockname not in dbsOutput:
logger.error("This block does not exist in DBS: %s", blockname)
continue
if rucioOutput[blockname] != sum(viewvalues(dbsOutput[blockname])):
if rucioOutput[blockname] != sum(dbsOutput[blockname].values()):
logger.warning("Block with file mismatch: %s", blockname)
logger.warning("\tRucio: %s\t\tDBS: %s", rucioOutput[blockname], sum(viewvalues(dbsOutput[blockname])))
logger.warning("\tRucio: %s\t\tDBS: %s", rucioOutput[blockname], sum(dbsOutput[blockname].values()))


if __name__ == "__main__":
Expand Down
9 changes: 4 additions & 5 deletions bin/adhoc-scripts/checkStuckLQE.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
local workqueue elements and print a summary of work/data location
for the elements sitting in the Available status
"""
from __future__ import print_function, division


from builtins import next
from future.utils import viewvalues, listvalues

import sys
import os
Expand Down Expand Up @@ -58,14 +57,14 @@ def commonDataLocation(element):
"""
commonLoc = set()
if element['PileupData']:
commonLoc = set(next(iter(viewvalues(element['PileupData']))))
commonLoc = set(next(iter(element['PileupData'].values())))
if element['Inputs']:
if commonLoc:
commonLoc = commonLoc & set(next(iter(viewvalues(element['Inputs']))))
commonLoc = commonLoc & set(next(iter(element['Inputs'].values())))
else:
commonLoc = set(list(element['Inputs'].values())[0])
if element['ParentData']:
tempLoc = listvalues(element['ParentData'])
tempLoc = list(element['ParentData'].values())
parentLoc = set(tempLoc[0])
for temp in tempLoc:
parentLoc = parentLoc & set(temp)
Expand Down
5 changes: 2 additions & 3 deletions bin/adhoc-scripts/drainAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
NOTE: you need to source the agent environment:
source apps/wmagent/etc/profile.d/init.sh
"""
from __future__ import print_function, division


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

import argparse
import logging
Expand Down Expand Up @@ -165,7 +164,7 @@ def getDsetAndWf(lfns, wfsDict):

match = []
for dset in uniqDsets:
for wf, values in viewitems(wfsDict):
for wf, values in wfsDict.items():
if dset in values['OutputDatasets']:
match.append((wf, values['RequestStatus'], dset))
if match:
Expand Down
2 changes: 1 addition & 1 deletion bin/adhoc-scripts/getWQStatusByWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
NOTE: you need to source the agent environment:
source apps/wmagent/etc/profile.d/init.sh
"""
from __future__ import print_function, division


import os
import sys
Expand Down
13 changes: 6 additions & 7 deletions bin/adhoc-scripts/parseUnifiedCampaigns.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@
python parseUnifiedCampaigns.py --fin=wmcore_campaign.json --url=https://alancc7-cloud2.cern.ch/reqmgr2
--verbose=10 --testcamp
"""
from __future__ import print_function, division


from builtins import object
from future.utils import viewitems

import argparse
import json
Expand Down Expand Up @@ -128,7 +127,7 @@ def getSecondaryAAA(initialValue, uniRecord):
* under the secondaries dictionary.
If it appears multiple times, we make an OR of the values.
"""
for _, innerDict in viewitems(uniRecord.get("secondaries", {})):
for _, innerDict in uniRecord.get("secondaries", {}).items():
if "secondary_AAA" in innerDict:
print("Found internal secondary_AAA for campaign: %s" % uniRecord['name'])
initialValue = initialValue or innerDict["secondary_AAA"]
Expand Down Expand Up @@ -161,7 +160,7 @@ def getSecondaryLocation(initialValue, uniRecord):
* under the secondaries dictionary.
If it appears multiple times, we make an intersection of the values.
"""
for _, innerDict in viewitems(uniRecord.get("secondaries", {})):
for _, innerDict in uniRecord.get("secondaries", {}).items():
if "SecondaryLocation" in innerDict:
print("Found internal SecondaryLocation for campaign: %s" % uniRecord['name'])
initialValue = intersect(initialValue, innerDict["SecondaryLocation"])
Expand All @@ -178,7 +177,7 @@ def getSecondaries(initialValue, uniRecord):
* taken from the SiteWhitelist key or
* taken from the SecondaryLocation one
"""
for dset, innerDict in viewitems(uniRecord.get("secondaries", {})):
for dset, innerDict in uniRecord.get("secondaries", {}).items():
print("Found secondaries for campaign: %s" % uniRecord['name'])
initialValue[dset] = intersect(innerDict.get("SiteWhitelist", []),
innerDict.get("SecondaryLocation", []))
Expand Down Expand Up @@ -224,7 +223,7 @@ def parse(istream, verbose=0):
conf = dict(confRec)
# Set default value from top level campaign configuration
# or use the default values defined above
for uniKey, wmKey in viewitems(remap):
for uniKey, wmKey in remap.items():
conf[wmKey] = rec.get(uniKey, conf[wmKey])

conf['SiteWhiteList'] = getSiteList("SiteWhitelist", conf['SiteWhiteList'], rec)
Expand Down Expand Up @@ -330,7 +329,7 @@ def main():
campData = json.load(istream)
if isinstance(campData, dict):
# then it's a Unified-like campaign schema
for key, val in viewitems(campData):
for key, val in campData.items():
rec = {'name': key}
rec.update(val)
data.append(rec)
Expand Down
3 changes: 0 additions & 3 deletions bin/adhoc-scripts/setrequeststatus.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
"""
This script can be used to update the status of a request in ReqMgr2.
"""
from __future__ import print_function, division

from future import standard_library
standard_library.install_aliases()
import http.client
import json
import os
Expand Down
7 changes: 1 addition & 6 deletions bin/adhoc-scripts/summaryWMStatsFailures.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@
type of failures, files skipped per agent; as well as an overview of failures
per task
"""
from __future__ import print_function, division

from future.utils import viewitems

from future import standard_library
standard_library.install_aliases()
import http.client
import json
import os
Expand Down Expand Up @@ -47,7 +42,7 @@ def main():
print(" Skipped files: %s" % pformat(data[agent]['skipped']))
print(" Overall agent status:\t\t %s" % data[agent]['status'])

for task, values in viewitems(data[agent]['tasks']):
for task, values in data[agent]['tasks'].items():
if values['jobtype'] not in ['Production', 'Processing', 'Merge', 'Harvest']:
# print("Skipping task type %s, for %s" % (values['jobtype'], task))
continue
Expand Down
4 changes: 2 additions & 2 deletions bin/adhoc-scripts/updateTotalStats.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def main():
msDbg = MSDbg(msConfig, logger=logger)

badWfList = []
reqList = msDbg.getRequestRecords(reqStatus).values()
reqList = list(msDbg.getRequestRecords(reqStatus).values())

allReqTypes = {req['RequestType'] for req in reqList}
logger.info("All possible request types: \n%s", pformat(allReqTypes))
Expand All @@ -120,7 +120,7 @@ def main():

for wflow in reqList:
# First check if the current workflwo suffers the issue:
if not keySetToCheck < wflow.keys():
if not keySetToCheck < list(wflow.keys()):
# Create a `tmp` key to fill in all the information we'll need in the follwoing steps.
wflow['tmp'] = {}

Expand Down
11 changes: 1 addition & 10 deletions bin/check-ACDC-parentage
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
#!/usr/bin/env python
from __future__ import print_function, division
from future import standard_library
standard_library.install_aliases()
from future.utils import viewitems

import json
import time
import http.client
import os

from pprint import pprint
from collections import defaultdict

from dbs.apis.dbsClient import DbsApi

def callRESTAPI(restURL, url="cmsweb.cern.ch"):
conn = http.client.HTTPSConnection(url, cert_file=os.getenv('X509_USER_CERT'),
Expand All @@ -35,7 +26,7 @@ def investigateACDCCollection(workflow):
if "rows" in result:
if result["rows"]:
for row in result["rows"]:
for inFile, value in viewitems(row["doc"]["files"]):
for inFile, value in row["doc"]["files"].items():
if not value["merged"] or value["merged"] == "0":
if value["parents"] and "/unmerged/" in value["parents"][0]:
missingFiles.add(inFile)
Expand Down
1 change: 0 additions & 1 deletion bin/check-phedex-dbs-status
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import (print_function, division)

from WMComponent.DBS3Buffer.DBSBufferUtil import DBSBufferUtil
from WMCore.WMInit import connectToDB
Expand Down
11 changes: 4 additions & 7 deletions bin/check-request-wq-status
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function, division

from future.utils import viewvalues

import os
from argparse import ArgumentParser
Expand Down Expand Up @@ -34,14 +31,14 @@ def getAcceptableSites(ele):

if ele['Inputs']:
if commonSites:
commonSites = commonSites & set([y for x in viewvalues(ele['Inputs']) for y in x])
commonSites = commonSites & set([y for x in ele['Inputs'].values() for y in x])
else:
commonSites = set([y for x in viewvalues(ele['Inputs']) for y in x])
commonSites = set([y for x in ele['Inputs'].values() for y in x])
if ele['PileupData']:
if commonSites:
commonSites = commonSites & set([y for x in viewvalues(ele['PileupData']) for y in x])
commonSites = commonSites & set([y for x in ele['PileupData'].values() for y in x])
else:
commonSites = set([y for x in viewvalues(ele['PileupData']) for y in x])
commonSites = set([y for x in ele['PileupData'].values() for y in x])

return commonSites

Expand Down
2 changes: 1 addition & 1 deletion bin/combineMinifyWMStats.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import print_function

from glob import iglob
import shutil
import os
Expand Down
2 changes: 1 addition & 1 deletion bin/couch_archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Replicate an agent's jobdump to another couch machine.
"""
from __future__ import print_function


import os
import sys
Expand Down
5 changes: 0 additions & 5 deletions bin/createStoreResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@
"""

from __future__ import print_function, division

from future import standard_library
standard_library.install_aliases()

import http.client
import json
import os
Expand Down
7 changes: 1 addition & 6 deletions bin/dbsbuffer-file-fix.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
"""
"""
from __future__ import print_function

from future.utils import listvalues

import logging
import os
import sys
import threading

from WMCore.Database.CMSCouch import Database
from WMCore.Database.DBFormatter import DBFormatter
from WMCore.WMInit import connectToDB

Expand Down Expand Up @@ -38,7 +33,7 @@ def fixDBSmissingFileAssoc():
print("trimed %s lenth" % len(result))
insertSQL = """INSERT INTO dbsbuffer_file_location (filename, location)
VALUES (:fileid, :seid)"""
done = formatter.dbi.processData(insertSQL, listvalues(result))
done = formatter.dbi.processData(insertSQL, list(result.values()))
print("inserted %s" % done)

if __name__ == '__main__':
Expand Down
2 changes: 0 additions & 2 deletions bin/fix-dbs-parentage
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ $manage execute-agent fix-dbs-parentage -p --insert -d /SingleMuon/Run2016D-03Fe
"""

from __future__ import print_function, division

from builtins import input
import time
import datetime
Expand Down
1 change: 0 additions & 1 deletion bin/inject-to-config-cache
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ _inject-to-config-cache_
Add a config and it's meta data to the config cache.
"""
from __future__ import print_function

import os
import sys
Expand Down
4 changes: 2 additions & 2 deletions bin/kill-workflow-in-agent
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Script for killing a workflow: delete from LQ, delete in WMBS and set cancelled
This has to be executed in each agent the workflow is running in (Agent Level)
"""
from __future__ import print_function
from builtins import str
import os, sys
import os
import sys
from WMCore.Configuration import loadConfigurationFile
from WMCore.WorkQueue.WorkQueueBackend import WorkQueueBackend
from WMCore.WMInit import connectToDB
Expand Down
1 change: 0 additions & 1 deletion bin/kill-workflow-in-global
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ This script will mark the global workqueue elements - for a given
workflow - as CancelRequested, such that the agents can proceed
and acknowledge it, moving elements to status Canceled.
"""
from __future__ import print_function

import os
import sys
Expand Down
4 changes: 0 additions & 4 deletions bin/outputmodules-from-config
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ _outputmodules-from-config_
Pull output module metadata from a CMSSW config.
"""
from __future__ import print_function

from future import standard_library
standard_library.install_aliases()
import urllib.request

import imp
Expand Down
1 change: 0 additions & 1 deletion bin/paused-jobs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
from __future__ import print_function

from builtins import input, object

Expand Down
Loading

0 comments on commit a2d28d5

Please sign in to comment.