forked from CMS/memberPlumbing
DoorController: Use an exception instead of sys.exit
This commit is contained in:
parent
3e474f1b79
commit
ee4898eaf3
@ -1,4 +1,3 @@
|
||||
import sys
|
||||
from lxml import etree
|
||||
from lxml.builder import ElementMaker
|
||||
import requests
|
||||
@ -10,6 +9,11 @@ ROOT = E_plain.VertXMessage
|
||||
|
||||
fieldnames = "CardNumber,CardFormat,PinRequired,PinCode,ExtendedAccess,ExpiryDate,Forename,Initial,Surname,Email,Phone,Custom1,Custom2,Schedule1,Schedule2,Schedule3,Schedule4,Schedule5,Schedule6,Schedule7,Schedule8".split(",")
|
||||
|
||||
class RemoteError(Exception):
|
||||
def __init__(self, r):
|
||||
super().__init__(
|
||||
f"Door Updating Error: {r.status_code} {r.reason}\n{r.text}")
|
||||
|
||||
class DoorController():
|
||||
def __init__(self, ip, username, password, name="", access=""):
|
||||
self.ip = ip
|
||||
@ -30,9 +34,7 @@ class DoorController():
|
||||
xml = etree.XML(r.content)
|
||||
if r.status_code != 200 \
|
||||
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0:
|
||||
print("Door Updating Error: ", r.status_code, r.reason)
|
||||
print(r.text)
|
||||
sys.exit(1)
|
||||
raise RemoteError(r)
|
||||
|
||||
def doCSVImport(self, csv):
|
||||
"""Do the CSV import procedure on a door control"""
|
||||
@ -52,9 +54,7 @@ class DoorController():
|
||||
# probably meed to be more sane about this
|
||||
if r.status_code != 200 \
|
||||
or len(resp_xml.findall("{*}Error")) > 0:
|
||||
print("Door Updating Error: ", r.status_code, r.reason)
|
||||
print(r.text)
|
||||
sys.exit(1)
|
||||
raise RemoteError(r)
|
||||
return resp_xml
|
||||
|
||||
def sendSchedules(self):
|
||||
|
Loading…
Reference in New Issue
Block a user