Pass cpuset through Futurize

Signed-off-by: Libor Pechacek <lpechacek@suse.com>
python3
Libor Pechacek 7 years ago
parent 011f52297d
commit 1344191105

@ -1,6 +1,8 @@
"""Process manipulation command
"""
from builtins import str
from builtins import range
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -654,7 +656,7 @@ def pidspec_to_list(pidspec, fset=None, threads=False):
log.debug('thread matching activated, looking for threads...')
dups = 0
hits = 0
for task in pdict.keys():
for task in list(pdict.keys()):
dirs = os.listdir('/proc/'+str(task)+'/task')
if len(dirs) > 1:
hits += 1
@ -664,7 +666,7 @@ def pidspec_to_list(pidspec, fset=None, threads=False):
continue
pdict[thread] = True
log.debug('found %s multithreaded containers and %s duplicates', hits, dups)
plist = pdict.keys()
plist = list(pdict.keys())
log.debug('returning parsed pid list of %s tasks: %s', len(plist), plist)
return plist

@ -1,6 +1,9 @@
"""Cpuset manipulation command
"""
from __future__ import division
from builtins import str
from past.utils import old_div
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -480,10 +483,10 @@ def set_details(name, indent=None, width=None, usehex=False):
if width != 0 and len(tst) > width:
target = width - len(out)
patha = set.path[:len(set.path)/2-3]
pathb = set.path[len(set.path)/2:]
patha = patha[:target/2-3]
pathb = pathb[-target/2:]
patha = set.path[:old_div(len(set.path),2)-3]
pathb = set.path[old_div(len(set.path),2):]
patha = patha[:old_div(target,2)-3]
pathb = pathb[old_div(-target,2):]
out += patha + '...' + pathb
else:
out = tst

@ -1,6 +1,7 @@
"""Shield supercommand
"""
from builtins import str
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -298,7 +299,7 @@ def func(parser, options, args):
else:
try:
proc.move_pidspec(options.pid, to_set, from_set, options.threads)
except CpusetException, err:
except CpusetException as err:
if str(err).find('do not match all criteria') != -1:
log.info("--> hint: perhaps use --force if sure of command")
raise
@ -375,7 +376,7 @@ def make_shield(cpuspec, kthread):
try:
set.create(USR_SET, cpuspec, memspec, True, False)
set.create(SYS_SET, cpuspec_inv, memspec, True, False)
except Exception, instance:
except Exception as instance:
# unroll
try: set.destroy(USR_SET)
except: pass

@ -7,7 +7,10 @@ if desired. The class variables are given default values in the module source.
Anything found in the configuration files in the list of paths will override
these defaults.
"""
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
__copyright__ = """
Copyright (C) 2009-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -28,7 +31,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import sys
import types
import ConfigParser
import configparser
############################################################################
# Default configuration variable values
@ -41,30 +44,30 @@ mountpoint = '/cpusets' # cpuset filessytem mount point
def ReadConfigFiles(path=None):
if path == None: path = defloc
cf = ConfigParser.ConfigParser()
cf = configparser.ConfigParser()
try:
fr = cf.read(path)
if len(fr) == 0: return
# can't use logging, too early...
if len(cf.sections()) != 1:
print "cset: warning, more than one section found in config file:", cf.sections()
print("cset: warning, more than one section found in config file:", cf.sections())
if 'default' not in cf.sections():
print 'cset: [default] section not found in config file "%s"' % path
print('cset: [default] section not found in config file "%s"' % path)
sys.exit(3)
except ConfigParser.MissingSectionHeaderError:
except configparser.MissingSectionHeaderError:
f = open(path)
cstr = f.read()
f.close()
import StringIO
cf.readfp(StringIO.StringIO('[default]\n' + cstr))
import io
cf.readfp(io.StringIO('[default]\n' + cstr))
# override our globals...
for opt in cf.options('default'):
typ = type(globals()[opt])
if typ == types.BooleanType:
if typ == bool:
globals()[opt] = cf.getboolean('default', opt)
elif typ == types.IntType:
elif typ == int:
globals()[opt] = cf.getint('default', opt)
else:
globals()[opt] = cf.get('default', opt)

