Commit b48b14c0 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Python: more fixes for running recent versions


Signed-off-by: Nicola Vigano's avatarNicola Vigano <nicola.vigano@esrf.fr>
parent 1fb1b0a4
......@@ -106,7 +106,7 @@ class DCTBatch(object):
return DCTBatch(dct_dir=dct_dir, dev_mode=dev_mode)
def __init__(self, dct_dir="", dev_mode=False):
if dct_dir is "":
if dct_dir == "":
dct_dir = os.path.abspath(os.path.dirname(sys.argv[0]))
if os.path.basename(dct_dir) == "zUtil_Python":
dct_dir = os.path.dirname(dct_dir)
......@@ -184,7 +184,7 @@ class DCTBatch(object):
return functions
def monitor_array(self, array, delay=10, timeout=None):
if oar_available is not True:
if not oar_available:
raise EnvironmentError("OAR service is not available!")
monitor = oar_utils.OARMonitorArray(array=array)
......
......@@ -26,14 +26,8 @@ def convert_timestamp_to_string(tstamp):
class DCTBatchGui(QtGui.QWidget):
"""
classdocs
"""
def __init__(self, cwd=""):
"""
Constructor
"""
super(DCTBatchGui, self).__init__()
self.qapi = oar_api.OarAPI(api_type="CmdAPI")
self.arrays = {}
......@@ -460,7 +454,7 @@ class DCTBatchGui(QtGui.QWidget):
stop_time,
resub_id,
]
if True in (not isinstance(x, basestring) for x in job_info):
if not all(isinstance(x, str) for x in job_info):
raise ValueError(
(
"Display Job Info: Some of the items for "
......
......@@ -9,14 +9,8 @@ from PyQt4 import QtCore
class DCTBatchOarParameters(object):
"""
classdocs
"""
def __init__(self, parent, stream=None):
"""
Constructor
"""
self.parent = parent
self.arrays = []
self.array_ids = {}
......@@ -104,7 +98,7 @@ class DCTBatchOarParameters(object):
for aid in array_ids:
print("Query Array ID: %d" % aid)
content = self.parent.qapi.query(array=aid)
if len(content) is not 0:
if len(content) > 0:
arrays_content.update(content)
else:
print(" - Skipping because not valid any more!")
......
......@@ -17,7 +17,7 @@ class MexBuilder(object):
@staticmethod
def getInstanceFromArgs(args, dct_dir=""):
if dct_dir is "":
if dct_dir == "":
dct_dir = os.path.abspath(os.path.dirname(args[0]))
dct_dir = os.path.join(dct_dir, os.path.pardir)
dct_dir = os.path.abspath(dct_dir)
......@@ -227,8 +227,8 @@ class MexBuilder(object):
os.makedirs(self.outdir)
self.out.printSubJob("Compiling mex files:")
if (len(self.mfiles_to_consider) is 0) or (
(len(self.mfiles_to_consider) is 1) and (self.mfiles_to_consider[0] == "all")
if (len(self.mfiles_to_consider) == 0) or (
(len(self.mfiles_to_consider) == 1) and (self.mfiles_to_consider[0] == "all")
):
# No preferences, so let's compile everything
files_to_compile = self.c_files
......@@ -246,21 +246,21 @@ class MexBuilder(object):
for cfile in self.c_files:
if re.search(file_name, cfile) is not None:
match_list.append(cfile)
if len(match_list) is 0:
if len(match_list) == 0:
errorMsg = "No file corresponds to: %s" % file_name
DCTOutput.printError(errorMsg)
dct_io_xml.DCTOutput.printError(errorMsg)
listOfErrors.append(errorMsg)
# Let's compile each match
for cfile in match_list:
ret_val = self._compile_mex_file(cfile)
if ret_val is not 0:
if ret_val != 0:
listOfErrors.append("Error compiling MEX: %s (Return Value: %d)" % (file_name, ret_val))
print("")
if len(listOfErrors) is not 0:
if len(listOfErrors) > 0:
print("Errors happened during compilation:")
for errorMsg in listOfErrors:
DCTOutput.printError("- %s" % errorMsg)
dct_io_xml.DCTOutput.printError("- %s" % errorMsg)
if __name__ == "__main__":
......@@ -269,9 +269,9 @@ if __name__ == "__main__":
mex_builder.find_mex_files()
mex_builder.compile_mex_files()
except ValueError as ex:
if (len(ex.args) is not 0) and (ex.args[0] is not ""):
DCTOutput.printError(ex.args)
if (len(ex.args) > 0) and (ex.args[0] != ""):
dct_io_xml.DCTOutput.printError(ex.args)
MexBuilder("").print_help()
except BaseException as ex:
DCTOutput.printError(ex.args)
dct_io_xml.DCTOutput.printError(ex.args)
exit(1)
......@@ -12,7 +12,7 @@ import fnmatch
try:
import lxml.etree as ET
except ImportError as ex:
except ImportError:
print("Couldn't import lxml. Trying with standard distribution.")
try:
import xml.etree.ElementTree as ET
......@@ -75,8 +75,9 @@ class DCTCheck(object):
try:
os.chdir(dctdir)
testdir = os.getcwd()
except:
raise EnvironmentError("DCT_DIR environment variable (%s) points to inexistent directory!" % dctdir)
except FileNotFoundError:
print("DCT_DIR environment variable (%s) points to inexistent directory!" % dctdir)
raise
os.chdir(indir)
if indir == testdir:
print("OK")
......@@ -234,7 +235,7 @@ class DCTConfUpdater(object):
def cleanup(self, file_name):
try:
self.backup(file_name)
except:
except ValueError:
print("Configuration already cleaned")
def copy(self, src_path, dest_filename):
......@@ -245,7 +246,7 @@ class DCTConfUpdater(object):
def safely_install_new_file(self, src_path, dest_filename):
try:
self.backup(dest_filename)
except:
except ValueError:
print("Creating new file: '%s'" % dest_filename)
self.copy(src_path, dest_filename)
......
......@@ -74,11 +74,11 @@ class DCTSetup(object):
else:
skip_next = False
if self.branch is "":
if self.branch == "":
self.branch = "master"
if self.repo_dir is "":
if self.branch is "master":
if self.repo_dir == "":
if self.branch == "master":
self.repo_dir = "dct"
else:
stable_ver = self.branch.split("_")
......@@ -91,7 +91,7 @@ class DCTSetup(object):
for arg in unclassified_args:
DCTOutput.printWarning("Unused argument: %s" % arg)
except ValueError as ex:
if (len(ex.args) is not 0) and (ex.args[0] is not ""):
if (len(ex.args) > 0) and (ex.args[0] != ""):
DCTOutput.printError(ex.args)
self.print_help()
......@@ -116,7 +116,7 @@ class DCTSetup(object):
def printRepoSummary(self):
print("\nGit repository information:")
if self.sf_username is not "":
if self.sf_username != "":
self.out.printInfoRecord("Mode", "Developer")
self.out.printInfoRecord("Sourceforge Username", self.sf_username)
self.out.printInfoRecord("User Real Name", self.user_real_name)
......@@ -143,7 +143,7 @@ class DCTSetup(object):
self.gcc_version = platform_utils.checkGccVersion()
def prepareUserEnvironment(self, proxy=""):
if proxy is not "":
if proxy != "":
dct_utils_git.DCTGit.setGlobalConfig("http.proxy", proxy)
def prepareDeveloperEnvironment(self, utils):
......@@ -175,7 +175,7 @@ if __name__ == "__main__":
try:
dct_sup.checkSystem(utils)
dct_sup.prepareUserEnvironment("proxy.esrf.fr:3128") # assuming ESRF
if dct_sup.sf_username is not "":
if dct_sup.sf_username != "":
dct_sup.prepareDeveloperEnvironment(utils)
except ValueError as ex:
DCTOutput.printError(ex.args)
......@@ -190,12 +190,12 @@ if __name__ == "__main__":
utils_git = dct_utils_git.DCTGit()
dct_sup.out.printSubJob("Cloning repository...")
if dct_sup.sf_username is not "":
if dct_sup.sf_username != "":
retcode = utils_git.createDeveloperRepo(username=dct_sup.sf_username, dest_dir=dct_sup.repo_dir, branch=dct_sup.branch)
utils_git.setRepoConfig("branch.master.rebase", "true")
else:
retcode = utils_git.createUserRepo(dest_dir=dct_sup.repo_dir, branch=dct_sup.branch)
if retcode is not 0:
if retcode != 0:
dct_sup.out.printSubJob("Directory exists. Checking it is a git repository, and updating...")
utils_git.updateRepo()
dct_sup.out.printJob("Done.")
......@@ -219,20 +219,19 @@ if __name__ == "__main__":
dct_conf = DCTConf(utils_git.repo_dir)
if dct_sup.matlab_dir is "":
if dct_sup.matlab_dir == "":
dct_sup.matlab_dir = dct_conf.getMatlabPath()
try:
utils.resetMatlabMexopts(matlabVersion=dct_sup.matlab_ver, matlabPath=dct_sup.matlab_dir)
except ex:
except ValueError:
if empty_mdir != empty_mver:
DCTOutput.printError(
"If you want to use a specific matlab version, you have to set both matlab version and path! (matlab_dir: '%s', matlab_ver: '%s')"
% (dct_sup.matlab_dir, dct_sup.matlab_ver)
"If you want to use a specific matlab version, you have to set both matlab version and path!"
+ " (matlab_dir: '%s', matlab_ver: '%s')" % (dct_sup.matlab_dir, dct_sup.matlab_ver)
)
else:
print(ex)
sys.exit(1)
raise
dct_sup.out.printJob("Done.")
print("")
......
......@@ -20,7 +20,7 @@ class DCTGit(object):
cmd = shlex.split(cmd)
subobj = subprocess.Popen(cmd, stdout=subprocess.PIPE)
retcode = subobj.wait()
if retcode is not 0:
if retcode != 0:
raise ValueError("Couldn't fetch branches information")
branches_txt = subobj.stdout.read()
......@@ -36,7 +36,7 @@ class DCTGit(object):
cmd = ["git", "config", "--global", conf_path, value]
subobj = subprocess.Popen(cmd, stderr=subprocess.PIPE)
if subobj.wait() is not 0:
if subobj.wait() != 0:
raise ValueError("Couldn't set GLOBAL property: %s, as %s." % (conf_path, value))
@staticmethod
......@@ -44,7 +44,7 @@ class DCTGit(object):
cmd = ["git", "config", "--global", conf_path]
subobj = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
if subobj.wait() is not 0:
if subobj.wait() != 0:
raise ValueError("Couldn't get GLOBAL property: %s." % conf_path)
value = subobj.stdout.read()
......@@ -56,7 +56,7 @@ class DCTGit(object):
self.repo_dir = repo_dir
def _cloneRepo(self, cmd, dest_dir="", branch=""):
if dest_dir is "":
if dest_dir == "":
dest_dir = self.repo_dir
dest_dir = os.path.join(dest_dir, "")
dest_dir = os.path.abspath(dest_dir)
......
"""
Created on Jan 30, 2013
@author: ben
@author: Nicola VIGANÒ, nicola.vigano@esrf.fr
"""
import subprocess
import os
import re
import platform
class UtilsFactory(object):
@staticmethod
def getMachineDep():
import platform
machine = platform.machine()
system = platform.system()
hostname = platform.node()
if system == "Linux":
distro = platform.linux_distribution()
ver_num_major = distro[1].split(".")[0]
distro = "".join([distro[0], ver_num_major])
return UtilsLinux(machine=machine, hostname=hostname, distro=distro)
return UtilsLinux(machine=machine, hostname=hostname)
else:
raise SystemError("Unsupported system: '%s' on machine: '%s'" % (system, machine))
......@@ -65,15 +61,14 @@ class UtilsInterface(object):
def checkSvnServers(self):
svnservers = self._getSvnServersPath()
try:
fid = open(svnservers, "r")
lines = fid.readlines()
fid.close()
searchPatterns = [
("^\s*http-proxy-host = .*", "http-proxy-host = proxy.esrf.fr"),
("^\s*http-proxy-port = .*", "http-proxy-port = 3128"),
]
searchPatterns = [
("^\s*http-proxy-host = .*", "http-proxy-host = proxy.esrf.fr"),
("^\s*http-proxy-port = .*", "http-proxy-port = 3128"),
]
try:
with open(svnservers, "r") as f:
lines = f.readlines()
for searchP, subP in searchPatterns:
for lineNum in range(len(lines)):
......@@ -83,13 +78,11 @@ class UtilsInterface(object):
break
else:
lines.append(subP)
except:
except FileNotFoundError:
print("SVN servers file: '%s' doesn't exist" % svnservers)
lines = ["http-proxy-host = proxy.esrf.fr", "http-proxy-host = proxy.esrf.fr"]
finally:
fid = open(svnservers, "w+")
fid.writelines(lines)
fid.close()
with open(svnservers, "w+") as f:
f.writelines(lines)
def getGccVersion(self):
subobj = subprocess.Popen(["g++", "--version"], stdout=subprocess.PIPE)
......@@ -128,10 +121,10 @@ class UtilsInterface(object):
mexoptsfile = self._getMatlabMexoptsPath(matlabVersion)
if os.path.exists(mexoptsfile) is True:
if os.path.exists(mexoptsfile):
os.remove(mexoptsfile)
if matlabPath is "":
if matlabPath == "":
# Try ESRF Paths
matlabPath = self._getMatlabPath(matlabVersion)
self._createMatlabMexopts(matlabVersion, matlabPath)
......@@ -139,9 +132,8 @@ class UtilsInterface(object):
stats = os.stat(mexoptsfile)
os.chmod(mexoptsfile, stats.st_mode | stat.S_IWRITE)
fid = open(mexoptsfile, "r")
lines = fid.readlines()
fid.close()
with open(mexoptsfile, "r") as f:
lines = f.readlines()
for searchP, subP in searchPatterns:
for lineNum in range(len(lines)):
......@@ -149,9 +141,8 @@ class UtilsInterface(object):
if m is not None:
lines[lineNum] = re.sub(searchP, subP, lines[lineNum])
fid = open(mexoptsfile, "w+")
fid.writelines(lines)
fid.close()
with open(mexoptsfile, "w+") as f:
f.writelines(lines)
def isMatlabNewerThan(self, test_ver, ref_ver):
major_test = test_ver[0:4]
......@@ -180,9 +171,7 @@ class UtilsInterface(object):
class UtilsLinux(UtilsInterface):
def __init__(self, machine, hostname, distro):
UtilsInterface.__init__(self, machine=machine, hostname=hostname)
self.distro = distro
"""Linux specific utility class"""
def getUserConfDir(self, dct_version):
return os.path.join(os.getenv("HOME"), ".dct", dct_version)
......@@ -191,7 +180,7 @@ class UtilsLinux(UtilsInterface):
return os.path.join(os.getenv("HOME"), ".dct", dct_version, file_name)
def getSystemDescription(self):
return " ".join([self.distro, self.machine])
return "Linux-" + self.machine
def _getSvnServersPath(self):
userpath = os.getenv("HOME", "")
......@@ -243,10 +232,6 @@ class UtilsLinux(UtilsInterface):
('(CXXLIBS="\$RPATH \$MLIBS -lm)"', '\g<1> -fopenmp"'),
]
if self.distro == "CentOS5":
searchPatterns.append(("CC='gcc'", "CC='gcc44'"))
searchPatterns.append(("CXX='g\+\+'", "CXX='g++44'"))
UtilsInterface.resetMatlabMexopts(
self, searchPatterns=searchPatterns, matlabVersion=matlabVersion, matlabPath=matlabPath
)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment