From acbef6591c6032617792d5b71f8a1824f1d3342b Mon Sep 17 00:00:00 2001 From: Bastian Schroll Date: Mon, 2 Oct 2017 07:25:22 +0200 Subject: [PATCH] edits for codacy (#310) --- CHANGELOG.md | 1 + includes/helper/stringConverter.py | 1 - includes/pynma/pynma.py | 14 ++++----- install.sh | 4 +-- plugins/MySQL/MySQL.py | 32 ++++++++++---------- plugins/Sms77/Sms77.py | 2 +- plugins/httpRequest/httpRequest.py | 4 +-- plugins/notifyMyAndroid/notifyMyAndroid.py | 34 +++++++++++----------- 8 files changed, 46 insertions(+), 46 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15ca61e..5777b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ##### Removed ##### Fixed - Schreibfehler in Service Readme [#313](https://github.com/Schrolli91/BOSWatch/issues/313) +- Einige Code-Style Verbesserungen [#310](https://github.com/Schrolli91/BOSWatch/pull/310) ##### Security diff --git a/includes/helper/stringConverter.py b/includes/helper/stringConverter.py index 01ada06..acd9a26 100644 --- a/includes/helper/stringConverter.py +++ b/includes/helper/stringConverter.py @@ -159,7 +159,6 @@ def convertToUTF8(inputString = ""): raise # End of exception UnicodeDecodeError: check given string is already UTF-8 - pass except: logging.warning("error checking given string") diff --git a/includes/pynma/pynma.py b/includes/pynma/pynma.py index 08a71cb..5649f05 100644 --- a/includes/pynma/pynma.py +++ b/includes/pynma/pynma.py @@ -3,14 +3,14 @@ from xml.dom.minidom import parseString try: - from http.client import HTTPSConnection + from http.client import HTTPSConnection except ImportError: - from httplib import HTTPSConnection + from httplib import HTTPSConnection try: - from urllib.parse import urlencode + from urllib.parse import urlencode except ImportError: - from urllib import urlencode + from urllib import urlencode __version__ = "1.0" @@ -55,10 +55,10 @@ takes 2 optional arguments: def delkey(self, key): "Removes a key (unregister ?)" - if type(key) == str: + if isinstance(key, str): if key in self._apikey: self._apikey.remove(key) - elif type(key) == list: + elif isinstance(key, list): for k in key: if key in self._apikey: self._apikey.remove(k) @@ -71,7 +71,7 @@ takes 2 optional arguments: def pushWithAPIKey(self, apikey=[], application="", event="", description="", url="", contenttype=None, priority=0, batch_mode=False, html=False): """Special Funktion""" if apikey: - if type(apikey) == str: + if isinstance(apikey, str): apikey = [apikey] self._apikey = uniq(apikey) return self.push(application, event, description, url, contenttype, priority, batch_mode, html) diff --git a/install.sh b/install.sh index 5c251ea..4b549a8 100644 --- a/install.sh +++ b/install.sh @@ -51,7 +51,7 @@ didBackup=false if [ -f $boswatchpath/BOSWatch/boswatch.py ]; then echo "Old installation found!" echo "A backup will be copied to $boswatchpath/old" - + mkdir /tmp/boswatch mv $boswatchpath/BOSWatch/* /tmp/boswatch/ didBackup=true @@ -61,7 +61,7 @@ fi if [ -f $boswatchpath/boswatch.py ]; then echo "Old installation found!" echo "A backup will be copied to $boswatchpath/old" - + mkdir /tmp/boswatch mv $boswatchpath/* /tmp/boswatch/ didBackup=true diff --git a/plugins/MySQL/MySQL.py b/plugins/MySQL/MySQL.py index 5941571..e9d3d7e 100644 --- a/plugins/MySQL/MySQL.py +++ b/plugins/MySQL/MySQL.py @@ -21,23 +21,23 @@ from includes import globalVars # Global variables from includes.helper import configHandler def isSignal(poc_id): - """ - @type poc_id: string - @param poc_id: POCSAG Ric + """ + @type poc_id: string + @param poc_id: POCSAG Ric - @requires: Configuration has to be set in the config.ini + @requires: Configuration has to be set in the config.ini - @return: True if the Ric is Signal, other False - @exception: none - """ - # If RIC is Signal return True, else False - if globalVars.config.get("POC", "netIdent_ric"): - if poc_id in globalVars.config.get("POC", "netIdent_ric"): - logging.info("RIC %s is net ident", poc_id) - return True - else: - logging.info("RIC %s is no net ident", poc_id) - return False + @return: True if the Ric is Signal, other False + @exception: none + """ + # If RIC is Signal return True, else False + if globalVars.config.get("POC", "netIdent_ric"): + if poc_id in globalVars.config.get("POC", "netIdent_ric"): + logging.info("RIC %s is net ident", poc_id) + return True + else: + logging.info("RIC %s is no net ident", poc_id) + return False ## @@ -87,7 +87,7 @@ def run(typ,freq,data): if configHandler.checkConfig("MySQL"): #read and debug the config try: - # + # # Connect to MySQL # logging.debug("connect to MySQL") diff --git a/plugins/Sms77/Sms77.py b/plugins/Sms77/Sms77.py index e4353d1..6d30a1a 100644 --- a/plugins/Sms77/Sms77.py +++ b/plugins/Sms77/Sms77.py @@ -58,7 +58,7 @@ def run(typ,freq,data): """ try: if configHandler.checkConfig("Sms77"): #read and debug the config - + # create an empty message an fill it with the required information message = "Alarm" if typ == "FMS": diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 744f621..56e35a6 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -71,8 +71,8 @@ def run(typ,freq,data): # Replace special characters in data Strings for URL # for key in data: - if isinstance(data[key], basestring): - data[key] = urllib.quote(data[key]) + if isinstance(data[key], basestring): + data[key] = urllib.quote(data[key]) # # Get URLs # diff --git a/plugins/notifyMyAndroid/notifyMyAndroid.py b/plugins/notifyMyAndroid/notifyMyAndroid.py index 7fa535f..a8ab127 100644 --- a/plugins/notifyMyAndroid/notifyMyAndroid.py +++ b/plugins/notifyMyAndroid/notifyMyAndroid.py @@ -268,23 +268,23 @@ def run(typ,freq,data): # nothing found pass # 3. lets look for ric prefixes in pocAPIKeyList - for prefixLength in reversed(range(6)): - ricPrefix = data['ric'][:prefixLength] - #fill the ric with stars - ricPrefix = ricPrefix.ljust(8,'*') - try: - xID = ricPrefix - # data structure: pocAPIKeyList[xID][i] = (xAPIKey, xPriority, xEventPrefix) - for i in range(len(pocAPIKeyList[xID])): - xEvent = event - (xAPIKey, xPriority, xEventPrefix) = pocAPIKeyList[xID][i] - if len(xEventPrefix) > 0: - xEvent = xEventPrefix + ": " + xEvent - response = nma.pushWithAPIKey(xAPIKey, application, xEvent, msg, priority=xPriority) - checkResponse(response, xAPIKey) - except KeyError: - # nothing found - pass + for prefixLength in reversed(range(6)): + ricPrefix = data['ric'][:prefixLength] + #fill the ric with stars + ricPrefix = ricPrefix.ljust(8,'*') + try: + xID = ricPrefix + # data structure: pocAPIKeyList[xID][i] = (xAPIKey, xPriority, xEventPrefix) + for i in range(len(pocAPIKeyList[xID])): + xEvent = event + (xAPIKey, xPriority, xEventPrefix) = pocAPIKeyList[xID][i] + if len(xEventPrefix) > 0: + xEvent = xEventPrefix + ": " + xEvent + response = nma.pushWithAPIKey(xAPIKey, application, xEvent, msg, priority=xPriority) + checkResponse(response, xAPIKey) + except KeyError: + # nothing found + pass # end if "POC" in typ # end if usecsv == True