Skip to content
Open
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
3 changes: 0 additions & 3 deletions .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
fail-fast: false
matrix:
python:
- 2.7.18
- 3.6.15
- 3.9.17

Expand Down Expand Up @@ -55,7 +54,6 @@ jobs:
fail-fast: false
matrix:
python:
- 2.7.18
- 3.6.15
- 3.9.17

Expand All @@ -82,7 +80,6 @@ jobs:
fail-fast: false
matrix:
python:
- 2.7.18
- 3.6.15
- 3.9.17

Expand Down
4 changes: 0 additions & 4 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,3 @@ dummy-variables=_
disable=
invalid-name,
line-too-long, # would be nice to remove this one
consider-using-f-string, # python2/3 support
unspecified-encoding, # python2/3 support
super-with-arguments, # python2/3 support
redefined-builtin, # python2/3 support
33 changes: 8 additions & 25 deletions Pilot/dirac-pilot.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,19 @@
But, as said, all the actions are actually configurable.
"""

from __future__ import absolute_import, division, print_function

import os
import sys
import time
from io import StringIO

############################
# python 2 -> 3 "hacks"

try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
from .pilotTools import (
Logger,
PilotParams,
RemoteLogger,
getCommand,
pythonPathCheck,
)

try:
from Pilot.pilotTools import (
Logger,
PilotParams,
RemoteLogger,
getCommand,
pythonPathCheck,
)
except ImportError:
from pilotTools import (
Logger,
PilotParams,
RemoteLogger,
getCommand,
pythonPathCheck,
)
############################

if __name__ == "__main__":
Expand Down
38 changes: 6 additions & 32 deletions Pilot/pilotCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ def __init__(self, pilotParams):
execution.
"""

from __future__ import absolute_import, division, print_function

import filecmp
import os
import platform
Expand All @@ -28,39 +26,18 @@ def __init__(self, pilotParams):
import sys
import time
import traceback
import subprocess
from collections import Counter
from http.client import HTTPSConnection
from shlex import quote

############################
# python 2 -> 3 "hacks"
try:
# For Python 3.0 and later
from http.client import HTTPSConnection
except ImportError:
# Fall back to Python 2
from httplib import HTTPSConnection

try:
from shlex import quote
except ImportError:
from pipes import quote

