diff --git a/main/ftp.py b/main/ftp.py index d9d50a8c..bfa0f248 100644 --- a/main/ftp.py +++ b/main/ftp.py @@ -1,41 +1,52 @@ +from enum import Enum from ftplib import FTP import os + __DATA_FILES_LIST = ("tv", "radio", "lamedb") -def download_data(*, properties): +class DownloadDataType(Enum): + ALL = 0 + BOUQUETS = 1 + SATELLITES = 2 + + +def download_data(*, properties, download_type=DownloadDataType.ALL): with FTP(properties["host"]) as ftp: + print(download_type) ftp.login(user=properties["user"], passwd=properties["password"]) save_path = properties["data_dir_path"] - # bouquets section - ftp.cwd(properties["services_path"]) files = [] - ftp.dir(files.append) + # bouquets section + if download_type is DownloadDataType.ALL or download_type is DownloadDataType.BOUQUETS: + ftp.cwd(properties["services_path"]) + ftp.dir(files.append) - for file in files: - name = str(file).strip() - if name.endswith(__DATA_FILES_LIST): - name = name.split()[-1] - with open(save_path + name, 'wb') as f: - ftp.retrbinary('RETR ' + name, f.write) + for file in files: + name = str(file).strip() + if name.endswith(__DATA_FILES_LIST): + name = name.split()[-1] + with open(save_path + name, 'wb') as f: + ftp.retrbinary('RETR ' + name, f.write) # satellites.xml section - ftp.cwd(properties["satellites_xml_path"]) - files.clear() - ftp.dir(files.append) + if download_type is DownloadDataType.ALL or download_type is DownloadDataType.SATELLITES: + ftp.cwd(properties["satellites_xml_path"]) + files.clear() + ftp.dir(files.append) - for file in files: - name = str(file).strip() - xml_file = "satellites.xml" - if name.endswith(xml_file): - with open(save_path + xml_file, 'wb') as f: - ftp.retrbinary('RETR ' + xml_file, f.write) + for file in files: + name = str(file).strip() + xml_file = "satellites.xml" + if name.endswith(xml_file): + with open(save_path + xml_file, 'wb') as f: + ftp.retrbinary('RETR ' + xml_file, f.write) return ftp.voidcmd("NOOP") -def upload_data(*, properties): +def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused=False): load_path = properties["data_dir_path"] for file_name in os.listdir(load_path): diff --git a/main/ui/dialogs.glade b/main/ui/dialogs.glade index 1d061648..5cc94f05 100644 --- a/main/ui/dialogs.glade +++ b/main/ui/dialogs.glade @@ -43,6 +43,348 @@ dmitry.v.yefremov@gmail.com + + 320 + False + FTP-transfer + False + True + 320 + True + mail-send-receive + dialog + + + 320 + False + vertical + 2 + + + False + end + + + gtk-undo + True + True + True + True + + + True + True + 0 + + + + + False + False + 0 + + + + + True + False + vertical + 1 + + + True + False + Receive + 1 + + + True + False + Receiver IP: + 0 + + + 0 + 0 + + + + + True + True + False + 10 + 127.0.0.1 + False + + + 0 + 1 + + + + + True + False + Current data path: + 0 + + + 1 + 0 + + + + + True + True + False + data/ + False + + + 1 + 1 + + + + + False + True + 0 + + + + + True + False + 5 + + + True + False + Data: + 0 + + + False + True + 0 + + + + + All + True + True + False + 0 + True + True + satellites_radio_button + + + False + True + 1 + + + + + Bouquets + True + True + False + 0 + True + True + satellites_radio_button + + + False + True + 2 + + + + + Satellites + True + True + False + 0 + True + True + all_radio_button + + + False + True + 3 + + + + + False + True + 1 + + + + + True + False + + + True + False + Receive files from receiver + True + Receive + gtk-goto-bottom + + + + True + True + + + + + True + False + Send files to receiver + True + Send + True + gtk-goto-top + + + + True + True + + + + + + False + True + 2 + + + + + True + False + + + Remove unused bouquets + True + True + False + 0 + True + True + + + False + True + 0 + + + + + + + + False + True + 3 + + + + + True + False + + + False + True + 4 + + + + + True + False + True + + + + False + expand + + + + + + False + False + 0 + + + + + False + 16 + + + + + + True + False + Info + + + False + True + 1 + + + + + + + + False + False + 0 + + + + + False + True + 5 + + + + + False + True + 1 + + + + + + cancel_download_dialog_button + + 320 False @@ -319,6 +661,7 @@ dmitry.v.yefremov@gmail.com True False + 1 True diff --git a/main/ui/download_dialog.py b/main/ui/download_dialog.py new file mode 100644 index 00000000..d3639b3c --- /dev/null +++ b/main/ui/download_dialog.py @@ -0,0 +1,80 @@ +from main.commons import run_task +from main.ftp import download_data, upload_data, DownloadDataType +from . import Gtk + + +def show_download_dialog(transient, options, open_data): + dialog = DownloadDialog(transient, options, open_data) + dialog.run() + dialog.destroy() + + +class DownloadDialog: + def __init__(self, transient, properties, open_data): + self._properties = properties + self._open_data = open_data + + handlers = {"on_receive": self.on_receive, + "on_send": self.on_send, + "on_info_bar_close": self.on_info_bar_close} + + builder = Gtk.Builder() + builder.add_objects_from_file("./ui/dialogs.glade", ("download_dialog",)) + builder.connect_signals(handlers) + + self._dialog = builder.get_object("download_dialog") + self._dialog.set_transient_for(transient) + self._info_bar = builder.get_object("info_bar") + self._message_label = builder.get_object("info_bar_message_label") + self._host_entry = builder.get_object("host_entry").set_text(properties["host"]) + self._data_path_entry = builder.get_object("data_path_entry").set_text(properties["data_dir_path"]) + self._remove_unused_check_button = builder.get_object("remove_unused_check_button") + self._all_radio_button = builder.get_object("all_radio_button") + self._bouquets_radio_button = builder.get_object("bouquets_radio_button") + self._satellites_radio_button = builder.get_object("satellites_radio_button") + # self._dialog.get_content_area().set_border_width(0) + + @run_task + def on_receive(self, item): + self.download(True, d_type=self.get_download_type()) + + def on_send(self, item): + self.download(d_type=self.get_download_type()) + + def get_download_type(self): + download_type = DownloadDataType.ALL + if self._bouquets_radio_button.get_active(): + download_type = DownloadDataType.BOUQUETS + elif self._satellites_radio_button.get_active(): + download_type = DownloadDataType.SATELLITES + return download_type + + def run(self): + return self._dialog.run() + + def destroy(self): + self._dialog.destroy() + + def on_info_bar_close(self, *args): + self._info_bar.set_visible(False) + + def download(self, download=False, d_type=DownloadDataType.ALL): + """ Download/upload data from/to receiver """ + try: + self._info_bar.set_visible(True) + if download: + download_data(properties=self._properties, download_type=d_type) + else: + upload_data(properties=self._properties, download_type=d_type) + except Exception as e: + self._info_bar.set_message_type(Gtk.MessageType.ERROR) + self._message_label.set_text(getattr(e, "message", repr(e))) # Or maybe so: getattr(e, 'message', str(e)) + else: + self._info_bar.set_message_type(Gtk.MessageType.INFO) + self._message_label.set_text("OK") + if download and d_type is not DownloadDataType.SATELLITES: + self._open_data() + + +if __name__ == "__main__": + pass diff --git a/main/ui/main_app_window.py b/main/ui/main_app_window.py index 6cae8f89..77bec8f0 100644 --- a/main/ui/main_app_window.py +++ b/main/ui/main_app_window.py @@ -2,9 +2,9 @@ from contextlib import suppress from main.commons import run_task from main.eparser import get_channels, get_bouquets, write_bouquets, write_channels, Bouquets, Bouquet, Channel -from main.ftp import download_data, upload_data from main.properties import get_config, write_config from . import Gtk, Gdk +from .download_dialog import show_download_dialog from .satellites_dialog import show_satellites_dialog from .settings_dialog import show_settings_dialog @@ -47,7 +47,6 @@ def get_handlers(): "on_about_app": on_about_app, "on_preferences": on_preferences, "on_download": on_download, - "on_upload": on_upload, "on_data_open": on_data_open, "on_data_save": on_data_save, "on_tree_view_key_release": on_tree_view_key_release, @@ -95,11 +94,12 @@ def move_items(key): """ Move items in fav tree view """ selection = __fav_view.get_selection() model, paths = selection.get_selected_rows() - # for correct down move! - if key in (Gdk.KEY_Down, Gdk.KEY_Page_Down, Gdk.KEY_KP_Page_Down): - paths = reversed(paths) if paths: + # for correct down move! + if key in (Gdk.KEY_Down, Gdk.KEY_Page_Down, Gdk.KEY_KP_Page_Down): + paths = reversed(paths) + for path in paths: itr = model.get_iter(path) if key == Gdk.KEY_Down: @@ -548,19 +548,9 @@ def on_tree_view_key_release(view: Gtk.TreeView, event): pass -@run_task -def on_upload(item): - connect(__options, False) - - @run_task def on_download(item): - connect(__options) - open_data() - - -def on_reload(item): - pass + show_download_dialog(__main_window, __options, open_data) @run_task @@ -591,15 +581,6 @@ def on_view_focus(view, focus_event): __tool_elements[elem].set_sensitive(not empty) -def connect(properties, download=True): - try: - res = download_data(properties=properties) if download else upload_data(properties=properties) - __status_bar.push(1, res) - except Exception as e: - __status_bar.remove_all(1) - __status_bar.push(1, getattr(e, "message", repr(e))) # Or maybe so: getattr(e, 'message', str(e)) - - def init_ui(): builder = Gtk.Builder() builder.add_from_file("ui/main_window.glade") diff --git a/main/ui/main_window.glade b/main/ui/main_window.glade index ab446224..1650d7cf 100644 --- a/main/ui/main_window.glade +++ b/main/ui/main_window.glade @@ -401,7 +401,7 @@ Download data from receiver Download True - gtk-goto-bottom + mail-send-receive @@ -409,20 +409,6 @@ True - - - True - False - Upload data into receiver - True - gtk-goto-top - - - - False - True - - True @@ -550,7 +536,7 @@ Paste True gtk-paste - + False @@ -716,268 +702,292 @@ 2 True - + True - True - in + False + vertical - + + True + False + Services + + + False + True + 0 + + + + True True - services_list_store - 2 - True - both - True - - - - - - - - multiple - - + in - - False - autosize - CAS - - - - 0 - - - - - - - False - autosize - Type - - - - 1 - - - - - - - True - autosize - Service - True - True - 2 - - - - 2 - - - - - - - True - autosize - Package - True - True - 3 - - - - 3 - - - - - - - True - Type - True - True - 4 - - - 0.51999998092651367 + + True + True + services_list_store + 2 + True + both + True + + + + + + + + multiple - - 4 - - - - - - True - autosize - Ssid - True - True - 5 - - 0.50999999046325684 + + False + autosize + CAS + + + + 0 + + - - 5 - - - - - - True - autosize - Freq - True - True - 6 - - 0.50999999046325684 + + False + autosize + Type + + + + 1 + + - - 6 - - - - - - True - autosize - Rate - True - True - 7 - - 0.50999999046325684 + + True + autosize + Service + True + True + 2 + + + + 2 + + - - 7 - - - - - - True - autosize - Pol - True - True - 8 - - 0.50999999046325684 + + True + autosize + Package + True + True + 3 + + + + 3 + + - - 8 - - - - - - True - autosize - FEC - True - True - 9 - - 0.50999999046325684 + + True + Type + True + True + 4 + + + 0.51999998092651367 + + + 4 + + - - 9 - - - - - - True - autosize - System - True - True - 10 - - 0.50999999046325684 + + True + autosize + Ssid + True + True + 5 + + + 0.50999999046325684 + + + 5 + + - - 10 - - - - - - True - Pos - True - 11 - - 0.50999999046325684 + + True + autosize + Freq + True + True + 6 + + + 0.50999999046325684 + + + 6 + + - - 11 - - - - - - False - autosize - data_id - - - 12 - + + True + autosize + Rate + True + True + 7 + + + 0.50999999046325684 + + + 7 + + + - - - - - False - autosize - fav_id - - - 13 - + + True + autosize + Pol + True + True + 8 + + + 0.50999999046325684 + + + 8 + + + - - - - - False - autosize - transponder - - - 14 - + + True + autosize + FEC + True + True + 9 + + + 0.50999999046325684 + + + 9 + + + + + + + True + autosize + System + True + True + 10 + + + 0.50999999046325684 + + + 10 + + + + + + + True + Pos + True + 11 + + + 0.50999999046325684 + + + 11 + + + + + + + False + autosize + data_id + + + + 12 + + + + + + + False + autosize + fav_id + + + + 13 + + + + + + + False + autosize + transponder + + + + 14 + + + + + True + True + 1 + @@ -991,100 +1001,124 @@ True True - + True - True - in + False + vertical - + + True + False + Bouquet details + + + False + True + 0 + + + + True True - fav_list_store - 1 - True - both - True - - - - - - - - - - multiple - - + in - - True - autosize - Num - True - - - - 0 - - - - - - - True - autosize - Service - True - - - - 1 - - - - - - - Type - True - - - 0.50999999046325684 + + True + True + fav_list_store + 1 + True + both + True + + + + + + + + + + multiple - - 2 - - - - - - Pos - True - - 0.50999999046325684 + + True + autosize + Num + True + + + + 0 + + - - 3 - - - - - - False - fav_id - - - 4 - + + True + autosize + Service + True + + + + 1 + + + + + + + Type + True + + + 0.50999999046325684 + + + 2 + + + + + + + Pos + True + + + 0.50999999046325684 + + + 3 + + + + + + + False + fav_id + + + + 4 + + + + + True + True + 1 + @@ -1093,54 +1127,78 @@ - + True - True - in + False + vertical - + + True + False + Bouquets + + + False + True + 0 + + + + True True - bouquets_tree_store - False - False - True - - - - - - - + in - - True - autosize - Bouquets - True - - - - 0 - + + True + True + bouquets_tree_store + False + False + True + + + + + + - - - - - False - True - autosize - Type - - - 1 - + + True + autosize + Bouquets + True + + + + 0 + + + + + + + False + True + autosize + Type + + + + 1 + + + + + True + True + 1 + @@ -1183,8 +1241,13 @@ 10 6 6 - vertical 2 + + + + + + False diff --git a/main/ui/settings_dialog.py b/main/ui/settings_dialog.py index 96d91898..33ec84fc 100644 --- a/main/ui/settings_dialog.py +++ b/main/ui/settings_dialog.py @@ -10,7 +10,7 @@ class SettingsDialog: def __init__(self, transient, options): handlers = {"on_data_dir_field_icon_press": self.on_data_dir_field_icon_press} builder = Gtk.Builder() - builder.add_from_file("ui/dialogs.glade") + builder.add_objects_from_file("ui/dialogs.glade", ("settings_dialog", )) builder.connect_signals(handlers) self._dialog = builder.get_object("settings_dialog") self._dialog.set_transient_for(transient)