@ -1,6 +1,10 @@
"""Cpuset class and cpuset graph, importing module will create model
"""
from __future__ import print_function
from builtins import str
from builtins import range
from builtins import object
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -98,7 +102,7 @@ class CpuSet(object):
else:
parpath = dir[0:dir.rfind('/')]
log.debug('parpath decodes to: %s from dir of: %s', parpath, dir)
if CpuSet.sets.has_key(parpath):
if parpath in CpuSet.sets:
log.debug("parent is %s", parpath)
node.parent = CpuSet.sets[parpath]
else:
@ -113,7 +117,7 @@ class CpuSet(object):
else:
path = '/'
log.debug(" relative: %s", path)
if CpuSet.sets.has_key(path):
if path in CpuSet.sets:
log.debug("the cpuset %s already exists, skipping", path)
self = CpuSet.sets[path] # questionable....
return
@ -179,7 +183,7 @@ class CpuSet(object):
# Properties of cpuset node
def delprop(self):
raise AttributeError, "deletion of properties not allowed"
raise AttributeError("deletion of properties not allowed")
def getcpus(self):
f = file(CpuSet.basepath+self.path+CpuSet.cpus_path)
@ -256,7 +260,7 @@ class CpuSet(object):
f = file(CpuSet.basepath+self.path+CpuSet.tasks_path,'w')
f.write(task)
f.close()
except Exception, err:
except Exception as err:
if str(err).find('No such process') != -1:
notfound.append(task)
elif str(err).find('Invalid argument'):
@ -413,8 +417,8 @@ def cpuspec_to_hex(cpuspec):
number |= 1 << int(items[0])
elif len(items) == 2:
il = [int(ii) for ii in items]
if il[1] >= il[0]: rng = range(il[0], il[1]+1)
else: rng = range(il[1], il[0]+1)
if il[1] >= il[0]: rng = list(range(il[0], il[1]+1))
else: rng = list(range(il[1], il[0]+1))
log.debug(' group=%s has cpu range of %s', sub, rng)
for num in rng: number |= 1 << num
else:
@ -515,26 +519,26 @@ if __name__ == '__main__':
except:
pass
print 'Max cpu on system:', maxcpu
print 'All cpu mask: 0x%s' % allcpumask
print('Max cpu on system:', maxcpu)
print('All cpu mask: 0x%s' % allcpumask)
print '------- find_sets tests --------'
print 'Find by root of "root" -> ', find_sets("root")
print 'Find by path of "/" -> ', find_sets("/")
print('------- find_sets tests --------')
print('Find by root of "root" -> ', find_sets("root"))
print('Find by path of "/" -> ', find_sets("/"))
print 'Find by path of "/csettest/one" -> ', find_sets("/csettest/one")
print 'Find by name of "one" -> ', find_sets("one")
print 'Find by path of "/csettest/two" -> ', find_sets("/csettest/two")
print 'Find by name of "two" -> ', find_sets("two")
print('Find by path of "/csettest/one" -> ', find_sets("/csettest/one"))
print('Find by name of "one" -> ', find_sets("one"))
print('Find by path of "/csettest/two" -> ', find_sets("/csettest/two"))
print('Find by name of "two" -> ', find_sets("two"))
print 'Find by path of "/csettest/one/x" -> ', find_sets("/csettest/one/x")
print 'Find by name of "x" -> ', find_sets("x")
print 'Find by path of "/csettest/two/y" -> ', find_sets("/csettest/two/y")
print 'Find by name of "y" -> ', find_sets("y")
print('Find by path of "/csettest/one/x" -> ', find_sets("/csettest/one/x"))
print('Find by name of "x" -> ', find_sets("x"))
print('Find by path of "/csettest/two/y" -> ', find_sets("/csettest/two/y"))
print('Find by name of "y" -> ', find_sets("y"))
try:
node = find_sets("cantfindmenoway")
print 'Found "cantfindmenoway??!? -> ', node
except CpusetException, err:
print 'Caught exeption for non-existant set (correctly)-> ', err
print('Found "cantfindmenoway??!? -> ', node)
except CpusetException as err:
print('Caught exeption for non-existant set (correctly)-> ', err)

