From edb4b03659f86d41f1e69cfc8243591257f2121a Mon Sep 17 00:00:00 2001 From: achbed Date: Mon, 26 Jan 2015 16:44:26 -0600 Subject: [PATCH] Additional coding style cleanup Signed-off-by: achbed --- deefuzzer/core.py | 27 ++++++++++--------- deefuzzer/station.py | 1 - deefuzzer/tools/PyRSS2Gen.py | 1 + deefuzzer/tools/ogg.py | 2 +- deefuzzer/tools/xmltodict2.py | 49 ++++++++++++++++------------------- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/deefuzzer/core.py b/deefuzzer/core.py index 7fbaf07..ee82fd5 100644 --- a/deefuzzer/core.py +++ b/deefuzzer/core.py @@ -46,7 +46,7 @@ from threading import Thread from deefuzzer.station import * from deefuzzer.tools import * -mimetypes.add_type('application/x-yaml','.yaml') +mimetypes.add_type('application/x-yaml', '.yaml') class DeeFuzzer(Thread): @@ -115,7 +115,6 @@ class DeeFuzzer(Thread): self._info('Using libshout version %s' % shout.version()) self._info('Number of stations : ' + str(len(self.station_settings))) - def _log(self, level, msg): try: obj = {'msg': 'Core: ' + str(msg), 'level': level} @@ -137,7 +136,7 @@ class DeeFuzzer(Thread): m3u.write('#EXTM3U\n') for k in self.station_instances.keys(): s = self.station_instances[k] - m3u.write('#EXTINF:%s,%s - %s\n' % ('-1',s.short_name, s.channel.name)) + m3u.write('#EXTINF:%s,%s - %s\n' % ('-1', s.short_name, s.channel.name)) m3u.write('http://' + s.channel.host + ':' + str(s.channel.port) + s.channel.mount + '\n') m3u.close() self._info('Writing M3U file to : ' + self.m3u) @@ -146,12 +145,12 @@ class DeeFuzzer(Thread): """Scan a folder for subfolders containing media, and make stations from them all.""" options = self.watchfolder - if not 'folder' in options.keys(): + if 'folder' not in options.keys(): # We have no folder specified. Bail. return if self.mainLoop: - if not 'livecreation' in options.keys(): + if 'livecreation' not in options.keys(): # We have no folder specified. Bail. return @@ -167,9 +166,9 @@ class DeeFuzzer(Thread): # This makes the log file a lot more verbose. Commented out since we report on new stations anyway. # self._info('Scanning folder ' + folder + ' for stations') - if not 'infos' in options.keys(): + if 'infos' not in options.keys(): options['infos'] = {} - if not 'short_name' in options['infos'].keys(): + if 'short_name' not in options['infos'].keys(): options['infos']['short_name'] = '[name]' files = os.listdir(folder) @@ -182,9 +181,9 @@ class DeeFuzzer(Thread): def station_exists(self, name): try: for s in self.station_settings: - if not 'infos' in s.keys(): + if 'infos' not in s.keys(): continue - if not 'short_name' in s['infos'].keys(): + if 'short_name' not in s['infos'].keys(): continue if s['infos']['short_name'] == name: return True @@ -201,11 +200,11 @@ class DeeFuzzer(Thread): if self.station_exists(name): return self._info('Creating station for folder ' + folder) - d = dict(path=folder,name=name) + d = dict(path=folder, name=name) for i in options.keys(): - if not 'folder' in i: + if 'folder' not in i: s[i] = replace_all(options[i], d) - if not 'media' in s.keys(): + if 'media' not in s.keys(): s['media'] = {} s['media']['source'] = folder @@ -276,7 +275,7 @@ class DeeFuzzer(Thread): if 'station_name' in self.station_settings[i].keys(): name = self.station_settings[i]['station_name'] - if not 'retries' in self.station_settings[i].keys(): + if 'retries' not in self.station_settings[i].keys(): self.station_settings[i]['retries'] = 0 try: @@ -289,7 +288,7 @@ class DeeFuzzer(Thread): if self.maxretry >= 0 and self.station_settings[i]['retries'] <= self.maxretry: # Station passed the max retries count is will not be reloaded - if not 'station_stop_logged' in self.station_settings[i].keys(): + if 'station_stop_logged' not in self.station_settings[i].keys(): self._err('Station ' + name + ' is stopped and will not be restarted.') self.station_settings[i]['station_stop_logged'] = True continue diff --git a/deefuzzer/station.py b/deefuzzer/station.py index 36124dd..59eeb15 100644 --- a/deefuzzer/station.py +++ b/deefuzzer/station.py @@ -806,7 +806,6 @@ class Station(Thread): return False return True - def icecastloop_metadata(self): try: self.update_twitter_current() diff --git a/deefuzzer/tools/PyRSS2Gen.py b/deefuzzer/tools/PyRSS2Gen.py index a2122f7..eb4edc3 100644 --- a/deefuzzer/tools/PyRSS2Gen.py +++ b/deefuzzer/tools/PyRSS2Gen.py @@ -8,6 +8,7 @@ _generator_name = __name__ + "-" + ".".join(map(str, __version__)) import datetime + # Could make this the base class; will need to add 'publish' class WriteXmlMixin: def __init__(self): diff --git a/deefuzzer/tools/ogg.py b/deefuzzer/tools/ogg.py index 3c196a1..bca591d 100644 --- a/deefuzzer/tools/ogg.py +++ b/deefuzzer/tools/ogg.py @@ -128,7 +128,7 @@ class Ogg: def get_args(self, options=None): """Get process options and return arguments for the encoder""" args = [] - if not options is None: + if options is not None: self.options = options if not ('verbose' in self.options and self.options['verbose'] != '0'): args.append('-Q ') diff --git a/deefuzzer/tools/xmltodict2.py b/deefuzzer/tools/xmltodict2.py index 90b2ac8..1724ec3 100644 --- a/deefuzzer/tools/xmltodict2.py +++ b/deefuzzer/tools/xmltodict2.py @@ -10,18 +10,18 @@ import locale from xml.parsers import expat # If we're in Dabo, get the default encoding. -#import dabo -#import dabo.lib.DesignerUtils as desUtil -#from dabo.dLocalize import _ -#from dabo.lib.utils import resolvePath -#app = dabo.dAppRef -#if app is not None: - #default_encoding = app.Encoding -#else: - #enc = locale.getlocale()[1] - #if enc is None: - #enc = dabo.defaultEncoding - #default_encoding = enc +# import dabo +# import dabo.lib.DesignerUtils as desUtil +# from dabo.dLocalize import _ +# from dabo.lib.utils import resolvePath +# app = dabo.dAppRef +# if app is not None: + # default_encoding = app.Encoding +# else: + # enc = locale.getlocale()[1] + # if enc is None: + # enc = dabo.defaultEncoding + # default_encoding = enc # Python seems to need to compile code with \n linesep: code_linesep = "\n" @@ -45,7 +45,6 @@ class Xml2Obj: self._currPropAtt = "" self._currPropDict = None - def StartElement(self, name, attributes): """SAX start element even handler""" if name == "code": @@ -95,7 +94,6 @@ class Xml2Obj: self.root = element self.nodeStack.append(element) - def EndElement(self, name): """SAX end element event handler""" if self._inCode: @@ -156,7 +154,6 @@ class Xml2Obj: ParserStatus = Parser.Parse(xml, 1) return self.root - def ParseFromFile(self, filename): return self.Parse(open(filename,"r").read()) @@ -274,7 +271,7 @@ def dicttoxml(dct, level=0, header=None, linesep=None): ret += "%s<%s>%s%s%s" % (methodTab, mthd, eol, cd, eol, methodTab, mthd, eol) - ret += "%s%s" % ("\t" * (level+1), eol) + ret += "%s%s" % ("\t" * (level+1), eol) if dct.has_key("properties"): if len(dct["properties"].keys()): @@ -287,7 +284,7 @@ def dicttoxml(dct, level=0, header=None, linesep=None): ret += "%s<%s>%s%s" % (itmTab, propItm, itmVal, propItm, eol) ret += "%s%s" % (currTab, prop, eol) - ret += "%s%s" % ("\t" * (level+1), eol) + ret += "%s%s" % ("\t" * (level+1), eol) if dct.has_key("children") and len(dct["children"]) > 0: ret += eol @@ -386,12 +383,12 @@ def addInheritedInfo(src, super, updateCode=False): -#if __name__ == "__main__": - #test_dict = {"name": "test", "attributes":{"path": "c:\\temp\\name", - #"problemChars": "Welcome to \xc2\xae".decode("latin-1")}} - #print "test_dict:", test_dict - #xml = dicttoxml(test_dict) - #print "xml:", xml - #test_dict2 = xmltodict(xml) - #print "test_dict2:", test_dict2 - #print "same?:", test_dict == test_dict2 +# if __name__ == "__main__": + # test_dict = {"name": "test", "attributes":{"path": "c:\\temp\\name", + # "problemChars": "Welcome to \xc2\xae".decode("latin-1")}} + # print "test_dict:", test_dict + # xml = dicttoxml(test_dict) + # print "xml:", xml + # test_dict2 = xmltodict(xml) + # print "test_dict2:", test_dict2 + # print "same?:", test_dict == test_dict2 -- 2.39.5