Apply the 2to3 conversions. In addition I put some imports on separate
lines in tuna.py so as not to confuse 2to3 conversions
Signed-off-by: John Kacur <jkacur(a)redhat.com>
---
oscilloscope-cmd.py | 8 +--
tuna-cmd.py | 189 ++++++++++++++++++++++++++-------------------------
tuna/config.py | 50 +++++++-------
tuna/gui/__init__.py | 2 +-
tuna/gui/cpuview.py | 21 +++---
tuna/gui/irqview.py | 13 ++--
tuna/gui/procview.py | 38 +++++------
tuna/gui/util.py | 8 +--
tuna/oscilloscope.py | 10 +--
tuna/sysfs.py | 16 ++---
tuna/tuna.py | 63 ++++++++---------
tuna/tuna_gui.py | 12 ++--
12 files changed, 217 insertions(+), 213 deletions(-)
diff --git a/oscilloscope-cmd.py b/oscilloscope-cmd.py
index bf821921c10e..753b879cbe57 100755
--- a/oscilloscope-cmd.py
+++ b/oscilloscope-cmd.py
@@ -24,7 +24,7 @@ import getopt, sys, gtk
from tuna import oscilloscope
def usage():
- print '''Usage: oscilloscope [OPTIONS]
+ print('''Usage: oscilloscope [OPTIONS]
-h, --help Give this help list
-d, --delimiter=CHARACTER CHARACTER used as a delimiter [Default: :]
-f, --field=FIELD FIELD to plot [Default: 2]
@@ -35,7 +35,7 @@ def usage():
-s, --nr_samples_on_screen=NR Show NR samples on screen
-S, --snapshot_samples=NR Take NR samples, a snapshot and exit
-u, --unit=TYPE Unit TYPE [Default: us]
-'''
+''')
def main():
try:
@@ -48,9 +48,9 @@ def main():
"nr_samples_on_screen=",
"snapshot_samples=",
"unit="))
- except getopt.GetoptError, err:
+ except getopt.GetoptError as err:
usage()
- print str(err)
+ print(str(err))
sys.exit(2)
max_value = 250
diff --git a/tuna-cmd.py b/tuna-cmd.py
index a58f2c1a6646..5c413cd0a061 100755
--- a/tuna-cmd.py
+++ b/tuna-cmd.py
@@ -19,6 +19,7 @@ from tuna import tuna, sysfs
import gettext
import locale
+from functools import reduce
try:
import inet_diag
@@ -40,50 +41,50 @@ irqs = None
version = "0.13.1"
def usage():
- print _('Usage: tuna [OPTIONS]')
+ print(_('Usage: tuna [OPTIONS]'))
fmt = '\t%-40s %s'
- print fmt % ('-h, --help', _('Give this help list'))
- print fmt % ('-a, --config_file_apply=profilename', _('Apply changes
described in profile'))
- print fmt % ('-l, --config_file_list', _('List preloaded
profiles'))
- print fmt % ('-g, --gui', _('Start the GUI'))
- print fmt % ('-G, --cgroup', _('Display the processes with the type of
cgroups they are in'))
- print fmt % ('-c, --cpus=' + _('CPU-LIST'), _('%(cpulist)s affected
by commands') % \
- {"cpulist": _('CPU-LIST')})
- print fmt % ('-C, --affect_children', _('Operation will affect children
threads'))
- print fmt % ('-f, --filter', _('Display filter the selected
entities'))
- print fmt % ('-i, --isolate', _('Move all threads away from
%(cpulist)s') % \
- {"cpulist": _('CPU-LIST')})
- print fmt % ('-I, --include', _('Allow all threads to run on
%(cpulist)s') % \
- {"cpulist": _('CPU-LIST')})
- print fmt % ('-K, --no_kthreads', _('Operations will not affect kernel
threads'))
- print fmt % ('-m, --move', _('Move selected entities to
%(cpulist)s') % \
- {"cpulist": _('CPU-LIST')})
- print fmt % ('-N, --nohz_full', _('CPUs in nohz_full= kernel command
line will be affected by operations'))
+ print(fmt % ('-h, --help', _('Give this help list')))
+ print(fmt % ('-a, --config_file_apply=profilename', _('Apply changes
described in profile')))
+ print(fmt % ('-l, --config_file_list', _('List preloaded
profiles')))
+ print(fmt % ('-g, --gui', _('Start the GUI')))
+ print(fmt % ('-G, --cgroup', _('Display the processes with the type of
cgroups they are in')))
+ print(fmt % ('-c, --cpus=' + _('CPU-LIST'), _('%(cpulist)s affected
by commands') % \
+ {"cpulist": _('CPU-LIST')}))
+ print(fmt % ('-C, --affect_children', _('Operation will affect children
threads')))
+ print(fmt % ('-f, --filter', _('Display filter the selected
entities')))
+ print(fmt % ('-i, --isolate', _('Move all threads away from
%(cpulist)s') % \
+ {"cpulist": _('CPU-LIST')}))
+ print(fmt % ('-I, --include', _('Allow all threads to run on
%(cpulist)s') % \
+ {"cpulist": _('CPU-LIST')}))
+ print(fmt % ('-K, --no_kthreads', _('Operations will not affect kernel
threads')))
+ print(fmt % ('-m, --move', _('Move selected entities to
%(cpulist)s') % \
+ {"cpulist": _('CPU-LIST')}))
+ print(fmt % ('-N, --nohz_full', _('CPUs in nohz_full= kernel command
line will be affected by operations')))
if have_inet_diag:
- print fmt % ('-n, --show_sockets', _('Show network sockets in use by
threads'))
- print fmt % ('-p, --priority=[' +
+ print(fmt % ('-n, --show_sockets', _('Show network sockets in use by
threads')))
+ print(fmt % ('-p, --priority=[' +
_('POLICY') + ':]' +
_('RTPRIO'), _('Set thread scheduler tunables: %(policy)s and
%(rtprio)s') % \
- {"policy": _('POLICY'), "rtprio":
_('RTPRIO')})
- print fmt % ('-P, --show_threads', _('Show thread list'))
- print fmt % ('-Q, --show_irqs', _('Show IRQ list'))
- print fmt % ('-q, --irqs=' + _('IRQ-LIST'), _('%(irqlist)s affected
by commands') %
- {"irqlist": _('IRQ-LIST')})
- print fmt % ('-r, --run=' + _('COMMAND'), _('fork a new process
and run the %(command)s') % \
- {"command": _('COMMAND')})
- print fmt % ('-s, --save=' + _('FILENAME'), _('Save kthreads sched
tunables to %(filename)s') % \
- {"filename": _('FILENAME')})
- print fmt % ('-S, --sockets=' +
+ {"policy": _('POLICY'), "rtprio":
_('RTPRIO')}))
+ print(fmt % ('-P, --show_threads', _('Show thread list')))
+ print(fmt % ('-Q, --show_irqs', _('Show IRQ list')))
+ print(fmt % ('-q, --irqs=' + _('IRQ-LIST'), _('%(irqlist)s affected
by commands') %
+ {"irqlist": _('IRQ-LIST')}))
+ print(fmt % ('-r, --run=' + _('COMMAND'), _('fork a new process
and run the %(command)s') % \
+ {"command": _('COMMAND')}))
+ print(fmt % ('-s, --save=' + _('FILENAME'), _('Save kthreads sched
tunables to %(filename)s') % \
+ {"filename": _('FILENAME')}))
+ print(fmt % ('-S, --sockets=' +
_('CPU-SOCKET-LIST'), _('%(cpusocketlist)s affected by
commands') % \
- {"cpusocketlist": _('CPU-SOCKET-LIST')})
- print fmt % ('-t, --threads=' +
+ {"cpusocketlist": _('CPU-SOCKET-LIST')}))
+ print(fmt % ('-t, --threads=' +
_('THREAD-LIST'), _('%(threadlist)s affected by commands') %
\
- {"threadlist": _('THREAD-LIST')})
- print fmt % ('-U, --no_uthreads', _('Operations will not affect user
threads'))
- print fmt % ('-v, --version', _('Show version'))
- print fmt % ('-W, --what_is', _('Provides help about selected
entities'))
- print fmt % ('-x, --spread', _('Spread selected entities over
%(cpulist)s') % \
- {"cpulist": _('CPU-LIST')})
+ {"threadlist": _('THREAD-LIST')}))
+ print(fmt % ('-U, --no_uthreads', _('Operations will not affect user
threads')))
+ print(fmt % ('-v, --version', _('Show version')))
+ print(fmt % ('-W, --what_is', _('Provides help about selected
entities')))
+ print(fmt % ('-x, --spread', _('Spread selected entities over
%(cpulist)s') % \
+ {"cpulist": _('CPU-LIST')}))
def get_nr_cpus():
global nr_cpus
@@ -106,18 +107,18 @@ def thread_help(tid):
if not ps:
ps = procfs.pidstats()
- if not ps.has_key(tid):
- print "tuna: " + _("thread %d doesn't exists!") % tid
+ if tid not in ps:
+ print("tuna: " + _("thread %d doesn't exists!") % tid)
return
pinfo = ps[tid]
cmdline = procfs.process_cmdline(pinfo)
help, title = tuna.kthread_help_plain_text(tid, cmdline)
- print "%s\n\n%s" % (title, _(help))
+ print("%s\n\n%s" % (title, _(help)))
def save(cpu_list, thread_list, filename):
kthreads = tuna.get_kthread_sched_tunings()
- for name in kthreads.keys():
+ for name in list(kthreads.keys()):
kt = kthreads[name]
if (cpu_list and not set(kt.affinity).intersection(set(cpu_list))) or \
(thread_list and kt.pid not in thread_list) :
@@ -125,17 +126,17 @@ def save(cpu_list, thread_list, filename):
tuna.generate_rtgroups(filename, kthreads, get_nr_cpus())
def ps_show_header(has_ctxt_switch_info,cgroups = False):
- print "%7s %6s %5s %7s %s" % \
+ print("%7s %6s %5s %7s %s" % \
(" ", " ", " ", _("thread"),
- has_ctxt_switch_info and "ctxt_switches" or "")
- print "%7s %6s %5s %7s%s %15s" % \
+ has_ctxt_switch_info and "ctxt_switches" or ""))
+ print("%7s %6s %5s %7s%s %15s" % \
("pid", "SCHED_", "rtpri", "affinity",
has_ctxt_switch_info and " %9s %12s" % ("voluntary",
"nonvoluntary") or "",
- "cmd"),
+ "cmd"), end=' ')
if cgroups:
- print " %7s" % ("cgroup")
+ print(" %7s" % ("cgroup"))
else:
- print ""
+ print("")
def ps_show_sockets(pid, ps, inodes, inode_re, indent = 0):
header_printed = False
@@ -155,19 +156,19 @@ def ps_show_sockets(pid, ps, inodes, inode_re, indent = 0):
if not inode_match:
continue
inode = int(inode_match.group(1))
- if not inodes.has_key(inode):
+ if inode not in inodes:
continue
if not header_printed:
- print "%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" % \
+ print("%s%-10s %-6s %-6s %15s:%-5s %15s:%-5s" % \
(sindent, "State", "Recv-Q", "Send-Q",
"Local Address", "Port",
- "Peer Address", "Port")
+ "Peer Address", "Port"))
header_printed = True
s = inodes[inode]
- print "%s%-10s %-6d %-6d %15s:%-5d %15s:%-5d" % \
+ print("%s%-10s %-6d %-6d %15s:%-5d %15s:%-5d" % \
(sindent, s.state(),
s.receive_queue(), s.write_queue(),
- s.saddr(), s.sport(), s.daddr(), s.dport())
+ s.saddr(), s.sport(), s.daddr(), s.dport()))
def format_affinity(affinity):
if len(affinity) <= 4:
@@ -215,19 +216,19 @@ def ps_show_thread(pid, affect_children, ps,
nonvoluntary_ctxt_switches)
if affect_children:
- print " %-5d " % pid,
+ print(" %-5d " % pid, end=' ')
else:
- print " %-5d" % pid,
- print "%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
- ctxt_switch_info, cmd, users),
+ print(" %-5d" % pid, end=' ')
+ print("%6s %5d %8s%s %15s %s" % (sched, rtprio, affinity,
+ ctxt_switch_info, cmd, users), end=' ')
if cgroups:
- print " %9s" % cgout,
- print ""
+ print(" %9s" % cgout, end=' ')
+ print("")
if sock_inodes:
ps_show_sockets(pid, ps, sock_inodes, sock_inode_re,
affect_children and 3 or 4)
- if affect_children and ps[pid].has_key("threads"):
- for tid in ps[pid]["threads"].keys():
+ if affect_children and "threads" in ps[pid]:
+ for tid in list(ps[pid]["threads"].keys()):
ps_show_thread(tid, False, ps[pid]["threads"],
has_ctxt_switch_info,
sock_inodes, sock_inode_re, cgroups)
@@ -238,7 +239,7 @@ def ps_show(ps, affect_children, thread_list, cpu_list,
has_ctxt_switch_info, sock_inodes, sock_inode_re, cgroups):
ps_list = []
- for pid in ps.keys():
+ for pid in list(ps.keys()):
iskth = tuna.iskthread(pid)
if not show_uthreads and not iskth:
continue
@@ -305,7 +306,7 @@ def do_ps(thread_list, cpu_list, irq_list, show_uthreads,
sock_inodes = load_sockets()
sock_inode_re = re.compile(r"socket:\[(\d+)\]")
- has_ctxt_switch_info =
ps[1]["status"].has_key("voluntary_ctxt_switches")
+ has_ctxt_switch_info = "voluntary_ctxt_switches" in ps[1]["status"]
try:
if sys.stdout.isatty():
ps_show_header(has_ctxt_switch_info, cgroups)
@@ -338,9 +339,9 @@ def show_irqs(irq_list, cpu_list):
irqs = procfs.interrupts()
if sys.stdout.isatty():
- print "%4s %-16s %8s" % ("#", _("users"),
_("affinity"),)
+ print("%4s %-16s %8s" % ("#", _("users"),
_("affinity"),))
sorted_irqs = []
- for k in irqs.keys():
+ for k in list(irqs.keys()):
try:
irqn = int(k)
affinity = irqs[irqn]["affinity"]
@@ -357,12 +358,12 @@ def show_irqs(irq_list, cpu_list):
for irq in sorted_irqs:
affinity = format_affinity(irqs[irq]["affinity"])
users = irqs[irq]["users"]
- print "%4d %-16s %8s" % (irq, ",".join(users), affinity),
+ print("%4d %-16s %8s" % (irq, ",".join(users), affinity), end='
')
drivers = find_drivers_by_users(users)
if drivers:
- print " %s" % ",".join(drivers)
+ print(" %s" % ",".join(drivers))
else:
- print
+ print()
def do_list_op(op, current_list, op_list):
if not current_list:
@@ -428,7 +429,7 @@ def apply_config(filename):
filename = os.path.basename(filename)
else:
if not os.path.exists(config.config['root']+filename):
- print filename + _(" not found!")
+ print(filename + _(" not found!"))
exit(-1)
if config.loadTuna(filename):
exit(1)
@@ -446,9 +447,9 @@ def apply_config(filename):
def list_config():
from tuna.config import Config
config = Config()
- print _("Preloaded config files:")
+ print(_("Preloaded config files:"))
for value in config.populate():
- print value
+ print(value)
exit(1)
def main():
@@ -466,11 +467,11 @@ def main():
"run=" ]
if have_inet_diag:
short += "n"
- long.append("show_sockets")
- opts, args = getopt.getopt(sys.argv[1:], short, long)
- except getopt.GetoptError, err:
+ int.append("show_sockets")
+ opts, args = getopt.getopt(sys.argv[1:], short, int)
+ except getopt.GetoptError as err:
usage()
- print str(err)
+ print(str(err))
sys.exit(2)
run_gui = not opts
@@ -509,7 +510,7 @@ def main():
try:
cpu_list = tuna.nohz_full_list()
except:
- print "tuna: --nohz_full " + _(" needs nohz_full=cpulist on the kernel
command line")
+ print("tuna: --nohz_full " + _(" needs nohz_full=cpulist on the kernel
command line"))
sys.exit(2)
elif o in ("-C", "--affect_children"):
affect_children = True
@@ -523,7 +524,7 @@ def main():
else:
(op, a) = pick_op(a)
op_list = reduce(lambda i, j: i + j,
- map(thread_mapper, a.split(",")))
+ list(map(thread_mapper, a.split(","))))
op_list = list(set(op_list))
thread_list = do_list_op(op, thread_list, op_list)
# Check if a process name was especified and no
@@ -541,12 +542,12 @@ def main():
run_gui = True
elif o in ("-i", "--isolate"):
if not cpu_list:
- print "tuna: --isolate " + _("requires a cpu list!")
+ print("tuna: --isolate " + _("requires a cpu list!"))
sys.exit(2)
tuna.isolate_cpus(cpu_list, get_nr_cpus())
elif o in ("-I", "--include"):
if not cpu_list:
- print "tuna: --include " + _("requires a cpu list!")
+ print("tuna: --include " + _("requires a cpu list!"))
sys.exit(2)
tuna.include_cpus(cpu_list, get_nr_cpus())
elif o in ("-p", "--priority"):
@@ -559,7 +560,7 @@ def main():
try:
tuna.threads_set_priority(thread_list, a, affect_children)
except (SystemError, OSError) as err: # old python-schedutils incorrectly raised
SystemError
- print "tuna: %s" % err
+ print("tuna: %s" % err)
sys.exit(2)
elif o in ("-P", "--show_threads"):
# If the user specified process names that weren't
@@ -579,10 +580,10 @@ def main():
show_sockets = True
elif o in ("-m", "--move", "-x", "--spread"):
if not cpu_list:
- print "tuna: --move " + _("requires a cpu list!")
+ print("tuna: --move " + _("requires a cpu list!"))
sys.exit(2)
if not (thread_list or irq_list):
- print "tuna: --move " + _("requires a list of threads/irqs!")
+ print("tuna: --move " + _("requires a list of threads/irqs!"))
sys.exit(2)
spread = o in ("-x", "--spread")
@@ -598,7 +599,7 @@ def main():
save(cpu_list, thread_list, a)
elif o in ("-S", "--sockets"):
(op, a) = pick_op(a)
- sockets = map(lambda socket: socket, a.split(","))
+ sockets = [socket for socket in a.split(",")]
if not cpu_list:
cpu_list = []
@@ -606,11 +607,11 @@ def main():
cpu_info = sysfs.cpus()
op_list = []
for socket in sockets:
- if not cpu_info.sockets.has_key(socket):
- print "tuna: %s" % \
+ if socket not in cpu_info.sockets:
+ print("tuna: %s" % \
(_("invalid socket %(socket)s sockets available: %(available)s") %
\
{"socket": socket,
- "available": ",".join(cpu_info.sockets.keys())})
+ "available": ",".join(list(cpu_info.sockets.keys()))}))
sys.exit(2)
op_list += [ int(cpu.name[3:]) for cpu in cpu_info.sockets[socket] ]
cpu_list = do_list_op(op, cpu_list, op_list)
@@ -619,7 +620,7 @@ def main():
elif o in ("-q", "--irqs"):
(op, a) = pick_op(a)
op_list = reduce(lambda i, j: i + j,
- map(irq_mapper, list(set(a.split(",")))))
+ list(map(irq_mapper, list(set(a.split(","))))))
irq_list = do_list_op(op, irq_list, op_list)
# See comment above about thread_list_str
if not op_list and type(a) == type(''):
@@ -644,10 +645,10 @@ def main():
elif o in ("-U", "--no_uthreads"):
uthreads = False
elif o in ("-v", "--version"):
- print version
+ print(version)
elif o in ("-W", "--what_is"):
if not thread_list:
- print "tuna: --what_is " + _("requires a thread list!")
+ print("tuna: --what_is " + _("requires a thread list!"))
sys.exit(2)
for tid in thread_list:
thread_help(tid)
@@ -665,7 +666,7 @@ def main():
tuna.run_command(a, policy, rtprio, cpu_list)
op_list = reduce(lambda i, j: i + j,
- map(thread_mapper, a.split(",")))
+ list(map(thread_mapper, a.split(","))))
op_list = list(set(op_list))
thread_list = do_list_op(op, thread_list, op_list)
@@ -683,7 +684,7 @@ def main():
# used to exit(2) if no action was taken (i.e. if no threads_list
# was set).
if p_waiting_action:
- print ("tuna: -p ") + _("requires a thread list!")
+ print(("tuna: -p ") + _("requires a thread list!"))
sys.exit(2)
if run_gui:
@@ -691,12 +692,12 @@ def main():
from tuna import tuna_gui
except ImportError:
# gui packages not installed
- print _('tuna: packages needed for the GUI missing.')
- print _(' Make sure xauth, pygtk2-libglade are installed.')
+ print(_('tuna: packages needed for the GUI missing.'))
+ print(_(' Make sure xauth, pygtk2-libglade are installed.'))
usage()
return
except RuntimeError:
- print "tuna: machine needs to be authorized via xhost or ssh -X?"
+ print("tuna: machine needs to be authorized via xhost or ssh -X?")
return
try:
diff --git a/tuna/config.py b/tuna/config.py
index e82a4200c6ff..019317fe3d32 100644
--- a/tuna/config.py
+++ b/tuna/config.py
@@ -1,6 +1,6 @@
import io, os, re, fnmatch
import sys, gtk
-import codecs, ConfigParser
+import codecs, configparser
from time import localtime, strftime
from subprocess import Popen, PIPE, STDOUT, call
TUNED_CONF="""[sysctl]\n"""
@@ -13,10 +13,10 @@ class Config:
self.configFile = "/etc/tuna.conf"
try:
- self.configParser = ConfigParser.RawConfigParser()
+ self.configParser = configparser.RawConfigParser()
self.configParser.read(self.configFile)
cfg = self.configParser.items('global')
- except ConfigParser.Error:
+ except configparser.Error:
f = open(self.configFile,'w')
f.write("[global]\n")
f.write("root=/etc/tuna/\n")
@@ -38,7 +38,7 @@ class Config:
def updateDefault(self, filename):
if filename.replace("", "temp-direct-load.conf") != filename:
- self.temp = ConfigParser.RawConfigParser()
+ self.temp = configparser.RawConfigParser()
self.temp.read(self.configFile)
self.temp.set('global', 'lastFile', filename)
with open(self.configFile, 'wb') as cfgfile:
@@ -46,18 +46,18 @@ class Config:
self.config['lastfile'] = filename
def load(self, profileName):
- tmp = ConfigParser.RawConfigParser()
+ tmp = configparser.RawConfigParser()
tmp.read(self.config['root'] + profileName)
try:
check = tmp.items('categories')
- except ConfigParser.NoSectionError:
+ except configparser.NoSectionError:
if(self.tuned2Tuna(profileName) < 0):
return -1
return self.loadTuna(profileName)
def tuned2Tuna(self,profileName):
try:
- tmp = ConfigParser.RawConfigParser()
+ tmp = configparser.RawConfigParser()
tmp.read(self.config['root']+profileName)
content = tmp.items('sysctl')
f = open(self.config['root']+profileName,'w')
@@ -68,7 +68,7 @@ class Config:
f.write(option + "=" + value + "\n")
f.close()
return 0
- except (ConfigParser.Error, IOError):
+ except (configparser.Error, IOError):
dialog = gtk.MessageDialog(None, 0, gtk.MESSAGE_ERROR,\
gtk.BUTTONS_OK, "%s\n%s" % \
(_("Corruputed config file: "),
_(self.config['root']+profileName)))
@@ -142,7 +142,7 @@ class Config:
raise RuntimeError(_("Config file contain errors: ") + _(err))
return -1
try:
- self.configParser = ConfigParser.RawConfigParser()
+ self.configParser = configparser.RawConfigParser()
self.configParser.read(self.config['root'] + profileName)
tempCategories = self.configParser.items('categories')
self.catIndex = 0
@@ -187,26 +187,26 @@ class Config:
self.categories[self.catIndex] = value
self.categoriesOrigin[self.catIndex] = option
self.catIndex = self.catIndex + 1
- except (ConfigParser.Error, IOError):
- print _("Config file is corrupted")
+ except (configparser.Error, IOError):
+ print(_("Config file is corrupted"))
return -1
try:
self.aliasList = self.configParser.items('guiAlias')
- except ConfigParser.Error:
+ except configparser.Error:
self.aliasList = []
self.aliasReverse = []
return 0
def updateDescription(self, filename):
try:
- self.temp = ConfigParser.RawConfigParser()
+ self.temp = configparser.RawConfigParser()
self.temp.read(self.config['root'] + filename)
self.description = self.temp.items('fileDescription')
self.description = dict(self.description)['text']
- except ConfigParser.Error as e:
+ except configparser.Error as e:
self.description = _("Description for this profile not found")
- if e != ConfigParser.NoSectionError:
- print e
+ if e != configparser.NoSectionError:
+ print(e)
return self.description
def fileToCache(self, profileName):
@@ -228,7 +228,7 @@ class Config:
f.write(self.cache)
f.close()
except IOError:
- print _("Cant write to config file: %s" % (self.config['root'] +
profileName))
+ print(_("Cant write to config file: %s" % (self.config['root'] +
profileName)))
def loadDirect(self, data):
try:
@@ -249,7 +249,7 @@ class Config:
try:
buffer = open("/proc/sys/" + self.ConfigPathToFileName(filename),
'r').read()
except IOError:
- print _("Invalid item! file: /proc/sys/%s"
%(self.ConfigPathToFileName(filename)))
+ print(_("Invalid item! file: /proc/sys/%s"
%(self.ConfigPathToFileName(filename))))
return ""
return buffer.strip()
@@ -262,7 +262,7 @@ class Config:
fp = open("/proc/sys/" + self.ConfigPathToFileName(filename), 'w')
fp.write(value)
except IOError:
- print "%s%s %s %s" % (_("Cant write to file! path: /proc/sys/"),
self.ConfigPathToFileName(filename), _("value:"), value)
+ print("%s%s %s %s" % (_("Cant write to file! path: /proc/sys/"),
self.ConfigPathToFileName(filename), _("value:"), value))
return -1
return 0
@@ -294,7 +294,7 @@ class Config:
return string
def saveSnapshot(self,data):
- tempconfig = ConfigParser.RawConfigParser()
+ tempconfig = configparser.RawConfigParser()
tempconfig.readfp(io.BytesIO(self.cache))
snapcat = tempconfig.items('categories')
out = {}
@@ -336,7 +336,7 @@ class Config:
with open(snapFileName , 'w') as configfile:
tempconfig.write(configfile)
except IOError:
- print _("Cant save snapshot")
+ print(_("Cant save snapshot"))
return snapFileName
def checkConfigFile(self, filename):
@@ -346,7 +346,7 @@ class Config:
if not os.path.exists(filename):
msgStack = "%s%s %s %s" % (msgStack, _("Error: File"), filename,
_("not found\n"))
return msgStack
- self.checkParser = ConfigParser.RawConfigParser()
+ self.checkParser = configparser.RawConfigParser()
self.checkParser.read(filename)
for option,value in self.checkParser.items('categories'):
if not self.checkParser.items(option):
@@ -360,12 +360,12 @@ class Config:
if self.empty:
msgStack = "%s%s" % (msgStack, _("Empty config File"))
return msgStack
- except (ConfigParser.Error, IOError) as e:
+ except (configparser.Error, IOError) as e:
return "Error {0}".format(str(e))
def fixConfigFile(self, filename):
try:
- self.checkParser = ConfigParser.RawConfigParser()
+ self.checkParser = configparser.RawConfigParser()
self.checkParser.read(filename)
for option,value in self.checkParser.items('categories'):
if not self.checkParser.items(option):
@@ -376,7 +376,7 @@ class Config:
if not os.path.exists("/proc/sys/" + self.ConfigPathToFileName(opt)) and
len(self.getFilesByFN("/proc/sys/", self.ConfigPathToFileName(opt))) == 0:
self.checkParser.remove_option(option, opt)
self.checkParser.set(option, '#' + opt, val)
- except (ConfigParser.Error, IOError) as e:
+ except (configparser.Error, IOError) as e:
return "Error {0}".format(str(e))
with open(filename, 'w') as configfile:
self.checkParser.write(configfile)
diff --git a/tuna/gui/__init__.py b/tuna/gui/__init__.py
index 0fe9f307b115..ba4057261e02 100755
--- a/tuna/gui/__init__.py
+++ b/tuna/gui/__init__.py
@@ -13,4 +13,4 @@ DND_TARGETS = [ ('STRING', 0, DND_TARGET_STRING),
('text/plain', 0, DND_TARGET_STRING),
('application/x-rootwin-drop', 0, DND_TARGET_ROOTWIN) ]
-from util import *
+from .util import *
diff --git a/tuna/gui/cpuview.py b/tuna/gui/cpuview.py
index c84ecd739c70..80913bf0fcb1 100755
--- a/tuna/gui/cpuview.py
+++ b/tuna/gui/cpuview.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import pygtk
+from functools import reduce
pygtk.require("2.0")
import gtk, gobject, math, os, procfs, schedutils
@@ -26,7 +27,7 @@ def drop_handler_move_threads_to_cpu(new_affinity, data):
def drop_handler_move_irqs_to_cpu(cpus, data):
irq_list = [ int(irq) for irq in data.split(",") ]
new_affinity = [ reduce(lambda a, b: a | b,
- map(lambda cpu: 1 << cpu, cpus)), ]
+ [1 << cpu for cpu in cpus]), ]
for irq in irq_list:
tuna.set_irq_affinity(irq, new_affinity)
@@ -38,7 +39,7 @@ def drop_handler_move_irqs_to_cpu(cpus, data):
class cpu_socket_frame(gtk.Frame):
- ( COL_FILTER, COL_CPU, COL_USAGE ) = range(3)
+ ( COL_FILTER, COL_CPU, COL_USAGE ) = list(range(3))
def __init__(self, socket, cpus, creator):
@@ -103,11 +104,11 @@ class cpu_socket_frame(gtk.Frame):
# pid list, a irq list, etc
source, data = selection.data.split(":")
- if self.drop_handlers.has_key(source):
+ if source in self.drop_handlers:
if self.drop_handlers[source][0](cpus, data):
self.drop_handlers[source][1].refresh()
else:
- print "cpu_socket_frame: unhandled drag source '%s'" % source
+ print("cpu_socket_frame: unhandled drag source '%s'" % source)
def on_drag_data_received_data(self, treeview, context, x, y,
selection, info, etime):
@@ -125,11 +126,11 @@ class cpu_socket_frame(gtk.Frame):
# Move to all CPUs in this socket
cpus = [ int(cpu.name[3:]) for cpu in self.cpus ]
- if self.drop_handlers.has_key(source):
+ if source in self.drop_handlers:
if self.drop_handlers[source][0](cpus, data):
self.drop_handlers[source][1].refresh()
else:
- print "cpu_socket_frame: unhandled drag source '%s'" % source
+ print("cpu_socket_frame: unhandled drag source '%s'" % source)
def refresh(self):
self.list_store.clear()
@@ -251,7 +252,7 @@ class cpuview:
vbox = window.get_child().get_child()
socket_ids = []
- for id in self.cpus.sockets.keys():
+ for id in list(self.cpus.sockets.keys()):
try:
socket_ids.append(int(id))
except TypeError: # Skip over offline cpus - type None
@@ -328,14 +329,14 @@ class cpuview:
self.previous_irq_affinities):
return
affinities = self.previous_pid_affinities
- for pid in affinities.keys():
+ for pid in list(affinities.keys()):
try:
schedutils.set_affinity(pid, affinities[pid])
except:
pass
affinities = self.previous_irq_affinities
- for irq in affinities.keys():
+ for irq in list(affinities.keys()):
tuna.set_irq_affinity(int(irq),
procfs.hexbitmask(affinities[irq],
self.cpus.nr_cpus))
@@ -356,6 +357,6 @@ class cpuview:
def refresh(self):
self.cpustats.reload()
- for frame in self.socket_frames.keys():
+ for frame in list(self.socket_frames.keys()):
self.socket_frames[frame].refresh()
return True
diff --git a/tuna/gui/irqview.py b/tuna/gui/irqview.py
index 2cb837608fd3..df19f6ee0b66 100755
--- a/tuna/gui/irqview.py
+++ b/tuna/gui/irqview.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import pygtk
+from functools import reduce
pygtk.require("2.0")
from tuna import tuna, gui
@@ -51,7 +52,7 @@ class irq_druid:
self.affinity.set_text(self.affinity_text)
def create_policy_model(self, policy):
- ( COL_TEXT, COL_SCHED ) = range(2)
+ ( COL_TEXT, COL_SCHED ) = list(range(2))
list_store = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_UINT)
renderer = gtk.CellRendererText()
@@ -115,7 +116,7 @@ class irqview:
nr_columns = 7
( COL_NUM, COL_PID, COL_POL, COL_PRI,
- COL_AFF, COL_EVENTS, COL_USERS ) = range(nr_columns)
+ COL_AFF, COL_EVENTS, COL_USERS ) = list(range(nr_columns))
columns = (gui.list_store_column(_("IRQ")),
gui.list_store_column(_("PID"), gobject.TYPE_INT),
gui.list_store_column(_("Policy"), gobject.TYPE_STRING),
@@ -137,7 +138,7 @@ class irqview:
( self.COL_NUM,
self.COL_AFF,
self.COL_EVENTS,
- self.COL_USERS ) = range(self.nr_columns)
+ self.COL_USERS ) = list(range(self.nr_columns))
self.columns = (gui.list_store_column(_("IRQ")),
gui.list_store_column(_("Affinity"), gobject.TYPE_STRING),
gui.list_store_column(_("Events")),
@@ -207,7 +208,7 @@ class irqview:
def show(self):
new_irqs = []
- for sirq in self.irqs.keys():
+ for sirq in list(self.irqs.keys()):
try:
new_irqs.append(int(sirq))
except:
@@ -219,7 +220,7 @@ class irqview:
while row:
irq = self.list_store.get_value(row, self.COL_NUM)
# IRQ was unregistered? I.e. driver unloaded?
- if not self.irqs.has_key(irq):
+ if irq not in self.irqs:
if self.list_store.remove(row):
# removed and row now its the next one
continue
@@ -280,7 +281,7 @@ class irqview:
return
row = self.list_store.get_iter(path)
irq = self.list_store.get_value(row, self.COL_NUM)
- if not self.irqs.has_key(irq):
+ if irq not in self.irqs:
return
dialog = irq_druid(self.irqs, self.ps, irq, self.gladefile)
diff --git a/tuna/gui/procview.py b/tuna/gui/procview.py
index 159d7f81d582..9b2a21a8bb58 100755
--- a/tuna/gui/procview.py
+++ b/tuna/gui/procview.py
@@ -14,7 +14,7 @@ def N_(s):
class process_druid:
- ( PROCESS_COL_PID, PROCESS_COL_NAME ) = range(2)
+ ( PROCESS_COL_PID, PROCESS_COL_NAME ) = list(range(2))
def __init__(self, ps, pid, pid_info, nr_cpus, gladefile):
self.ps = ps
@@ -52,7 +52,7 @@ class process_druid:
self.regex_edit.set_text(cmdline_regex)
self.just_this_thread.set_active(True)
self.regex_edit.set_sensitive(False)
- if not ps.has_key(pid) or not ps[pid].has_key("threads"):
+ if pid not in ps or "threads" not in ps[pid]:
self.all_these_threads.hide()
self.on_just_this_thread_clicked(None)
@@ -81,7 +81,7 @@ class process_druid:
processes.set_model(self.process_list_store)
def create_policy_model(self, policy):
- ( COL_TEXT, COL_SCHED ) = range(2)
+ ( COL_TEXT, COL_SCHED ) = list(range(2))
list_store = gtk.ListStore(gobject.TYPE_STRING,
gobject.TYPE_UINT)
renderer = gtk.CellRendererText()
@@ -123,7 +123,7 @@ class process_druid:
self.process_list_store.set(info,
self.PROCESS_COL_PID, self.pid,
self.PROCESS_COL_NAME, cmdline)
- for tid in self.ps[self.pid]["threads"].keys():
+ for tid in list(self.ps[self.pid]["threads"].keys()):
child = self.process_list_store.append()
self.process_list_store.set(child,
self.PROCESS_COL_PID, tid,
@@ -156,7 +156,7 @@ class process_druid:
def set_attributes_for_threads(self, pid, new_policy, new_prio, new_affinity):
changed = False
threads = self.ps[pid]["threads"]
- for tid in threads.keys():
+ for tid in list(threads.keys()):
if gui.thread_set_attributes(threads[tid], new_policy,
new_prio, new_affinity,
self.nr_cpus):
@@ -199,7 +199,7 @@ class process_druid:
class procview:
nr_columns = 8
- ( COL_PID, COL_POL, COL_PRI, COL_AFF, COL_VOLCTXT, COL_NONVOLCTXT, COL_CGROUP,
COL_CMDLINE ) = range(nr_columns)
+ ( COL_PID, COL_POL, COL_PRI, COL_AFF, COL_VOLCTXT, COL_NONVOLCTXT, COL_CGROUP,
COL_CMDLINE ) = list(range(nr_columns))
columns = (gui.list_store_column(_("PID")),
gui.list_store_column(_("Policy"), gobject.TYPE_STRING),
gui.list_store_column(_("Priority")),
@@ -223,7 +223,7 @@ class procview:
except: # No perf, poll /proc baby, poll
pass
- if not ps[1]["status"].has_key("voluntary_ctxt_switches"):
+ if "voluntary_ctxt_switches" not in ps[1]["status"]:
self.nr_columns = 5
else:
self.nr_columns = 7
@@ -239,24 +239,24 @@ class procview:
gui.list_store_column(_("Affinity"), gobject.TYPE_STRING))
if self.nr_columns==5:
- ( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CMDLINE ) =
range(self.nr_columns)
+ ( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CMDLINE ) =
list(range(self.nr_columns))
self.columns = self.columns + (gui.list_store_column(_("Command Line"),
gobject.TYPE_STRING))
elif self.nr_columns==6:
- ( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CGROUP,
self.COL_CMDLINE ) = range(self.nr_columns)
+ ( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_CGROUP,
self.COL_CMDLINE ) = list(range(self.nr_columns))
self.columns = self.columns + (gui.list_store_column(_("CGroup"),
gobject.TYPE_STRING),
gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))
elif self.nr_columns==7:
( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_VOLCTXT,
- self.NONVOLCTXT, self.COL_CMDLINE ) = range(self.nr_columns)
+ self.NONVOLCTXT, self.COL_CMDLINE ) = list(range(self.nr_columns))
self.columns = self.columns + (gui.list_store_column(_("VolCtxtSwitch"),
gobject.TYPE_UINT),
gui.list_store_column(_("NonVolCtxtSwitch"), gobject.TYPE_UINT),
gui.list_store_column(_("Command Line"), gobject.TYPE_STRING))
elif self.nr_columns==8:
( self.COL_PID, self.COL_POL, self.COL_PRI, self.COL_AFF, self.COL_VOLCTXT,
- self.COL_NONVOLCTXT, self.COL_CGROUP, self.COL_CMDLINE ) = range(self.nr_columns)
+ self.COL_NONVOLCTXT, self.COL_CGROUP, self.COL_CMDLINE ) =
list(range(self.nr_columns))
self.columns = self.columns + (gui.list_store_column(_("VolCtxtSwitch"),
gobject.TYPE_UINT),
gui.list_store_column(_("NonVolCtxtSwitch"), gobject.TYPE_UINT),
gui.list_store_column(_("CGroup"), gobject.TYPE_STRING),
@@ -326,7 +326,7 @@ class procview:
del self.ps[int(event.tid)]
elif event.type == perf.RECORD_SAMPLE:
tid = event.sample_tid
- if self.perf_counter.has_key(tid):
+ if tid in self.perf_counter:
self.perf_counter[tid] += event.sample_period
else:
self.perf_counter[tid] = event.sample_period
@@ -418,7 +418,7 @@ class procview:
self.treeview.show_all()
def update_rows(self, threads, row, parent_row):
- new_tids = threads.keys()
+ new_tids = list(threads.keys())
previous_row = None
while row:
tid = self.tree_store.get_value(row, self.COL_PID)
@@ -427,7 +427,7 @@ class procview:
if previous_tid == tid:
# print "WARNING: tree_store dup %d, fixing..." % tid
self.tree_store.remove(previous_row)
- if not threads.has_key(tid):
+ if tid not in threads:
if self.tree_store.remove(row):
# removed and now row is the next one
continue
@@ -453,7 +453,7 @@ class procview:
try:
self.set_thread_columns(row, tid, threads[tid])
- if threads[tid].has_key("threads"):
+ if "threads" in threads[tid]:
children = threads[tid]["threads"]
else:
children = {}
@@ -488,9 +488,9 @@ class procview:
self.tree_store.remove(row)
continue
- if threads[tid].has_key("threads"):
+ if "threads" in threads[tid]:
children = threads[tid]["threads"]
- children_list = children.keys()
+ children_list = list(children.keys())
children_list.sort()
for child in children_list:
child_row = self.tree_store.append(row)
@@ -516,7 +516,7 @@ class procview:
return
row = self.tree_store.get_iter(path)
pid = self.tree_store.get_value(row, self.COL_PID)
- if self.ps.has_key(pid):
+ if pid in self.ps:
pid_info = self.ps[pid]
else:
parent = self.tree_store.iter_parent(row)
@@ -545,7 +545,7 @@ class procview:
return
row = self.tree_store.get_iter(path)
pid = self.tree_store.get_value(row, self.COL_PID)
- if not self.ps.has_key(pid):
+ if pid not in self.ps:
return
cmdline = self.tree_store.get_value(row, self.COL_CMDLINE)
diff --git a/tuna/gui/util.py b/tuna/gui/util.py
index 68c5c86df09f..73eceae23ab7 100755
--- a/tuna/gui/util.py
+++ b/tuna/gui/util.py
@@ -75,11 +75,11 @@ def thread_set_attributes(pid_info, new_policy, new_prio,
new_affinity, nr_cpus)
curr_policy = schedutils.get_scheduler(pid)
if curr_policy != new_policy:
- print _("couldn't change pid %(pid)d from %(cpol)s(%(cpri)d) to
%(npol)s(%(npri)d)!") % \
+ print(_("couldn't change pid %(pid)d from %(cpol)s(%(cpri)d) to
%(npol)s(%(npri)d)!") % \
{ 'pid': pid, 'cpol': schedutils.schedstr(curr_policy),
'cpri': curr_prio,
'npol': schedutils.schedstr(new_policy),
- 'npri': new_prio}
+ 'npri': new_prio})
else:
changed = True
@@ -114,8 +114,8 @@ def thread_set_attributes(pid_info, new_policy, new_prio,
new_affinity, nr_cpus)
raise e
if curr_affinity != new_affinity:
- print _("couldn't change pid %(pid)d from %(caff)s to %(naff)s!") % \
- { 'pid':pid, 'caff':curr_affinity, 'naff':new_affinity
}
+ print(_("couldn't change pid %(pid)d from %(caff)s to %(naff)s!") % \
+ { 'pid':pid, 'caff':curr_affinity, 'naff':new_affinity
})
else:
changed = True
diff --git a/tuna/oscilloscope.py b/tuna/oscilloscope.py
index 81693cc29762..ab3d8af77d05 100755
--- a/tuna/oscilloscope.py
+++ b/tuna/oscilloscope.py
@@ -309,7 +309,7 @@ class oscilloscope(gtk.Window):
self.snapshot()
gtk.main_quit()
except:
- print "invalid sample, check the input format"
+ print("invalid sample, check the input format")
pass
return self.getting_samples
@@ -351,7 +351,7 @@ class oscilloscope(gtk.Window):
class ftrace_window(gtk.Window):
- (COL_FUNCTION, ) = range(1)
+ (COL_FUNCTION, ) = list(range(1))
def __init__(self, trace, parent = None):
gtk.Window.__init__(self)
@@ -425,13 +425,13 @@ class cyclictestoscope(oscilloscope):
try:
sample = float(fields[self.field]) * self.sample_multiplier
except:
- print "fields=%s, self.field=%s,self.delimiter=%s" % (fields, self.field,
self.delimiter)
+ print("fields=%s, self.field=%s,self.delimiter=%s" % (fields, self.field,
self.delimiter))
return None
if self.latency_tracer:
del self.traces[0]
if sample > self.avg:
- print sample
+ print(sample)
try:
f = file("/sys/kernel/debug/tracing/trace")
trace = f.readlines()
@@ -442,7 +442,7 @@ class cyclictestoscope(oscilloscope):
except:
trace = None
else:
- print "-"
+ print("-")
trace = None
self.traces.append(trace)
diff --git a/tuna/sysfs.py b/tuna/sysfs.py
index d6aa4a67cb1b..acc81d667753 100755
--- a/tuna/sysfs.py
+++ b/tuna/sysfs.py
@@ -61,10 +61,10 @@ class cpus:
return self.cpus[key]
def keys(self):
- return self.cpus.keys()
+ return list(self.cpus.keys())
def has_key(self, key):
- return self.cpus.has_key(key)
+ return key in self.cpus
def reload(self):
sockets_to_sort = []
@@ -96,12 +96,12 @@ if __name__ == '__main__':
cpus = cpus()
- for socket in cpus.sockets.keys():
- print "Socket %s" % socket
+ for socket in list(cpus.sockets.keys()):
+ print("Socket %s" % socket)
for c in cpus.sockets[socket]:
- print " %s" % c.name
- print " online: %s" % c.online
+ print(" %s" % c.name)
+ print(" online: %s" % c.online)
c.set_online(False)
- print " online: %s" % c.online
+ print(" online: %s" % c.online)
c.set_online()
- print " online: %s" % c.online
+ print(" online: %s" % c.online)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index 196bbbf3aca7..29248352231e 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -2,7 +2,8 @@
# -*- coding: utf-8 -*-
import copy, ethtool, errno, os, procfs, re, schedutils, sys, shlex
-import help, fnmatch
+from . import help
+import fnmatch
from procfs import utilist
try:
@@ -96,7 +97,7 @@ def has_threaded_irqs(ps):
def set_irq_affinity_filename(filename, bitmasklist):
pathname="/proc/irq/%s" % filename
f = file(pathname, "w")
- text = ",".join(map(lambda a: "%x" % a, bitmasklist))
+ text = ",".join(["%x" % a for a in bitmasklist])
f.write("%s\n" % text)
try:
f.close()
@@ -125,7 +126,7 @@ def cpustring_to_list(cpustr):
if len(ends) > 2:
raise SyntaxError("Syntax error")
if len(ends) == 2:
- cpu_list += range(ends[0], ends[1] + 1)
+ cpu_list += list(range(ends[0], ends[1] + 1))
else:
cpu_list += [ends[0]]
return list(set(cpu_list))
@@ -235,16 +236,16 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning =
None,
elif set_affinity_warning:
set_affinity_warning(pid, new_affinity)
else:
- print "move_threads_to_cpu: %s " % \
+ print("move_threads_to_cpu: %s " % \
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
- {'pid':pid, 'new_affinity':new_affinity})
+ {'pid':pid, 'new_affinity':new_affinity}))
# See if this is the thread group leader
- if not ps.has_key(pid):
+ if pid not in ps:
continue
threads = procfs.pidstats("/proc/%d/task" % pid)
- for tid in threads.keys():
+ for tid in list(threads.keys()):
try:
curr_affinity = schedutils.get_affinity(tid)
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised
SystemError
@@ -264,15 +265,15 @@ def move_threads_to_cpu(cpus, pid_list, set_affinity_warning =
None,
elif set_affinity_warning:
set_affinity_warning(tid, new_affinity)
else:
- print "move_threads_to_cpu: %s " % \
+ print("move_threads_to_cpu: %s " % \
(_("could not change %(pid)d affinity to %(new_affinity)s") % \
- {'pid':pid, 'new_affinity':new_affinity})
+ {'pid':pid, 'new_affinity':new_affinity}))
except (SystemError, OSError) as e: # old python-schedutils incorrectly raised
SystemError
if e[0] == errno.ESRCH:
# process died
continue
elif e[0] == errno.EINVAL: # unmovable thread)
- print >> stderr, "thread %(pid)d cannot be moved as requested"
%{'pid':pid}
+ print("thread %(pid)d cannot be moved as requested" %{'pid':pid},
file=stderr)
continue
raise e
return changed
@@ -330,7 +331,7 @@ def affinity_remove_cpus(affinity, cpus, nr_cpus):
# If the cpu being isolated was the only one in the current affinity
affinity = list(set(affinity) - set(cpus))
if not affinity:
- affinity = range(nr_cpus)
+ affinity = list(range(nr_cpus))
affinity = list(set(affinity) - set(cpus))
return affinity
@@ -347,7 +348,7 @@ def isolate_cpus(cpus, nr_cpus):
ps = procfs.pidstats()
ps.reload_threads()
previous_pid_affinities = {}
- for pid in ps.keys():
+ for pid in list(ps.keys()):
if cannot_set_affinity(ps, pid):
continue
try:
@@ -356,7 +357,7 @@ def isolate_cpus(cpus, nr_cpus):
if e[0] == errno.ESRCH:
continue
elif e[0] == errno.EINVAL:
- print >> sys.stderr, "Function:", fname,
",", e.strerror
+ print("Function:", fname, ",",
e.strerror, file=sys.stderr)
sys.exit(2)
raise e
if set(affinity).intersection(set(cpus)):
@@ -368,14 +369,14 @@ def isolate_cpus(cpus, nr_cpus):
if e[0] == errno.ESRCH:
continue
elif e[0] == errno.EINVAL:
- print >> sys.stderr, "Function:",
fname, ",", e.strerror
+ print("Function:", fname, ",",
e.strerror, file=sys.stderr)
sys.exit(2)
raise e
- if not ps[pid].has_key("threads"):
+ if "threads" not in ps[pid]:
continue
threads = ps[pid]["threads"]
- for tid in threads.keys():
+ for tid in list(threads.keys()):
if cannot_set_thread_affinity(ps, pid, tid):
continue
try:
@@ -384,7 +385,7 @@ def isolate_cpus(cpus, nr_cpus):
if e[0] == errno.ESRCH:
continue
elif e[0] == errno.EINVAL:
- print >> sys.stderr, "Function:",
fname, ",", e.strerror
+ print("Function:", fname, ",",
e.strerror, file=sys.stderr)
sys.exit(2)
raise e
if set(affinity).intersection(set(cpus)):
@@ -396,7 +397,7 @@ def isolate_cpus(cpus, nr_cpus):
if e[0] == errno.ESRCH:
continue
elif e[0] == errno.EINVAL:
- print >> sys.stderr,
"Function:", fname, ",", e.strerror
+ print("Function:", fname,
",", e.strerror, file=sys.stderr)
sys.exit(2)
raise e
@@ -405,9 +406,9 @@ def isolate_cpus(cpus, nr_cpus):
# Now isolate it from IRQs too
irqs = procfs.interrupts()
previous_irq_affinities = {}
- for irq in irqs.keys():
+ for irq in list(irqs.keys()):
# LOC, NMI, TLB, etc
- if not irqs[irq].has_key("affinity"):
+ if "affinity" not in irqs[irq]:
continue
affinity = irqs[irq]["affinity"]
if set(affinity).intersection(set(cpus)):
@@ -427,7 +428,7 @@ def include_cpus(cpus, nr_cpus):
ps = procfs.pidstats()
ps.reload_threads()
previous_pid_affinities = {}
- for pid in ps.keys():
+ for pid in list(ps.keys()):
if cannot_set_affinity(ps, pid):
continue
try:
@@ -446,10 +447,10 @@ def include_cpus(cpus, nr_cpus):
continue
raise e
- if not ps[pid].has_key("threads"):
+ if "threads" not in ps[pid]:
continue
threads = ps[pid]["threads"]
- for tid in threads.keys():
+ for tid in list(threads.keys()):
if cannot_set_thread_affinity(ps, pid, tid):
continue
try:
@@ -473,9 +474,9 @@ def include_cpus(cpus, nr_cpus):
# Now include it in IRQs too
irqs = procfs.interrupts()
previous_irq_affinities = {}
- for irq in irqs.keys():
+ for irq in list(irqs.keys()):
# LOC, NMI, TLB, etc
- if not irqs[irq].has_key("affinity"):
+ if "affinity" not in irqs[irq]:
continue
affinity = irqs[irq]["affinity"]
if set(affinity).intersection(set(cpus)) != set(cpus):
@@ -564,7 +565,7 @@ def threads_set_priority(tids, parm, affect_children = False):
try:
(policy, rtprio) = get_policy_and_rtprio(parm)
except ValueError:
- print "tuna: " + _("\"%s\" is unsupported priority
value!") % parms[0]
+ print("tuna: " + _("\"%s\" is unsupported priority
value!") % parms[0])
return
for tid in tids:
@@ -598,7 +599,7 @@ def get_kthread_sched_tunings(proc = None):
proc = procfs.pidstats()
kthreads = {}
- for pid in proc.keys():
+ for pid in list(proc.keys()):
name = proc[pid]["stat"]["comm"]
# Trying to set the priority of the migration threads will
# fail, at least on 3.6.0-rc1 and doesn't make sense anyway
@@ -631,19 +632,19 @@ def run_command(cmd, policy, rtprio, cpu_list):
try:
thread_set_priority(pid, policy, rtprio)
except (SystemError, OSError) as err:
- print "tuna: %s" % err
+ print("tuna: %s" % err)
sys.exit(2)
if cpu_list:
try:
schedutils.set_affinity(pid, cpu_list)
except (SystemError, OSError) as err:
- print "tuna: %s" % err
+ print("tuna: %s" % err)
sys.exit(2)
try:
os.execvp(cmd_list[0], cmd_list)
except (SystemError, OSError) as err:
- print "tuna: %s" % err
+ print("tuna: %s" % err)
sys.exit(2)
else:
os.waitpid(newpid, 0);
@@ -677,7 +678,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
f.write("kthreads:*:1:*:\[.*\]$\n\n")
per_cpu_kthreads = []
- names = kthreads.keys()
+ names = list(kthreads.keys())
names.sort()
for name in names:
kt = kthreads[name]
diff --git a/tuna/tuna_gui.py b/tuna/tuna_gui.py
index 22a53b9a2991..490dc5946cbc 100755
--- a/tuna/tuna_gui.py
+++ b/tuna/tuna_gui.py
@@ -7,12 +7,12 @@ pygtk.require("2.0")
import gtk, gobject, os, procfs, sys
import gtk.glade
from gtk import ListStore
-from gui.cpuview import cpuview
-from gui.irqview import irqview
-from gui.procview import procview
-from gui.commonview import commonview
-from gui.profileview import profileview
-from config import Config
+from .gui.cpuview import cpuview
+from .gui.irqview import irqview
+from .gui.procview import procview
+from .gui.commonview import commonview
+from .gui.profileview import profileview
+from .config import Config
tuna_glade_dirs = [ ".", "tuna", "/usr/share/tuna" ]
tuna_glade = None
--
2.14.3