兼容Windows,修复界面bug
This commit is contained in:
parent
9a7440c97a
commit
b3a3738f6d
1 changed files with 18 additions and 5 deletions
23
manage.py
23
manage.py
|
@ -7,11 +7,13 @@ from queue import Empty, SimpleQueue
|
|||
from tkinter import *
|
||||
from tkinter import filedialog
|
||||
from tkinter.ttk import *
|
||||
from platform import system
|
||||
|
||||
config = ConfigParser()
|
||||
options = {"ftp": ["host", "user", "pass", "lftp"], "file": ["local", "remote"]}
|
||||
output_queue = SimpleQueue()
|
||||
finished = False
|
||||
win_os = system() == "Windows"
|
||||
|
||||
|
||||
def check_config_valid(config: ConfigParser, options: dict[str, list[str]]) -> bool:
|
||||
|
@ -51,9 +53,13 @@ def generate_db(config: ConfigParser) -> str:
|
|||
|
||||
|
||||
def sync_all_command() -> list[str]:
|
||||
file_path = config["file"]["local"]
|
||||
if win_os:
|
||||
drive = file_path[0]
|
||||
file_path = f'/cygdrive/{drive}{Path(config["file"]["local"]).as_posix()[2:]}'
|
||||
return [
|
||||
config["ftp"]["lftp"],
|
||||
f'-e mirror -R -e --parallel=10 {config["file"]["local"]} {config["file"]["remote"]}; exit',
|
||||
f'-e set log:enabled true; set mirror:set-permissions false; mirror -R -e --parallel=10 {file_path} {config["file"]["remote"]}; exit',
|
||||
"-u",
|
||||
f'{config["ftp"]["user"]},{config["ftp"]["pass"]}',
|
||||
config["ftp"]["host"],
|
||||
|
@ -61,9 +67,13 @@ def sync_all_command() -> list[str]:
|
|||
|
||||
|
||||
def sync_pdf_command() -> list[str]:
|
||||
file_path = config["file"]["local"]
|
||||
if win_os:
|
||||
drive = file_path[0]
|
||||
file_path = f'/cygdrive/{drive}{Path(config["file"]["local"]).as_posix()[2:]}'
|
||||
return [
|
||||
config["ftp"]["lftp"],
|
||||
f'-e mirror -R -e --parallel=10 {config["file"]["local"]}/categories {config["file"]["remote"]}/categories; exit',
|
||||
f'-e set log:enabled true; set mirror:set-permissions false; mirror -R -e --parallel=10 {file_path}/categories {config["file"]["remote"]}/categories; exit',
|
||||
"-u",
|
||||
f'{config["ftp"]["user"]},{config["ftp"]["pass"]}',
|
||||
config["ftp"]["host"],
|
||||
|
@ -95,20 +105,23 @@ def display_output():
|
|||
lftp_output.insert(END, line)
|
||||
except Empty:
|
||||
pass
|
||||
lftp_output.see(END)
|
||||
if not finished:
|
||||
root.after(200, display_output)
|
||||
|
||||
|
||||
def sync_all_files(_: Event) -> None:
|
||||
get_config()
|
||||
lftp_output.delete("1.0", END)
|
||||
Thread(target=sync_func, args=(sync_all_command(),), daemon=True).start()
|
||||
root.after(500, display_output)
|
||||
root.after(200, display_output)
|
||||
|
||||
|
||||
def sync_pdf_files(_: Event) -> None:
|
||||
get_config()
|
||||
lftp_output.delete("1.0", END)
|
||||
Thread(target=sync_func, args=(sync_pdf_command(),), daemon=True).start()
|
||||
root.after(500, display_output)
|
||||
root.after(200, display_output)
|
||||
|
||||
|
||||
def select_lftp(_: Event) -> None:
|
||||
|
@ -229,7 +242,7 @@ sync_pdf_btn = Button(actions_frm, text="Sync PDF Files", width=12)
|
|||
sync_pdf_btn.grid(row=0, column=3)
|
||||
sync_pdf_btn.bind("<Button-1>", sync_pdf_files)
|
||||
|
||||
lftp_output = Text(actions_frm, width=51, height=12)
|
||||
lftp_output = Text(actions_frm, width=53, height=12)
|
||||
lftp_output.grid(row=1, column=0, columnspan=4)
|
||||
|
||||
root.mainloop()
|
||||
|
|
Loading…
Reference in a new issue