diff options
Diffstat (limited to 'serviceconfig/serviceconfig.py')
-rwxr-xr-x | serviceconfig/serviceconfig.py | 78 |
1 files changed, 39 insertions, 39 deletions
diff --git a/serviceconfig/serviceconfig.py b/serviceconfig/serviceconfig.py index 244e40e..d806f8e 100755 --- a/serviceconfig/serviceconfig.py +++ b/serviceconfig/serviceconfig.py @@ -58,7 +58,7 @@ class DescriptionCache(object): def __init__(self,filename,path="/tmp"): if not os.path.isdir(path): - print path, "is not a valid directory, can't cache." + print(path, "is not a valid directory, can't cache.") self.filename = os.path.join(path,filename) @@ -68,15 +68,15 @@ class DescriptionCache(object): pickler = Unpickler(fhandle) self.data = pickler.load() fhandle.close() - except IOError, e: - print "Couldn't load file:", e - print "Not reading description cache data" + except IOError as e: + print("Couldn't load file:", e) + print("Not reading description cache data") def saveCache(self): """ Save pickled dataobject to the file. We don't want the user to be able to save a datastructure that root will read in since that would have implications for security.""" if not isroot: - print "Not saving description cache data for security reasons, we're not root" + print("Not saving description cache data for security reasons, we're not root") return try: @@ -85,8 +85,8 @@ class DescriptionCache(object): pickler.dump(self.data) fhandle.close() #print "Saved description cache data to ", self.filename - except IOError, e: - print "Can't cache:", e + except IOError as e: + print("Can't cache:", e) def add(self,filename,packagename,description): self.data[filename] = (packagename,description) @@ -117,7 +117,7 @@ class Service(object): self.runlevels = [] self.gotStatus = False self.statusable = False - self.status = unicode(i18n("?")) + self.status = str(i18n("?")) self.startpriority = "50" self.killpriority = "50" @@ -392,7 +392,7 @@ class DebianService(Service): self.runlevels = [] self.gotStatus = False self.statusable = False - self.status = unicode(i18n("not running")) + self.status = str(i18n("not running")) self.startpriority = "50" self.killpriority = "50" self.getStatusFrom = "pidfile" @@ -433,7 +433,7 @@ class DebianService(Service): if ":" in line: self.packagename = line.strip().split(":")[0] else: - print self.path_and_filename + " is no file or does not exist!" + print(self.path_and_filename + " is no file or does not exist!") ######################################################################## def fetchStatus(self): @@ -452,14 +452,14 @@ class DebianService(Service): def fetchStatusFromPidFile(self): try: if os.path.isfile(os.path.join('/var/run',self.pidfiles[self.filename])): - self.status = unicode(i18n("running")) + self.status = str(i18n("running")) else: - self.status = unicode(i18n("not running")) + self.status = str(i18n("not running")) except KeyError: if os.path.isfile(os.path.join('/var/run',self.filename + '.pid')): - self.status = unicode(i18n("running")) + self.status = str(i18n("running")) else: - self.status = unicode(i18n("not running")) + self.status = str(i18n("not running")) self.gotStatus = True ############################################################################ @@ -546,7 +546,7 @@ class DebianServiceContext(ServiceContext): shell_output.close() cur_runlevel = raw_runlevel[2:-1] - for num in deb_runlevels.keys(): + for num in list(deb_runlevels.keys()): if cur_runlevel.isdigit(): if num == int(cur_runlevel): self.__currentrunlevel = DebianRunLevel(self, num, deb_runlevels[num]) @@ -554,11 +554,11 @@ class DebianServiceContext(ServiceContext): else: self.runlevels.append(DebianRunLevel(self, num, deb_runlevels[num])) else: - if num == cur_runlevel: - self.__currentrunlevel = DebianRunLevel(self, num, deb_runlevels[num]) + if num == cur_runlevel: + self.__currentrunlevel = DebianRunLevel(self, num, deb_runlevels[num]) self.runlevels.append(self.__currentrunlevel) - else: - self.runlevels.append(DebianRunLevel(self, num, deb_runlevels[num])) + else: + self.runlevels.append(DebianRunLevel(self, num, deb_runlevels[num])) self._filenametoservice = {} ######################################################################## @@ -632,22 +632,22 @@ class DebianRunLevel(SysVRunLevel): #print "Removing symlink, " + linkname + ", the target does not match." try: posix.unlink(linkname) - except OSError, e: - print "Couldn't remove symlink " + linkname + " :: " + str(e) + except OSError as e: + print("Couldn't remove symlink " + linkname + " :: " + str(e)) try: posix.symlink(target, linkname) #print "Created symlink " + linkname + " -> " + target + " successfully." os.chdir(odir) return True - except OSError, e: + except OSError as e: #print "Creating symlink " + linkname + " -> " + target + " failed: " + str(e) os.chdir(odir) return False def removeSymlink(servicename, runleveldir, KorS): if KorS not in ('K','S'): - print "OUCH, symlinks have to start with S or K!" + print("OUCH, symlinks have to start with S or K!") return for link in os.listdir(runleveldir): if (link[0] == KorS) and (link[3:] == servicename): @@ -672,8 +672,8 @@ class DebianRunLevel(SysVRunLevel): runleveldir = os.path.join(leveldir,"rc"+l_num+".d") #print "Removing symlink " + s_link removeSymlink(service.filename, runleveldir, "S") - except OSError, e: - print "Could not remove symlink " + s_link + " :: " + str(e) + except OSError as e: + print("Could not remove symlink " + s_link + " :: " + str(e)) self.activeservices.remove(service) @@ -698,8 +698,8 @@ class DebianRunLevel(SysVRunLevel): try: #print "Removing " + k_link removeSymlink(service.filename, runleveldir, "K") - except OSError, e: - print "Could not remove " + k_link + " :: " + str(e) + except OSError as e: + print("Could not remove " + k_link + " :: " + str(e)) ############################################################################ @@ -746,7 +746,7 @@ class GentooService(DebianService): else: description_lines.append(line[1:].strip()) fhandle.close() else: - print self.path_and_filename + " is no file or does not exist!" + print(self.path_and_filename + " is no file or does not exist!") if len(description_lines): self.description = "\n".join(description_lines) @@ -812,7 +812,7 @@ class GentooServiceContext(ServiceContext): def currentRunLevelNum(): runlevelbin = "/sbin/runlevel" if not os.path.isfile(runlevelbin): - print "Couldn't find %s, that sucks. :o" % runlevelbin + print("Couldn't find %s, that sucks. :o" % runlevelbin) sys.exit(1) shell_output = os.popen(runlevelbin) raw_runlevel = shell_output.readline() @@ -877,7 +877,7 @@ class GentooRunLevel(SysVRunLevel): #self.no_dirs = ('reboot', 'shutdown', 'single') if self.dirname not in self.no_dirs: self.no_dirs.append(self.dirname) - print "Runlevel " + self.leveldir + " is not a valid path. '" + self.dirname + "'" + print("Runlevel " + self.leveldir + " is not a valid path. '" + self.dirname + "'") self.leveldir = False return @@ -885,7 +885,7 @@ class GentooRunLevel(SysVRunLevel): def loadInfo(self): """ Only look up active services if runlevel path exists, else leave empty. """ if self.leveldir: - print "GentooRunLevel.loadInfo() from " + self.leveldir + print("GentooRunLevel.loadInfo() from " + self.leveldir) for filename in os.listdir(self.leveldir): # Exclude backup files from portage and .sh files like shutdown, depscan, etc. if (filename.find('._cfg')<0) and not filename.endswith('.sh'): @@ -895,9 +895,9 @@ class GentooRunLevel(SysVRunLevel): if target in self.context._filenametoservice: self.activeservices.append(self.context._filenametoservice[target]) else: - print "Couldn't find service '%s'. " % target + print("Couldn't find service '%s'. " % target) else: - print "%s is not a valid symlink." % linkname + print("%s is not a valid symlink." % linkname) ######################################################################## def setActiveAtBoot(self,service,activeflag): @@ -908,18 +908,18 @@ class GentooRunLevel(SysVRunLevel): # FIXME :: "Start at Boot" column does not properly get updated once it's "False". # The commands issued might better be passed through via CommandRunner. if self.name in self.no_dirs: - print "Runlevel has no corresponding path, running rc-update anyway." + print("Runlevel has no corresponding path, running rc-update anyway.") if activeflag: if not service in self.activeservices: rc_add_cmd = "rc-update add %s %s" % (service.filename, self.dirname) - print rc_add_cmd + print(rc_add_cmd) # The brave really run it yet. os.system(rc_add_cmd) self.activeservices.append(service) else: if service in self.activeservices: rc_del_cmd = "rc-update del %s %s" % (service.filename, self.dirname) - print rc_del_cmd + print(rc_del_cmd) # The brave really run it yet. os.system(rc_dell_cmd) self.activeservices.remove(service) @@ -1194,7 +1194,7 @@ class SysVInitApp(programbase): return self.updatingGUI = True - for service in self.servicestolistitems.keys(): + for service in list(self.servicestolistitems.keys()): if self.servicestolistitems[service] is item: self.selectedservice = service self.__selectService(self.selectedservice) @@ -1440,13 +1440,13 @@ class CommandRunner(KDialogBase): uncolor = lambda text: re.compile('\\x1b\[[0-9]+;01m').sub("", \ re.compile('\\x1b\[0m').sub("", re.compile('\\033\[1;[0-9]+m').sub("", \ re.compile('\\033\[0m').sub("", text)))) - self.output += uncolor(unicode(self.kid.readStdout())) + self.output += uncolor(str(self.kid.readStdout())) self.outputtextview.setText(self.output) self.outputtextview.ensureVisible(0,self.outputtextview.contentsHeight()) ######################################################################## def slotReadyReadStderr(self): - self.output += unicode(self.kid.readStderr()) + self.output += str(self.kid.readStderr()) self.outputtextview.setText(self.output) self.outputtextview.ensureVisible(0,self.outputtextview.contentsHeight()) |