Made clusterconfigurator code comply (mostly) to pylint and mypy best practices while working on bug 2701.

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
This commit is contained in:
Guillaume Raffy 2019-07-10 08:34:42 +00:00
parent 13d52fd4d4
commit e39a65c288
2 changed files with 12 additions and 12 deletions

View File

@ -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))

16
Util.py
View File

@ -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)