mirror of
https://github.com/DYefremov/DemonEditor.git
synced 2026-05-06 11:45:36 +02:00
implemented ftp upload
This commit is contained in:
45
app/ftp.py
45
app/ftp.py
@@ -14,7 +14,7 @@ class DownloadDataType(Enum):
|
||||
|
||||
|
||||
def download_data(*, properties, download_type=DownloadDataType.ALL):
|
||||
with FTP(properties["host"]) as ftp:
|
||||
with FTP(host=properties["host"], timeout=5) as ftp:
|
||||
ftp.login(user=properties["user"], passwd=properties["password"])
|
||||
save_path = properties["data_dir_path"]
|
||||
files = []
|
||||
@@ -42,15 +42,40 @@ def download_data(*, properties, download_type=DownloadDataType.ALL):
|
||||
with open(save_path + xml_file, 'wb') as f:
|
||||
ftp.retrbinary('RETR ' + xml_file, f.write)
|
||||
|
||||
return ftp.voidcmd("NOOP")
|
||||
|
||||
|
||||
def upload_data(*, properties, download_type=DownloadDataType.ALL, remove_unused=False):
|
||||
load_path = properties["data_dir_path"]
|
||||
data_path = properties["data_dir_path"]
|
||||
|
||||
with FTP(host=properties["host"], timeout=5) as ftp:
|
||||
ftp.login(user=properties["user"], passwd=properties["password"])
|
||||
|
||||
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.SATELLITES:
|
||||
ftp.cwd(properties["satellites_xml_path"])
|
||||
file_name = "satellites.xml"
|
||||
send = send_file(file_name, data_path, ftp)
|
||||
if download_type == DownloadDataType.SATELLITES:
|
||||
return send
|
||||
|
||||
if download_type is DownloadDataType.ALL or download_type is DownloadDataType.BOUQUETS:
|
||||
ftp.cwd(properties["services_path"])
|
||||
if remove_unused:
|
||||
files = []
|
||||
ftp.dir(files.append)
|
||||
for file in files:
|
||||
name = str(file).strip()
|
||||
if name.endswith(__DATA_FILES_LIST):
|
||||
name = name.split()[-1]
|
||||
ftp.delete(name)
|
||||
|
||||
for file_name in os.listdir(data_path):
|
||||
if file_name == "satellites.xml":
|
||||
continue
|
||||
send_file(file_name, data_path, ftp)
|
||||
|
||||
|
||||
def send_file(file_name, path, ftp):
|
||||
""" Opens the file in binary mode and transfers into receiver """
|
||||
with open(path + file_name, "rb") as f:
|
||||
return ftp.storbinary("STOR " + file_name, f)
|
||||
|
||||
|
||||
for file_name in os.listdir(load_path):
|
||||
print(file_name)
|
||||
# Open the file for transfer in binary mode
|
||||
# f = open(file_name, "rb")
|
||||
# transfer the file into receiver
|
||||
# send = ftp.storbinary("STOR " + file_name, f)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from app.commons import run_task
|
||||
from app.ftp import download_data, upload_data, DownloadDataType
|
||||
from .dialogs import show_dialog
|
||||
from . import Gtk
|
||||
|
||||
|
||||
@@ -39,6 +40,8 @@ class DownloadDialog:
|
||||
self.download(True, d_type=self.get_download_type())
|
||||
|
||||
def on_send(self, item):
|
||||
if show_dialog("question_dialog", self._dialog) == Gtk.ResponseType.CANCEL:
|
||||
return
|
||||
self.download(d_type=self.get_download_type())
|
||||
|
||||
def get_download_type(self):
|
||||
@@ -65,10 +68,12 @@ class DownloadDialog:
|
||||
if download:
|
||||
download_data(properties=self._properties, download_type=d_type)
|
||||
else:
|
||||
upload_data(properties=self._properties, download_type=d_type)
|
||||
upload_data(properties=self._properties,
|
||||
download_type=d_type,
|
||||
remove_unused=self._remove_unused_check_button.get_active())
|
||||
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))
|
||||
self._message_label.set_text(getattr(e, "message", str(e)))
|
||||
else:
|
||||
self._info_bar.set_message_type(Gtk.MessageType.INFO)
|
||||
self._message_label.set_text("OK")
|
||||
|
||||
@@ -427,10 +427,10 @@ class MainAppWindow:
|
||||
|
||||
# Getting bouquets
|
||||
self.__bouquets_view.get_model().foreach(parse_bouquets)
|
||||
write_bouquets(path + "tmp/", bouquets, self.__bouquets)
|
||||
write_bouquets(path, bouquets, self.__bouquets)
|
||||
# Getting services
|
||||
services = [Channel(*row[:]) for row in services_model]
|
||||
write_channels(path + "tmp/", services)
|
||||
write_channels(path, services)
|
||||
|
||||
def on_services_selection(self, model, path, column):
|
||||
self.delete_selection(self.__fav_view)
|
||||
@@ -561,4 +561,4 @@ def close_app():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
pass
|
||||
pass
|
||||
|
||||
@@ -279,6 +279,7 @@
|
||||
<property name="can_focus">False</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="use_stock">True</property>
|
||||
<signal name="activate" handler="on_quit" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@@ -29,7 +29,8 @@ class SatellitesDialog:
|
||||
"on_edit": self.on_edit,
|
||||
"on_key_release": self.on_key_release,
|
||||
"on_row_activated": self.on_row_activated,
|
||||
"on_resize": self.on_resize}
|
||||
"on_resize": self.on_resize,
|
||||
"on_quit": self.on_quit}
|
||||
|
||||
builder = Gtk.Builder()
|
||||
builder.add_objects_from_file("app/ui/satellites_dialog.glade",
|
||||
@@ -62,6 +63,9 @@ class SatellitesDialog:
|
||||
if self._options:
|
||||
self._options["sat_editor_window_size"] = window.get_size()
|
||||
|
||||
def on_quit(self, item):
|
||||
self.destroy()
|
||||
|
||||
def on_open(self, model):
|
||||
builder = Gtk.Builder()
|
||||
builder.add_objects_from_file("app/ui/dialogs.glade", ("path_chooser_dialog",))
|
||||
|
||||
@@ -46,7 +46,7 @@ class SettingsDialog:
|
||||
|
||||
def on_data_dir_field_icon_press(self, entry, icon, event_button):
|
||||
builder = Gtk.Builder()
|
||||
builder.add_from_file("ui/dialogs.glade")
|
||||
builder.add_from_file("app/ui/dialogs.glade")
|
||||
dialog = builder.get_object("path_chooser_dialog")
|
||||
dialog.set_transient_for(self._dialog)
|
||||
dialog.set_current_folder(self._current_data_path)
|
||||
|
||||
Reference in New Issue
Block a user