Skip to content

Commit

Permalink
manuelle pep8 Anpassungen
Browse files Browse the repository at this point in the history
  • Loading branch information
motom001 committed Feb 24, 2022
1 parent acd3796 commit f0cc45b
Show file tree
Hide file tree
Showing 26 changed files with 102 additions and 122 deletions.
3 changes: 1 addition & 2 deletions doorpi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""provide intercomstation to the doorstation by VoIP"""

from .doorpi import metadata, DoorPi

from .doorpi import DoorPi, metadata # noqa F401

__version__ = metadata.version
__author__ = metadata.authors[0]
Expand Down
4 changes: 1 addition & 3 deletions doorpi/action/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ def register_action(self, event_name, action_object, *args, **kwargs):
logger.error('action_object is None')
return False

single_fire = kwargs['single_fire_action'] is True
if ('single_fire_action' in list(kwargs.keys()) and single_fire):

if ('single_fire_action' in list(kwargs.keys()) and kwargs['single_fire_action'] is True):
action_object.single_fire_action = True
del kwargs['single_fire_action']

Expand Down
2 changes: 1 addition & 1 deletion doorpi/conf/config_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def find_config(configfile=None):
open(possible_default_file, 'r').close()
return possible_default_file
except Exception as exp:
logger.debug(possible_default_file+' failed with '+exp)
logger.debug(possible_default_file+' failed with %s' % exp)

return None

Expand Down
18 changes: 8 additions & 10 deletions doorpi/doorpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class DoorPi(object, metaclass=Singleton):
__prepared = False
__config = None

@property
def meta(self): return metadata

@property
def config(self): return self.__config

Expand Down Expand Up @@ -92,8 +95,7 @@ def epilog(self): return metadata.epilog
def name(self): return str(metadata.package)

@property
def name_and_version(self): return str(
metadata.package) + ' - version: ' + metadata.version
def name_and_version(self): return str(metadata.package) + ' - version: ' + metadata.version

__shutdown = False

Expand All @@ -106,10 +108,8 @@ def shutdown(self): return self.__shutdown
def base_path(self):
if self._base_path is None:
try:
self._base_path = os.path.join(
os.path.expanduser('~'), metadata.package)
assert os.access(
self._base_path, os.W_OK), 'use fallback for base_path (see tmp path)'
self._base_path = os.path.join(os.path.expanduser('~'), metadata.package)
assert os.access(self._base_path, os.W_OK), 'use fallback for base_path (see tmp path)'
except Exception as exp:
logger.error(exp)
import tempfile
Expand Down Expand Up @@ -152,14 +152,12 @@ def prepare(self, parsed_arguments):
self.__event_handler = EventHandler()

if self.config.config_file is None:
self.event_handler.register_action(
'AfterStartup', self.config.save_config)
self.event_handler.register_action('AfterStartup', self.config.save_config)
self.config.get('EVENT_OnStartup', '10', 'sleep:1')

if 'test' in parsed_arguments and parsed_arguments.test is True:
logger.warning('using only test-mode and destroy after 5 seconds')
self.event_handler.register_action(
'AfterStartup', DoorPiShutdownAction(self.doorpi_shutdown))
self.event_handler.register_action('AfterStartup', DoorPiShutdownAction(self.doorpi_shutdown))

# register own events
self.event_handler.register_event('BeforeStartup', __name__)
Expand Down
6 changes: 3 additions & 3 deletions doorpi/keyboard/KeyboardInterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@ def __init__(self, config_keyboards):
)
self.__OutputMappingTable[output_pin_name] = keyboard_name

if len(self.__keyboards) is 0:
if len(self.__keyboards) == 0:
logger.error('No Keyboards loaded - load dummy!')
self.__keyboards['dummy'] = load_single_keyboard('dummy')

def destroy(self):
try:
for Keyboard in self.__keyboards:
self.__keyboards[Keyboard].destroy()
except:
pass
except Exception as exp:
logger.info(exp)

def set_output(self, pin, value, log_output=True):
if pin not in self.__OutputMappingTable:
Expand Down
5 changes: 2 additions & 3 deletions doorpi/keyboard/from_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL

import os
import ntpath
from watchdog.observers import Observer
from watchdog.events import FileModifiedEvent, FileSystemEventHandler

Expand All @@ -12,8 +11,8 @@


def path_leaf(path):
head, tail = ntpath.split(path)
return tail or ntpath.basename(head)
head, tail = os.path.split(path)
return tail or os.path.basename(head)


class MissingMandatoryParameter(Exception):
Expand Down
4 changes: 2 additions & 2 deletions doorpi/keyboard/from_gpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def event_detect(self, pin):
self._fire_OnKeyPressed(pin, __name__)

def status_input(self, pin):
if self._polarity is 0:
if self._polarity == 0:
return str(RPiGPIO.input(int(pin))).lower() in HIGH_LEVEL
else:
return str(RPiGPIO.input(int(pin))).lower() in LOW_LEVEL
Expand All @@ -117,7 +117,7 @@ def set_output(self, pin, value, log_output=True):

pin = int(pin)
value = str(value).lower() in HIGH_LEVEL
if self._polarity is 1:
if self._polarity == 1:
value = not value
log_output = str(log_output).lower() in HIGH_LEVEL

Expand Down
4 changes: 2 additions & 2 deletions doorpi/keyboard/from_piface.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def event_detect(self, event):
self._fire_OnKeyPressed(event.pin_num, __name__)

def status_input(self, pin):
if self._polarity is 0:
if self._polarity == 0:
return str(p.digital_read(int(pin))).lower() in HIGH_LEVEL
else:
return str(p.digital_read(int(pin))).lower() in LOW_LEVEL
Expand All @@ -86,7 +86,7 @@ def set_output(self, pin, value, log_output=True):

pin = int(pin)
value = str(value).lower() in HIGH_LEVEL
if self._polarity is 1:
if self._polarity == 1:
value = not value
log_output = str(log_output).lower() in HIGH_LEVEL

Expand Down
2 changes: 1 addition & 1 deletion doorpi/keyboard/from_pn532.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
# copy source-dir to pythons libdir:
# sudo cp -r nfc /usr/local/lib/python2.7/dist-packages/nfc
# /TODO
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass
import doorpi

import threading
Expand Down
2 changes: 1 addition & 1 deletion doorpi/keyboard/from_rdm6300.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
#
# RFID data: http://kampis-elektroecke.de/?page_id=3248
import doorpi
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass

import threading
import serial
Expand Down
3 changes: 1 addition & 2 deletions doorpi/keyboard/from_usb_plain.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass
import doorpi

import threading
import serial
import time
from os import linesep as OS_LINESEP

import logging
Expand Down
35 changes: 17 additions & 18 deletions doorpi/keyboard/from_wiegand.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass, HIGH_LEVEL, LOW_LEVEL
from doorpi.keyboard.AbstractBaseClass import KeyboardAbstractBaseClass
import doorpi

import RPi.GPIO as RPiGPIO
Expand Down Expand Up @@ -26,12 +26,9 @@ def __init__(self, input_pins, output_pins, keyboard_name, conf_pre, conf_post,

# read config file
section_name = conf_pre + 'keyboard' + conf_post
self._data0 = doorpi.DoorPi().config.get(
section_name, 'data0') # w0 - data signal
self._data1 = doorpi.DoorPi().config.get(
section_name, 'data1') # w1 - data signal
self._timeout = doorpi.DoorPi().config.get(section_name, 'timeout',
0.25) # time for reading data signal
self._data0 = doorpi.DoorPi().config.get(section_name, 'data0') # w0 - data signal
self._data1 = doorpi.DoorPi().config.get(section_name, 'data1') # w1 - data signal
self._timeout = doorpi.DoorPi().config.get(section_name, 'timeout', 0.25) # time for reading data signal

# init vars
self._nextInput = '' # stores input until timeout
Expand Down Expand Up @@ -122,44 +119,46 @@ def _processData(self):
# reset input signal
self._nextInput = ''

def _verifyParity(evenParity, oddParity):
@staticmethod
def verifyParity(evenParity, oddParity):
bitsEven = evenParity.count('1')
bitsOdd = oddParity.count('1')
return (bitsEven % 2 == 0) and (bitsOdd % 2 == 1)

def _verify37Bit(input):
# even parity (start: 0, length: 19)
# odd parity (start: 18, length: 19)
return _verifyParity(input[0:19], input[18:])
return Wiegand.verifyParity(input[0:19], input[18:])

def _verify34Bit(input):
# even parity (start 0, length: 17)
# odd parity (start: 17, length: 17)
return _verifyParity(input[0:17], input[17:])
return Wiegand.verifyParity(input[0:17], input[17:])

def _verify26Bit(input):
# even parity (start: 0, length: 13)
# odd parity (start: 13, length: 13)
return _verifyParity(input[0:13], input[13:])
return Wiegand.verifyParity(input[0:13], input[13:])

def _verify8Bit(input):
# first 4bits equal reverse last 4 bits
return (int(input[0:4], 2) == ~int(input[4:], 2))

def _removeParityBits(input):
@staticmethod
def removeParityBits(input):
# remove parity bits
input = input[1:-1]
# dual to decimal
return int(input, 2)

def _interpret8Bit(input):
# IIIICCCC signal format (I = inverse)
value = int(intput, 2) & 0x0F
value = int(input, 2) & 0x0F
return {'fc': -1, 'value': value}

def _interpret26Bit(input):
# PFFFFFFFFCCCCCCCCCCCCCCCCP signal format
temp = _removeParityBits(input)
temp = Wiegand.removeParityBits(input)
# mask: 000000001111111111111111
cardNumber = temp & 0x00FFFF
# mask: 111111110000000000000000
Expand All @@ -172,14 +171,14 @@ def _interpret32Bit(input):

def _interpret34Bit(input):
# PFFFFFFFFFFFFFFFFCCCCCCCCCCCCCCCCP signal format
temp = _removeParityBits(input)
temp = Wiegand.removeParityBits(input)
cardNumber = temp & 0x000FFFF
facilityCode = (temp & 0x7FFF80000) >> 16
return {'fc': facilityCode, 'value': cardNumber}

def _interpret37Bit(input):
# PFFFFFFFFFFFFFFFFCCCCCCCCCCCCCCCCCCCP signal format
temp = _removeParityBits(input)
temp = Wiegand.removeParityBits(input)
cardNumber = temp & 0x0007FFFF
facilityCode = (temp & 0x7FFF80000) >> 19
return {'fc': facilityCode, 'value': cardNumber}
Expand All @@ -189,8 +188,8 @@ def destroy(self):
return

self._shutdown = True
GPIO.remove_event_detect(self._data0)
GPIO.remove_event_detect(self._data1)
RPiGPIO.remove_event_detect(self._data0)
RPiGPIO.remove_event_detect(self._data1)
doorpi.DoorPi().event_handler.unregister_source(__name__, True)
self.__destroyed = True

Expand Down
1 change: 1 addition & 0 deletions doorpi/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
url = 'https://github.com/motom001/DoorPi'
url_raw = 'https://raw.githubusercontent.com/motom001/DoorPi'

# flake8: noqa W605
# created with: http://patorjk.com/software/taag/#p=display&f=Ogre&t=DoorPi
epilog = '''
___ ___ _
Expand Down
70 changes: 34 additions & 36 deletions doorpi/sipphone/AbstractBaseClass.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,65 +31,63 @@ def video_devices(self): return []
@property
def current_call_dump(self): return {}

def __init__(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def __init__(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def config(self, **kwargs): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def config(self, **kwargs):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def start(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def start(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def stop(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def stop(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def destroy(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def destroy(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def call(self, number): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def call(self, number):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def hangup(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def is_admin_number(self, number): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def hangup(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def is_admin_number(self, number):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def __del__(self): self.destroy()


class RecorderAbstractBaseClass(object):

def __init__(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def __init__(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def config(self, **kwargs):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def config(self, **kwargs): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def start(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def start(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def stop(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def stop(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def destroy(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def destroy(self):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def __del__(self): self.destroy()


class PlayerAbstractBaseClass(object):

def __init__(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def __init__(self): raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def config(self, **kwargs): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def config(self, **kwargs):
raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def start(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def start(self): raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def stop(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def destroy(self): raise NotImplementedError(
"Subclass %s should implement this!" % self.__class__.__name__)
def stop(self): raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)
def destroy(self): raise NotImplementedError("Subclass %s should implement this!" % self.__class__.__name__)

def __del__(self): self.destroy()
Loading

0 comments on commit f0cc45b

Please sign in to comment.