From 213f772f40719050c1423785d069587d1dac4c03 Mon Sep 17 00:00:00 2001 From: punix Date: Tue, 29 Apr 2025 11:39:05 +0200 Subject: [PATCH] methods optimized in wirepy and cls_mth_fc --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 23550 -> 23366 bytes cls_mth_fc.py | 16 +++--- wirepy.py | 70 ++++++++++--------------- 3 files changed, 36 insertions(+), 50 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index cad7fecc4342ea16b8e912544eb5d3f8f4c5111f..8c9b363d4c3d0e5e58ff9c192aa90c4cda2e92e9 100644 GIT binary patch delta 1844 zcmZXUeM}Tr5Wx5CeR9W@hbB)^Crq#rzNt@_tt7J`6W1_}1saI>#)_%U(Luu^(@!Oes zGjHb2?AyOjkuOgY+t)Umg<}snXzzXNLmP2|Xi6i8;lRowDA1ds&bh=v&;g%eGMWx8nYVbSxf&XO>h;HPwMgoJg&WPqdkuzrLe z=3BY2A@%kchg#rnjuZaLt6okwV74}fA!9>Olm$zJ-@|L?QPZdp40kHR4uzd?DRWT` zVnh;TRi{K^vW^*G&y0fAuQEZdX4uKyw{V%xF+W(Y+T97e`&iFKyZf?z;izHKntjNS zu;x!Xaz^WtM$Vo!YDwz2ET&CnI7Thn$>YYEnMQWx+`=_8VwldfwO>{u-GeGGZD%FO z%tjR$DXgqciKst^j+RhV?C+E0SWr^=b!$|zotpfHEv%fwXw%%|@I|?sB;aQG!IE~gYG0C; zM!zK*6=@hFb+SS!Hk@L!=}9=^?aD|qRQ;mkjE*GFq@)WnD!ln=hO9Avl4Gw!;d}Uc z8OwN3Jroq#I_{j*{m1vD)jr@hjZ? zJ{+je%eJvQJ!JFuOOhaZgCQj{APmBp`ag*kPB$zfdm!21vp?RgxUVs(Cs$y0v)6hR z_d1K1gpTITi*BH}kU`ang7lw1lr}AMC>k47s3556eZg%)XOM<^SxUMY?lzZ{X`@T? z55|Pl#BBeY6Kk{Nfd{@hEo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S<+z=TB$D%A4 zUU7{*Yjh|?l{f-oVbp-+a<)oT{hR%R<&sWTLm6&)2j zBHbdz8d)uh;15Y^`;??W&@YFAlB{Uew+2?Y3JrTO%QgmRa}AK{_=M{^Uv>$df8uMXKr8su@NS#FOwVbi#2Av+C{EK~xN(B8hH6 zyOhZk(xVXe+3@$UAG^v?`ZjddTXITRus7YyUMu!#b4YBvZkH2-tMQ}t`^j8&kvA|M zKb20xzn=U@eR9HGnKHR4{;VAHtbxDmUTXLvpI^s zO_XJ^hi$V^#P17<)P&j=OgDlkL&O;ry}T1X1 diff --git a/cls_mth_fc.py b/cls_mth_fc.py index a6ab225..cffc669 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -135,8 +135,7 @@ class LxTools(tk.Tk): """ log_name: str = f"{Path.home()}"[6:] file: Path = Path.home() / "/tmp/.log_user" - with open(file, "w", encoding="utf-8") as f: - f.write(log_name) + Path(file).write_text(log_name, encoding="utf-8") @staticmethod def clean_files(folder_path: Path = None, file: Path = None) -> None: @@ -156,13 +155,12 @@ class LxTools(tk.Tk): """ method that writes in file whether tooltip is displayed or not """ - with open(path, "r", encoding="utf-8") as set_f2: - lines2 = set_f2.readlines() - if "False\n" in lines2: - tip = False - else: - tip = True - return tip + lines = Path(path).read_text(encoding="utf-8") + if "False\n" in lines: + tip = False + else: + tip = True + return tip @staticmethod def msg_window(img_w: str, img_i: str, w_title: str, w_txt: str, txt2: Optional[str] = None, diff --git a/wirepy.py b/wirepy.py index b62cb6e..e442916 100755 --- a/wirepy.py +++ b/wirepy.py @@ -349,11 +349,9 @@ class FrameWidgets(ttk.Frame): """ if self.tk.call("ttk::style", "theme", "use") == "water-dark": self.tk.call("set_theme", "light") - with open(set_file, "r", encoding="utf-8") as theme_set2: - lines3 = theme_set2.readlines() - lines3[3] = "light\n" - with open(set_file, "w", encoding="utf-8") as theme_set2: - theme_set2.writelines(lines3) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) # (keepends=True) = not changed + lines[3] = 'light\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") self.color_label() def theme_change_dark(self): @@ -362,33 +360,27 @@ class FrameWidgets(ttk.Frame): """ if not self.tk.call("ttk::style", "theme", "use") == "water-dark": self.tk.call("set_theme", "dark") - with open(set_file, "r", encoding="utf-8") as theme_set2: - lines4 = theme_set2.readlines() - lines4[3] = "dark\n" - with open(set_file, "w", encoding="utf-8") as theme_set2: - theme_set2.writelines(lines4) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) + lines[3] = 'dark\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") self.color_label() @staticmethod - def update_setting(update_res): + def update_setting(update_res) -> None: """ write off or on in file Args: update_res (int): argument that is passed contains 0 or 1 """ if update_res == 1: - with open(set_file, "r", encoding="utf-8") as set_f2: - lines2 = set_f2.readlines() - lines2[1] = "off\n" - with open(set_file, "w", encoding="utf-8") as set_f2: - set_f2.writelines(lines2) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) + lines[1] = 'off\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") else: - with open(set_file, "r", encoding="utf-8") as set_f2: - lines2 = set_f2.readlines() - lines2[1] = "on\n" - with open(set_file, "w", encoding="utf-8") as set_f2: - set_f2.writelines(lines2) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) + lines[1] = 'on\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") @staticmethod def tooltip(tip) -> None: @@ -398,20 +390,16 @@ class FrameWidgets(ttk.Frame): tip (bool): argument that is passed contains True or False """ if tip: - with open(set_file, "r", encoding="utf-8") as set_f2: - lines2 = set_f2.readlines() - lines2[5] = "False\n" - with open(set_file, "w", encoding="utf-8") as set_f2: - set_f2.writelines(lines2) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) + lines[5] = 'False\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") else: - with open(set_file, "r", encoding="utf-8") as set_f2: - lines2 = set_f2.readlines() - lines2[5] = "True\n" - with open(set_file, "w", encoding="utf-8") as set_f2: - set_f2.writelines(lines2) + lines = Path(set_file).read_text(encoding="utf-8").splitlines(keepends=True) + lines[5] = 'True\n' + Path(set_file).write_text(''.join(lines), encoding="utf-8") - def enable_check_box(self, _): + def enable_check_box(self, _) -> None: """ checkbox for enable autostart Tunnel """ @@ -422,7 +410,7 @@ class FrameWidgets(ttk.Frame): self.lb_rename.delete(0, tk.END) self.btn_rename.config(state="normal") - def delete(self): + def delete(self) -> None: """ delete Wireguard Tunnel """ @@ -541,7 +529,7 @@ class FrameWidgets(ttk.Frame): except subprocess.CalledProcessError: pass - def import_sl(self): + def import_sl(self) -> None: """ Import Methode for Wireguard config Files. Before importing, it is checked whether PrivateKey and PublicKey are in the file. @@ -671,7 +659,7 @@ class FrameWidgets(ttk.Frame): self.show_data() return data - def box_set(self): + def box_set(self) -> None: """ This Method will display the autostarted label which Tunnel is automatically started regardless of the active tunnel. @@ -705,7 +693,7 @@ class FrameWidgets(ttk.Frame): self.on_off() - def on_off(self): + def on_off(self) -> None: """ Here it is checked whether the path to the file is there, if not, it is created. Set (on), the selected tunnel is displayed in the label. @@ -732,7 +720,7 @@ class FrameWidgets(ttk.Frame): self.autoconnect.config(font=("Ubuntu", 11)) self.autoconnect.grid(column=1, row=0, sticky="e", pady=19) - def init_and_report(self, data=None): + def init_and_report(self, data=None) -> None: """ Displays the value address, DNS and peer in the labels or empty it again @@ -755,7 +743,7 @@ class FrameWidgets(ttk.Frame): for field in fields: field.set("") - def show_data(self): + def show_data(self) -> None: """ shows data in the label """ @@ -775,7 +763,7 @@ class FrameWidgets(ttk.Frame): self.endpoint.grid(column=0, row=8, sticky="w", padx=10, pady=20) self.endpoint.config(font=("Ubuntu", 9)) - def stop(self): + def stop(self) -> None: """ Stop Button """ @@ -785,7 +773,7 @@ class FrameWidgets(ttk.Frame): Tooltip(self.btn_stst, _("Click to stop selected Wireguard Tunnel"), tips) - def start(self): + def start(self) -> None: """ Start Button """ @@ -799,7 +787,7 @@ class FrameWidgets(ttk.Frame): else: Tooltip(self.btn_stst, _("Click to start selected Wireguard Tunnel"), tips) - def color_label(self): + def color_label(self) -> None: """ View activ Tunnel in the color green or yellow """