Updating python code to python3

This commit is contained in:
Ingo Ruhnke 2019-11-24 18:36:25 +01:00
parent 47ecf50f7c
commit e37d3558a1
3 changed files with 34 additions and 34 deletions

View file

@ -1,14 +1,14 @@
#!/usr/bin/env python #!/usr/bin/env python3
import sys import sys
import string import string
if len(sys.argv) != 3: if len(sys.argv) != 3:
print "Usage:", sys.argv[0], "STEPS", "EQUATION" print("Usage:", sys.argv[0], "STEPS", "EQUATION")
print "Simple generator for generating responsecurve data from equations." print("Simple generator for generating responsecurve data from equations.")
print "" print("")
print "Example:" print("Example:")
print " ", sys.argv[0], "6 i**2" print(" ", sys.argv[0], "6 i**2")
else: else:
steps = int(sys.argv[1]) steps = int(sys.argv[1])
equation = sys.argv[2] equation = sys.argv[2]
@ -19,6 +19,6 @@ else:
left.reverse() left.reverse()
left = left[0:-1] left = left[0:-1]
print string.join([str(x) for x in (left + right)], ":") print(string.join([str(x) for x in (left + right)], ":"))
# EOF # # EOF #

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python #!/usr/bin/env python3
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or # the Free Software Foundation, either version 3 of the License, or
@ -409,7 +409,7 @@ class ProcessManager(object):
""" """
# Since reap() modifies __procs, we have to iterate over a copy # Since reap() modifies __procs, we have to iterate over a copy
# of the keys in it. Thus, do not remove the .keys() call. # of the keys in it. Thus, do not remove the .keys() call.
for procid in self.__procs.keys(): for procid in list(self.__procs.keys()):
self.reap(procid) self.reap(procid)
@ -445,7 +445,7 @@ import os, sys
import os.path import os.path
import fcntl import fcntl
import time import time
import ConfigParser import configparser
from subprocess import check_call, Popen, PIPE from subprocess import check_call, Popen, PIPE
from signal import SIGINT, SIGKILL from signal import SIGINT, SIGKILL
from optparse import OptionParser from optparse import OptionParser
@ -482,7 +482,7 @@ class RunXBoxDrv(object):
@staticmethod @staticmethod
def runCommandAndGetOutput(command): def runCommandAndGetOutput(command):
print command print(command)
callcommand = Popen(command, shell=True, stdout=PIPE) callcommand = Popen(command, shell=True, stdout=PIPE)
outputcommand = callcommand.communicate() outputcommand = callcommand.communicate()
return outputcommand[0].split("\n") return outputcommand[0].split("\n")
@ -517,7 +517,7 @@ class RunXBoxDrv(object):
if RunXBoxDrv.which(RunXBoxDrv.sudo_command) is None: if RunXBoxDrv.which(RunXBoxDrv.sudo_command) is None:
raise Exception("Cannot find %s!" % RunXBoxDrv.sudo_command) raise Exception("Cannot find %s!" % RunXBoxDrv.sudo_command)
commandline = "%s %s" % (RunXBoxDrv.sudo_command, command) commandline = "%s %s" % (RunXBoxDrv.sudo_command, command)
print commandline print(commandline)
callcommand = Popen(commandline, shell=True, stdout=PIPE) callcommand = Popen(commandline, shell=True, stdout=PIPE)
outputcommand = callcommand.communicate() outputcommand = callcommand.communicate()
return outputcommand[0] return outputcommand[0]
@ -525,14 +525,14 @@ class RunXBoxDrv(object):
@staticmethod @staticmethod
def killExistingXBoxDrv(sig, signame): def killExistingXBoxDrv(sig, signame):
for line in RunXBoxDrv.runCommandAndGetOutput("ps"): for line in RunXBoxDrv.runCommandAndGetOutput("ps"):
print line print(line)
fields = line.split() fields = line.split()
if len(fields) < 4: if len(fields) < 4:
continue continue
pid = fields[0] pid = fields[0]
process = fields[3] process = fields[3]
if process.find(XBOXDRVNAME) != -1: if process.find(XBOXDRVNAME) != -1:
print "Using %s on existing %s" % (signame, XBOXDRVNAME) print("Using %s on existing %s" % (signame, XBOXDRVNAME))
os.kill(int(pid), sig) os.kill(int(pid), sig)
return True return True
return False return False
@ -542,7 +542,7 @@ class RunXBoxDrv(object):
loadedmodules = [] loadedmodules = []
unloadedmodules = [] unloadedmodules = []
for line in RunXBoxDrv.runCommandAndGetOutput("lsmod"): for line in RunXBoxDrv.runCommandAndGetOutput("lsmod"):
print line print(line)
fields = line.split() fields = line.split()
if len(fields) < 3: if len(fields) < 3:
continue continue
@ -555,17 +555,17 @@ class RunXBoxDrv(object):
unloadedmodules.append(modulename) unloadedmodules.append(modulename)
for modulename in MODULELOAD: for modulename in MODULELOAD:
if modulename in loadedmodules: if modulename in loadedmodules:
print "%s already loaded!" % modulename print("%s already loaded!" % modulename)
else: else:
print "Loading %s!" % modulename print("Loading %s!" % modulename)
print RunXBoxDrv.runCommandAsRoot("modprobe %s" % modulename) print(RunXBoxDrv.runCommandAsRoot("modprobe %s" % modulename))
for modulename in MODULEUNLOAD: for modulename in MODULEUNLOAD:
if modulename in unloadedmodules: if modulename in unloadedmodules:
print "Unloading %s!" % modulename print("Unloading %s!" % modulename)
print RunXBoxDrv.runCommandAsRoot("rmmod %s" % modulename) print(RunXBoxDrv.runCommandAsRoot("rmmod %s" % modulename))
else: else:
print "%s already unloaded!" % modulename print("%s already unloaded!" % modulename)
@staticmethod @staticmethod
@ -579,11 +579,11 @@ class RunXBoxDrv(object):
raise Exception("Cannot find one of: %s!" % str(UINPUT_LOCATIONS)) raise Exception("Cannot find one of: %s!" % str(UINPUT_LOCATIONS))
if not os.access(location, os.W_OK): if not os.access(location, os.W_OK):
print "Trying to change permissions of: %s" % location print("Trying to change permissions of: %s" % location)
print RunXBoxDrv.runCommandAsRoot("chmod 0660 %s" % location) print(RunXBoxDrv.runCommandAsRoot("chmod 0660 %s" % location))
if os.access(location, os.W_OK): if os.access(location, os.W_OK):
print "%s is writable!" % location print("%s is writable!" % location)
else: else:
raise Exception("Could not set write permissions on %s" % location) raise Exception("Could not set write permissions on %s" % location)
@ -614,36 +614,36 @@ class RunXBoxDrv(object):
out = "" out = ""
while out.lower().find(LOADEDTEXT) == -1: while out.lower().find(LOADEDTEXT) == -1:
out = RunXBoxDrv.getNext(myProc) out = RunXBoxDrv.getNext(myProc)
print out print(out)
def process(self): def process(self):
commandlist = [self.xboxdrvpath] commandlist = [self.xboxdrvpath]
if self.configfile: if self.configfile:
commandlist = commandlist + ["--config=%s" % self.configfile] commandlist = commandlist + ["--config=%s" % self.configfile]
print commandlist print(commandlist)
myProc = Process(commandlist) myProc = Process(commandlist)
with_timeout(1, self.checkLoaded, myProc) with_timeout(1, self.checkLoaded, myProc)
if len(self.appandparams) == 0: if len(self.appandparams) == 0:
print("WARNING: No path to application specified!") print("WARNING: No path to application specified!")
else: else:
print(self.appandparams) print((self.appandparams))
check_call(self.appandparams) check_call(self.appandparams)
print "Sending SIGINT" print("Sending SIGINT")
myProc.kill(SIGINT) myProc.kill(SIGINT)
try: try:
with_timeout(1, myProc.wait) with_timeout(1, myProc.wait)
sys.exit(0) sys.exit(0)
except Timeout: except Timeout:
pass pass
print "Sending SIGINT again" print("Sending SIGINT again")
myProc.kill(SIGINT) myProc.kill(SIGINT)
try: try:
with_timeout(1, myProc.wait) with_timeout(1, myProc.wait)
sys.exit(0) sys.exit(0)
except Timeout: except Timeout:
pass pass
print "Killing" print("Killing")
myProc.terminate() myProc.terminate()
def main(): def main():

