兼容Windows,修复界面bug

This commit is contained in:
zhbaor 2021-11-04 00:01:45 +08:00
parent 9a7440c97a
commit b3a3738f6d

View file

@ -7,11 +7,13 @@ from queue import Empty, SimpleQueue
from tkinter import * from tkinter import *
from tkinter import filedialog from tkinter import filedialog
from tkinter.ttk import * from tkinter.ttk import *
from platform import system
config = ConfigParser() config = ConfigParser()
options = {"ftp": ["host", "user", "pass", "lftp"], "file": ["local", "remote"]} options = {"ftp": ["host", "user", "pass", "lftp"], "file": ["local", "remote"]}
output_queue = SimpleQueue() output_queue = SimpleQueue()
finished = False finished = False
win_os = system() == "Windows"
def check_config_valid(config: ConfigParser, options: dict[str, list[str]]) -> bool: 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]: 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 [ return [
config["ftp"]["lftp"], 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", "-u",
f'{config["ftp"]["user"]},{config["ftp"]["pass"]}', f'{config["ftp"]["user"]},{config["ftp"]["pass"]}',
config["ftp"]["host"], config["ftp"]["host"],
@ -61,9 +67,13 @@ def sync_all_command() -> list[str]:
def sync_pdf_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 [ return [
config["ftp"]["lftp"], 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", "-u",
f'{config["ftp"]["user"]},{config["ftp"]["pass"]}', f'{config["ftp"]["user"]},{config["ftp"]["pass"]}',
config["ftp"]["host"], config["ftp"]["host"],
@ -95,20 +105,23 @@ def display_output():
lftp_output.insert(END, line) lftp_output.insert(END, line)
except Empty: except Empty:
pass pass
lftp_output.see(END)
if not finished: if not finished:
root.after(200, display_output) root.after(200, display_output)
def sync_all_files(_: Event) -> None: def sync_all_files(_: Event) -> None:
get_config()
lftp_output.delete("1.0", END) lftp_output.delete("1.0", END)
Thread(target=sync_func, args=(sync_all_command(),), daemon=True).start() 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: def sync_pdf_files(_: Event) -> None:
get_config()
lftp_output.delete("1.0", END) lftp_output.delete("1.0", END)
Thread(target=sync_func, args=(sync_pdf_command(),), daemon=True).start() 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: 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.grid(row=0, column=3)
sync_pdf_btn.bind("<Button-1>", sync_pdf_files) 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) lftp_output.grid(row=1, column=0, columnspan=4)
root.mainloop() root.mainloop()