@ -1,6 +1,11 @@
"""Front end command line tool for Linux cpusets
"""
from __future__ import print_function
from __future__ import absolute_import
from future import standard_library
standard_library.install_aliases()
from builtins import str
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -36,7 +41,7 @@ class Commands(dict):
"""Return the canonical name for a possibly-shortenned
command name.
"""
candidates = [cmd for cmd in self.keys() if cmd.startswith(key)]
candidates = [cmd for cmd in list(self.keys()) if cmd.startswith(key)]
if not candidates:
log.error('Unknown command: %s', key)
@ -71,29 +76,29 @@ supercommands = (
)
def _print_helpstring(cmd):
print ' ' + cmd + ' ' * (12 - len(cmd)) + commands[cmd].help
print(' ' + cmd + ' ' * (12 - len(cmd)) + commands[cmd].help)
def print_help():
print 'Usage: %s [global options] <command> [command options]' % os.path.basename(sys.argv[0])
print
print 'Global options:'
print ' -l/--log <fname> output debugging log in fname'
print ' -m/--machine print machine readable output'
print ' -x/--tohex <CPUSPEC> convert a CPUSPEC to hex'
print
print 'Generic commands:'
print ' help print the detailed command usage'
print ' version display version information'
print ' copyright display copyright information'
cmds = commands.keys()
print('Usage: %s [global options] <command> [command options]' % os.path.basename(sys.argv[0]))
print()
print('Global options:')
print(' -l/--log <fname> output debugging log in fname')
print(' -m/--machine print machine readable output')
print(' -x/--tohex <CPUSPEC> convert a CPUSPEC to hex')
print()
print('Generic commands:')
print(' help print the detailed command usage')
print(' version display version information')
print(' copyright display copyright information')
cmds = list(commands.keys())
cmds.sort()
print
print 'Super commands (high-level and multi-function):'
print()
print('Super commands (high-level and multi-function):')
for cmd in supercommands:
_print_helpstring(cmd)
print
print 'Regular commands:'
print()
print('Regular commands:')
for cmd in cmds:
if not cmd in supercommands:
_print_helpstring(cmd)
@ -111,9 +116,8 @@ def main():
logfile = None
if len(sys.argv) < 2:
print >> sys.stderr, 'usage: %s <command>' % prog
print >> sys.stderr, \
' Try "%s --help" for a list of supported commands' % prog
print('usage: %s <command>' % prog, file=sys.stderr)
print(' Try "%s --help" for a list of supported commands' % prog, file=sys.stderr)
sys.exit(1)
# configure logging
@ -198,10 +202,10 @@ def main():
log.critical('not enough arguments')
sys.exit(1)
cpuspec = sys.argv[2]
import cset
from . import cset
try:
print cset.cpuspec_to_hex(cpuspec)
except (ValueError, OSError, IOError, CpusetException, CmdException), err:
print(cset.cpuspec_to_hex(cpuspec))
except (ValueError, OSError, IOError, CpusetException, CmdException) as err:
log.critical('**> ' + str(err))
if debug_level:
raise
@ -226,7 +230,7 @@ def main():
parser = OptionParser(usage = usage, option_list = command.options)
options, args = parser.parse_args()
command.func(parser, options, args)
except (ValueError, OSError, IOError, CpusetException, CmdException), err:
except (ValueError, OSError, IOError, CpusetException, CmdException) as err:
log.critical('**> ' + str(err))
if str(err).find('Permission denied') != -1:
log.critical('insufficient permissions, you probably need to be root')

@ -1,6 +1,12 @@
"""Utility functions
"""
from __future__ import division
from __future__ import print_function
from builtins import chr
from builtins import range
from past.utils import old_div
from builtins import object
__copyright__ = """
Copyright (C) 2007-2010 Novell Inc.
Author: Alex Tsariounov <alext@novell.com>
@ -38,7 +44,7 @@ class CpusetExists(CpusetException):
pass
# a twirling bar progress indicator
class TwirlyBar:
class TwirlyBar(object):
def __init__(self):
import sys
self.__dict__['__call__'] = self.tick
@ -47,7 +53,7 @@ class TwirlyBar:
def tick(self):
if not config.mread:
print '\b' + self.__bar[self.__state] + '\b',
print('\b' + self.__bar[self.__state] + '\b', end=' ')
self.__state = self.__state + 1
if self.__state > 3: self.__state = 0
@ -57,7 +63,7 @@ class TwirlyBar:
time.sleep(0.04)
# a progress bar indicator
class ProgressBar:
class ProgressBar(object):
def __init__(self, finalcount, progresschar=None):
self.__dict__['__call__'] = self.progress
self.finalcount=finalcount
@ -85,7 +91,7 @@ class ProgressBar:
else:
percentcomplete=100
blockcount=int(percentcomplete/2)
blockcount=int(old_div(percentcomplete,2))
if not config.mread:
if blockcount > self.blockcount:
for i in range(self.blockcount,blockcount):

Loading…
Cancel
Save