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 import etree
|
||||||
from lxml.builder import ElementMaker
|
from lxml.builder import ElementMaker
|
||||||
import requests
|
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(",")
|
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():
|
class DoorController():
|
||||||
def __init__(self, ip, username, password, name="", access=""):
|
def __init__(self, ip, username, password, name="", access=""):
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
@ -30,9 +34,7 @@ class DoorController():
|
|||||||
xml = etree.XML(r.content)
|
xml = etree.XML(r.content)
|
||||||
if r.status_code != 200 \
|
if r.status_code != 200 \
|
||||||
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0:
|
or len(xml.findall("{http://www.hidglobal.com/VertX}Error")) > 0:
|
||||||
print("Door Updating Error: ", r.status_code, r.reason)
|
raise RemoteError(r)
|
||||||
print(r.text)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def doCSVImport(self, csv):
|
def doCSVImport(self, csv):
|
||||||
"""Do the CSV import procedure on a door control"""
|
"""Do the CSV import procedure on a door control"""
|
||||||
@ -52,9 +54,7 @@ class DoorController():
|
|||||||
# probably meed to be more sane about this
|
# probably meed to be more sane about this
|
||||||
if r.status_code != 200 \
|
if r.status_code != 200 \
|
||||||
or len(resp_xml.findall("{*}Error")) > 0:
|
or len(resp_xml.findall("{*}Error")) > 0:
|
||||||
print("Door Updating Error: ", r.status_code, r.reason)
|
raise RemoteError(r)
|
||||||
print(r.text)
|
|
||||||
sys.exit(1)
|
|
||||||
return resp_xml
|
return resp_xml
|
||||||
|
|
||||||
def sendSchedules(self):
|
def sendSchedules(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user