From e39a65c28890c9104410c8fb9a5bb671209837f9 Mon Sep 17 00:00:00 2001 From: Guillaume Raffy Date: Wed, 10 Jul 2019 08:34:42 +0000 Subject: [PATCH] Made clusterconfigurator code comply (mostly) to pylint and mypy best practices while working on bug 2701. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As a result, clusterconfigurator no longer pesses with hardcoded sys.path, we now use PYTHONPATH, which is somewhat cleaner. As mypy doesn't support python2, I had to migrate code from python2 to python3. Because some libraries are shared between all python code, python2 code using these libraries will be broken while all python code is not upgraded to python3. Bug 2701 - mettre en place un mécanisme pour éviter le blocage des gpu par des jobs cpu --- SunGridEngine/SgeConfig.py | 8 ++++---- Util.py | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SunGridEngine/SgeConfig.py b/SunGridEngine/SgeConfig.py index 432c8e8..a37a6d8 100755 --- a/SunGridEngine/SgeConfig.py +++ b/SunGridEngine/SgeConfig.py @@ -74,7 +74,7 @@ class SgeConfig: self.m_attrs[ matchObj.group("attrName") ] = matchObj.group("attrValue") def asFormat1String( self ): strResult = "" - for (k,v) in self.m_attrs.iteritems(): + for (k,v) in self.m_attrs.items(): #print "%s %s" % (k,v) strResult += "%s %s\n" % (k,v) #print strSgeConfigString @@ -85,7 +85,7 @@ class SgeConfig: if iNumAttrs == 0: return "NONE" iAttr = 0 - for (k,v) in self.m_attrs.iteritems(): + for (k,v) in self.m_attrs.items(): #print "%s %s" % (k,v) strResult += "%s=%s" % (k,v) if iAttr != (iNumAttrs - 1): @@ -94,7 +94,7 @@ class SgeConfig: #print strSgeConfigString return strResult def dump( self ): - for (k,v) in self.m_attrs.iteritems(): - print "['%s']='%s'" % (k,v) + for (k,v) in self.m_attrs.items(): + print("['%s']='%s'" % (k,v)) diff --git a/Util.py b/Util.py index 188e615..d3616bf 100644 --- a/Util.py +++ b/Util.py @@ -6,8 +6,8 @@ import re # import os # import signal import smtplib -from email.MIMEText import MIMEText -from HTMLParser import HTMLParser +from email.mime.text import MIMEText +from html.parser import HTMLParser def sendTextMail(strFrom, to, strSubject, text): @@ -37,7 +37,7 @@ def getHostName(): def log(message): - print time.asctime(time.localtime()) + ' : ' + message + print(time.asctime(time.localtime()) + ' : ' + message) def executeProgram(astrArguments): @@ -45,7 +45,7 @@ def executeProgram(astrArguments): popen = subprocess.Popen( astrArguments, bufsize=1, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) # bufsize=1 seems to prevent deadlocks that happen 50% the time stdout, stderr = popen.communicate() # popen.wait() - result = (popen.returncode, stdout, stderr) + result = (popen.returncode, stdout.decode(), stderr) # log('executeProgram : command %s popen.pid = %d' % (astrArguments[0], popen.pid)) # os.kill(popen.pid, signal.SIGTERM) return result @@ -59,7 +59,7 @@ def executeCommand(command): # if we don't specify the optional executable argument, then the default non interactive shell will be used. On debian, the default non-interactive shell is dash, which doesn't understand the keyword 'source' that we use in many places stdout, stderr = popen.communicate() # popen.wait() - result = (popen.returncode, stdout, stderr) + result = (popen.returncode, stdout.decode(), stderr.decode()) return result @@ -99,15 +99,15 @@ def getUpsStatus(): def GetTokenList(self): return self.TokenList - import urllib2 + from urllib.request import urlopen try: url = 'http://Net Vision:public@129.20.27.119/PageMonComprehensive.html' - f = urllib2.urlopen(url) + f = urlopen(url) res = f.read() f.close() except: - print "bad read" + print("bad read") return h = MyHTMLParser() h.feed(res)