telnet for neutrino

This commit is contained in:
Dmitriy Yefremov
2018-01-07 16:33:18 +03:00
parent 0f02055c0c
commit a3cf34ba2a
4 changed files with 34 additions and 12 deletions

View File

@@ -90,3 +90,7 @@ def write_bouquet(file, bouquet):
bq_elem.appendChild(srv_elem)
doc.writexml(open(file, "w"), addindent=" ", newl="\n", encoding="UTF-8")
if __name__ == "__main__":
pass

View File

@@ -5,6 +5,9 @@ from enum import Enum
from ftplib import FTP
from telnetlib import Telnet
from app.commons import log
from app.properties import Profile
__DATA_FILES_LIST = ("tv", "radio", "lamedb", "blacklist", "whitelist", # enigma 2
"services.xml", "myservices.xml", "bouquets.xml", "ubouquets.xml") # neutrino
@@ -46,13 +49,14 @@ def download_data(*, properties, download_type=DownloadDataType.ALL):
ftp.retrbinary("RETR " + xml_file, f.write)
def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused=False):
def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused=False, profile=Profile.ENIGMA_2):
data_path = properties["data_dir_path"]
host = properties["host"]
# telnet
tn = telnet(host=host)
tn = telnet(host=host, user=None if profile is Profile.ENIGMA_2 else "root", password=None,
timeout=5 if profile is Profile.ENIGMA_2 else 1)
next(tn)
# terminate enigma
# terminate enigma or enigma
tn.send("init 4")
with FTP(host=host) as ftp:
@@ -80,8 +84,8 @@ def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused
if file_name == "satellites.xml":
continue
file_name, send_file(file_name, data_path, ftp)
# resume enigma
tn.send("init 3")
# resume enigma or restart neutrino
tn.send("init 3" if profile is Profile.ENIGMA_2 else "init 6")
def send_file(file_name, path, ftp):
@@ -90,14 +94,22 @@ def send_file(file_name, path, ftp):
return ftp.storbinary("STOR " + file_name, f)
def telnet(host, port=23, user="root", password="root", timeout=5):
def telnet(host, port=23, user=None, password=None, timeout=5):
try:
tn = Telnet(host=host, port=port, timeout=timeout)
except socket.timeout:
print("socket timeout")
log("telnet error: socket timeout")
else:
time.sleep(1)
command = yield
if user is not None:
tn.read_until(b"login: ")
tn.write(user.encode("utf-8") + b"\n")
time.sleep(timeout)
if password is not None:
tn.read_until(b"Password: ")
tn.write(password.encode("utf-8") + b"\n")
time.sleep(timeout)
tn.write("{}\r\n".format(command).encode("utf-8"))
time.sleep(timeout)
command = yield

View File

@@ -1,19 +1,21 @@
from app.commons import run_idle, run_task
from app.ftp import download_data, DownloadDataType, upload_data
from app.properties import Profile
from . import Gtk, UI_RESOURCES_PATH
from .dialogs import show_dialog, DialogType
def show_download_dialog(transient, options, open_data):
dialog = DownloadDialog(transient, options, open_data)
def show_download_dialog(transient, options, open_data, profile=Profile.ENIGMA_2):
dialog = DownloadDialog(transient, options, open_data, profile)
dialog.run()
dialog.destroy()
class DownloadDialog:
def __init__(self, transient, properties, open_data):
def __init__(self, transient, properties, open_data, profile):
self._properties = properties
self._open_data = open_data
self._profile = profile
handlers = {"on_receive": self.on_receive,
"on_send": self.on_send,
@@ -72,7 +74,8 @@ class DownloadDialog:
self.show_info_message("Please, wait...", Gtk.MessageType.INFO)
upload_data(properties=self._properties,
download_type=d_type,
remove_unused=self._remove_unused_check_button.get_active())
remove_unused=self._remove_unused_check_button.get_active(),
profile=self._profile)
except Exception as e:
message = str(getattr(e, "message", str(e)))
self.show_info_message(message, Gtk.MessageType.ERROR)

View File

@@ -655,7 +655,10 @@ class MainAppWindow:
pass
def on_download(self, item):
show_download_dialog(self.__main_window, self.__options.get(self.__profile), self.open_data)
show_download_dialog(transient=self.__main_window,
options=self.__options.get(self.__profile),
open_data=self.open_data,
profile=Profile(self.__profile))
@run_idle
def on_view_focus(self, view, focus_event):