View file

@ -1,4 +1,4 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
## Xbox360 USB Gamepad Userspace Driver ## Xbox360 USB Gamepad Userspace Driver
## Copyright (C) 2011 Ingo Ruhnke <grumbel@gmail.com> ## Copyright (C) 2011 Ingo Ruhnke <grumbel@gmail.com>
@ -71,7 +71,7 @@ elif options.bus == "auto":
except dbus.exceptions.DBusException: except dbus.exceptions.DBusException:
bus = dbus.SystemBus() bus = dbus.SystemBus()
else: else:
print "Error: invalid argument to --bus. Must be 'auto', 'session, or 'system'" print("Error: invalid argument to --bus. Must be 'auto', 'session, or 'system'")
exit() exit()
if options.status: if options.status:
@ -82,7 +82,7 @@ elif options.shutdown:
daemon.Shutdown() daemon.Shutdown()
else: else:
if (options.led or options.rumble or options.config) and options.slot == None: if (options.led or options.rumble or options.config) and options.slot == None:
print "Error: --slot argument required" print("Error: --slot argument required")
exit() exit()
else: else:
if options.slot != None: if options.slot != None:
@ -94,7 +94,7 @@ else:
if options.rumble: if options.rumble:
m = re.match('^(\d+):(\d+)$', options.rumble) m = re.match('^(\d+):(\d+)$', options.rumble)
if not m: if not m:
print "Error: invalid argument to --rumble" print("Error: invalid argument to --rumble")
exit() exit()
else: else:
left = int(m.group(1)) left = int(m.group(1))