try:
from Pilot.pilotTools import (
CommandBase,
getSubmitterInfo,
retrieveUrlTimeout,
safe_listdir,
sendMessage,
)
except ImportError:
from pilotTools import (
from .pilotTools import (
CommandBase,
getSubmitterInfo,
retrieveUrlTimeout,
safe_listdir,
sendMessage,
)

############################


Expand Down Expand Up @@ -283,7 +260,7 @@ def _getPreinstalledEnvScript(self):
self.pp.installEnv["DIRAC_RC_PATH"] = preinstalledEnvScript

def _localInstallDIRAC(self):
"""Install python3 version of DIRAC client"""
"""Install DIRAC client"""

self.log.info("Installing DIRAC locally")

Expand All @@ -296,10 +273,7 @@ def _localInstallDIRAC(self):

# 1. Get the DIRACOS installer name
# curl -O -L https://github.com/DIRACGrid/DIRACOS2/releases/latest/download/DIRACOS-Linux-$(uname -m).sh
try:
machine = os.uname().machine # py3
except AttributeError:
machine = os.uname()[4] # py2
machine = os.uname().machine

installerName = "DIRACOS-Linux-%s.sh" % machine

Expand Down
125 changes: 26 additions & 99 deletions Pilot/pilotTools.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""A set of common tools to be used in pilot commands"""

from __future__ import absolute_import, division, print_function

import fcntl
import getopt
import importlib.util
import json
import os
import re
Expand All @@ -16,81 +15,23 @@
import warnings
from datetime import datetime
from functools import partial, wraps
from threading import RLock

############################
# python 2 -> 3 "hacks"
try:
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import urlopen
except ImportError:
from urllib import urlencode

from urllib2 import HTTPError, URLError, urlopen

try:
import importlib.util
from importlib import import_module

def load_module_from_path(module_name, path_to_module):
spec = importlib.util.spec_from_file_location(module_name, path_to_module) # pylint: disable=no-member
module = importlib.util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module)
return module

except ImportError:
from importlib import import_module
from io import StringIO
from threading import RLock, Timer
from urllib.error import HTTPError, URLError
from urllib.parse import urlencode
from urllib.request import urlopen

def import_module(module):
import imp
from .proxyTools import getVO

impData = imp.find_module(module)
return imp.load_module(module, *impData)
# Utilities functions

def load_module_from_path(module_name, path_to_module):
import imp

fp, pathname, description = imp.find_module(module_name, [path_to_module])
try:
return imp.load_module(module_name, fp, pathname, description)
finally:
if fp:
fp.close()


try:
from cStringIO import StringIO
except ImportError:
from io import StringIO

try:
basestring # pylint: disable=used-before-assignment
except NameError:
basestring = str

try:
from Pilot.proxyTools import getVO
except ImportError:
from proxyTools import getVO

try:
FileNotFoundError # pylint: disable=used-before-assignment
# because of https://github.com/PyCQA/pylint/issues/6748
except NameError:
FileNotFoundError = OSError

try:
IsADirectoryError # pylint: disable=used-before-assignment
except NameError:
IsADirectoryError = IOError

# Timer 2.7 and < 3.3 versions issue where Timer is a function
if sys.version_info.major == 2 or sys.version_info.major == 3 and sys.version_info.minor < 3:
from threading import _Timer as Timer # pylint: disable=no-name-in-module
else:
from threading import Timer

# Utilities functions
def load_module_from_path(module_name, path_to_module):
spec = importlib.util.spec_from_file_location(module_name, path_to_module) # pylint: disable=no-member
module = importlib.util.module_from_spec(spec) # pylint: disable=no-member
spec.loader.exec_module(module)
return module


def parseVersion(releaseVersion):
Expand Down Expand Up @@ -399,7 +340,7 @@ def loadModule(self, modName, hideExceptions=False):

def __recurseImport(self, modName, parentModule=None, hideExceptions=False):
"""Internal function to load modules"""
if isinstance(modName, basestring):
if isinstance(modName, str):
modName = modName.split(".")
try:
if parentModule:
Expand Down Expand Up @@ -713,11 +654,7 @@ def sendMessage(url, pilotUUID, wnVO, method, rawMessage):
context.load_cert_chain(os.path.join(cert, "hostcert.pem"), os.path.join(cert, "hostkey.pem"))
raw_data = {"method": method, "args": message, "extraCredentials": '"hosts"'}

if sys.version_info.major == 3:
data = urlencode(raw_data).encode("utf-8") # encode to bytes ! for python3
else:
# Python2
data = urlencode(raw_data)
data = urlencode(raw_data).encode("utf-8") # encode to bytes

res = urlopen(url, data, context=context)
res.close()
Expand Down Expand Up @@ -787,17 +724,7 @@ def executeAndGetOutput(self, cmd, environDict=None):
if not outChunk:
continue
dataWasRead = True
if sys.version_info.major == 2:
# Ensure outChunk is unicode in Python 2
if isinstance(outChunk, str):
outChunk = outChunk.decode("utf-8")
# Strip unicode replacement characters
# Ensure correct type conversion in Python 2
outChunk = str(outChunk.replace(u"\ufffd", ""))
# Avoid potential str() issues in Py2
outChunk = unicode(outChunk) # pylint: disable=undefined-variable
else:
outChunk = str(outChunk.replace("\ufffd", "")) # Python 3: Ensure it's a string
outChunk = str(outChunk.replace("\ufffd", "")) # Ensure it's a string

if stream == _p.stderr:
sys.stderr.write(outChunk)
Expand Down Expand Up @@ -1455,7 +1382,7 @@ def __initJSON(self):
# Commands first
# FIXME: pilotSynchronizer() should publish these as comma-separated lists. We are ready for that.
try:
if isinstance(self.pilotJSON["Setups"][self.setup]["Commands"][self.gridCEType], basestring):
if isinstance(self.pilotJSON["Setups"][self.setup]["Commands"][self.gridCEType], str):
self.commands = [
str(pv).strip()
for pv in self.pilotJSON["Setups"][self.setup]["Commands"][self.gridCEType].split(",")
Expand All @@ -1466,7 +1393,7 @@ def __initJSON(self):
]
except KeyError:
try:
if isinstance(self.pilotJSON["Setups"][self.setup]["Commands"]["Defaults"], basestring):
if isinstance(self.pilotJSON["Setups"][self.setup]["Commands"]["Defaults"], str):
self.commands = [
str(pv).strip()
for pv in self.pilotJSON["Setups"][self.setup]["Commands"]["Defaults"].split(",")
Expand All @@ -1477,7 +1404,7 @@ def __initJSON(self):
]
except KeyError:
try:
if isinstance(self.pilotJSON["Setups"]["Defaults"]["Commands"][self.gridCEType], basestring):
if isinstance(self.pilotJSON["Setups"]["Defaults"]["Commands"][self.gridCEType], str):
self.commands = [
str(pv).strip()
for pv in self.pilotJSON["Setups"]["Defaults"]["Commands"][self.gridCEType].split(",")
Expand All @@ -1488,7 +1415,7 @@ def __initJSON(self):
]
except KeyError:
try:
if isinstance(self.pilotJSON["Defaults"]["Commands"]["Defaults"], basestring):
if isinstance(self.pilotJSON["Defaults"]["Commands"]["Defaults"], str):
self.commands = [
str(pv).strip() for pv in self.pilotJSON["Defaults"]["Commands"]["Defaults"].split(",")
]
Expand All @@ -1504,7 +1431,7 @@ def __initJSON(self):
# pilotSynchronizer() can publish this as a comma separated list. We are ready for that.
try:
if isinstance(
self.pilotJSON["Setups"][self.setup]["CommandExtensions"], basestring
self.pilotJSON["Setups"][self.setup]["CommandExtensions"], str
): # In the specific setup?
self.commandExtensions = [
str(pv).strip() for pv in self.pilotJSON["Setups"][self.setup]["CommandExtensions"].split(",")
Expand All @@ -1516,7 +1443,7 @@ def __initJSON(self):
except KeyError:
try:
if isinstance(
self.pilotJSON["Setups"]["Defaults"]["CommandExtensions"], basestring
self.pilotJSON["Setups"]["Defaults"]["CommandExtensions"], str
): # Or in the defaults section?
self.commandExtensions = [
str(pv).strip() for pv in self.pilotJSON["Setups"]["Defaults"]["CommandExtensions"].split(",")
Expand All @@ -1533,7 +1460,7 @@ def __initJSON(self):
# pilotSynchronizer() can publish this as a comma separated list. We are ready for that
try:
if isinstance(
self.pilotJSON["ConfigurationServers"], basestring
self.pilotJSON["ConfigurationServers"], str
): # Generic, there may also be setup-specific ones
self.configServer = ",".join(
[str(pv).strip() for pv in self.pilotJSON["ConfigurationServers"].split(",")]
Expand All @@ -1544,7 +1471,7 @@ def __initJSON(self):
pass
try: # now trying to see if there is setup-specific ones
if isinstance(
self.pilotJSON["Setups"][self.setup]["ConfigurationServer"], basestring
self.pilotJSON["Setups"][self.setup]["ConfigurationServer"], str
): # In the specific setup?
self.configServer = ",".join(
[str(pv).strip() for pv in self.pilotJSON["Setups"][self.setup]["ConfigurationServer"].split(",")]
Expand All @@ -1556,7 +1483,7 @@ def __initJSON(self):
except KeyError: # and if it doesn't exist
try:
if isinstance(
self.pilotJSON["Setups"]["Defaults"]["ConfigurationServer"], basestring
self.pilotJSON["Setups"]["Defaults"]["ConfigurationServer"], str
): # Is there one in the defaults section?
self.configServer = ",".join(
[
Expand Down
2 changes: 0 additions & 2 deletions Pilot/proxyTools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""few functions for dealing with proxies"""

from __future__ import absolute_import, division, print_function

import re
from base64 import b16decode
from subprocess import PIPE, Popen
Expand Down
Loading