added logging conf and now checking recording status with simple script ; notifications are missing

This commit is contained in:
Tobias Kurze
2019-11-13 08:19:39 +01:00
parent 4563e16137
commit 872e531ef5
7 changed files with 436 additions and 265 deletions

View File

@@ -19,7 +19,10 @@ PW = "lrgrashof+-"
class EpiphanV1(RecorderAdapter):
def __init__(self, admin_user: str, admin_pw: str):
def __init__(self, url: str, admin_user: str, admin_pw: str):
if not url.startswith('http'):
url = 'http://' + url
self.url = url
self.user = admin_user
self.password = admin_pw
self.session = requests.Session()
@@ -32,13 +35,13 @@ class EpiphanV1(RecorderAdapter):
pass
def get_status(self) -> dict:
res = self.session.get(BASE_URL + "/admin/ajax/recorder_status.cgi")
res = self.session.get(self.url + "/admin/ajax/recorder_status.cgi")
if res.ok:
return res.json()
raise LrcException(res.text, res.status_code)
def get_sysinfo(self) -> dict:
res = self.session.get(BASE_URL + "/ajax/sysinfo.cgi")
res = self.session.get(self.url + "/ajax/sysinfo.cgi")
if res.ok:
return res.json()
raise LrcException(res.text, res.status_code)
@@ -55,13 +58,13 @@ class EpiphanV1(RecorderAdapter):
return self.get_status().get('seconds', None)
def start_recording(self):
res = self.session.get(BASE_URL + "/admin/ajax/start_recorder.cgi")
res = self.session.get(self.url + "/admin/ajax/start_recorder.cgi")
if not res.ok:
raise LrcException(res.text, res.status_code)
time.sleep(2) # just a little bit of waiting time -> it takes a bit for the Epiphan to update its state
def stop_recording(self):
res = self.session.get(BASE_URL + "/admin/ajax/stop_recorder.cgi")
res = self.session.get(self.url + "/admin/ajax/stop_recorder.cgi")
if not res.ok:
raise LrcException(res.text, res.status_code)
time.sleep(4) # just a little bit of waiting time -> it takes a bit for the Epiphan to update its state
@@ -106,7 +109,7 @@ class EpiphanV1(RecorderAdapter):
raise LrcException(str(err))
def get_screenshot(self):
ret = self.session.get(BASE_URL + "/admin/grab_frame.cgi?size=256x192&device=DAV93133.vga&_t=1573471990578",
ret = self.session.get(self.url + "/admin/grab_frame.cgi?size=256x192&device=DAV93133.vga&_t=1573471990578",
stream=True)
print(ret)
@@ -117,7 +120,7 @@ class EpiphanV1(RecorderAdapter):
if __name__ == '__main__':
e = EpiphanV1(USER, PW)
e = EpiphanV1(BASE_URL, USER, PW)
try:
# print(e.is_recording())
"""

View File

@@ -1,5 +1,10 @@
import logging
from backend import LrcException
from backend.recorder_adapters import telnetlib, TelnetAdapter, RecorderAdapter
logger = logging.getLogger()
RECORDER_MODEL_NAME = "SMP 351 / 352"
VERSION = "0.9.0"
REQUIRES_USER = False
@@ -16,26 +21,34 @@ PW = "123mzsmp"
class SMP(TelnetAdapter, RecorderAdapter):
def __init__(self, address, password, **kwargs):
def __init__(self, address, password, auto_login=True, **kwargs):
super().__init__(address)
self.admin_pw = password
if auto_login:
self._login()
def _login(self):
self.tn = telnetlib.Telnet(HOST)
print("Connecting to {} ...".format(self.address))
try:
self.tn = telnetlib.Telnet(self.address)
except TimeoutError as e:
raise LrcException(str(e))
self.tn.read_until("\r\nPassword:")
# password = getpass.getpass()
password = self.admin_pw
self.tn.write(password + "\n\r")
out = self.tn.assert_string_in_output("Login Administrator")
print(out)
if not out[0]:
print(out[1])
if "Password:" in out[1]:
# TODO: loop until logged in...
print("re-enter pw")
self.tn.write("123mzsmp\n\r")
self.tn.write(self.admin_pw+"\n\r")
print(self.tn.assert_string_in_output("Login Administrator"))
print("WRONG (admin) password!! Exiting!")
print(self.admin_pw)
self.tn = None
raise Exception("Could not login as administrator with given pw!")
print("OK, we have admin rights!")
@@ -369,6 +382,9 @@ class SMP(TelnetAdapter, RecorderAdapter):
self.tn.write("{}YRCDR\n".format(self.esc_char))
return TelnetAdapter._get_response_str(self.tn.read_until_non_empty_line())
def is_recording(self):
return self.get_recording_status() == 1
def extent_recording_time(self, extension_time: int):
"""
Extends a scheduled recording by extension_time minutes
@@ -764,7 +780,7 @@ class SMP(TelnetAdapter, RecorderAdapter):
def main():
smp = SMP(HOST, PW)
smp = SMP(HOST, PW, False)
print(smp)
smp._login()
print(smp.get_version(verbose_info=False))