From 3bab0710a44a9ebe912f2e9fb881434fb3bcf8ea Mon Sep 17 00:00:00 2001 From: punix Date: Wed, 23 Apr 2025 14:18:06 +0200 Subject: [PATCH] replace "str(" with f"format{example}" --- __pycache__/cls_mth_fc.cpython-312.pyc | Bin 20595 -> 20555 bytes cls_mth_fc.py | 25 +++--- ssl_decrypt.py | 8 +- ssl_encrypt.py | 16 ++-- wirepy.py | 105 +++++++++---------------- 5 files changed, 64 insertions(+), 90 deletions(-) diff --git a/__pycache__/cls_mth_fc.cpython-312.pyc b/__pycache__/cls_mth_fc.cpython-312.pyc index 3009fde6c8ad0099a83ad012bbbe8cf728743ec7..913ab8ca6982a8cb6d75f9685030a59858d28970 100644 GIT binary patch delta 2104 zcmZ8ieQZ-z6o2=%ef?UuwtH*WkF90kK4k;;!B&Q&z<{lc0RzMYMYh*%9i`LThXb<8 zqM$@Hf(HU-ERKL#6P8eIj3gQ(Ao#%_e2E!F1&xW~KLXDwuP~O~^!+6(l9YyGMNkIXTANW7Da!NIv6_}Z$2|EzkV z0bRBS=FQHAO_c^%ntg|;p;Ua%9bhT;vM2gHg8}ZLnX}rCI1W0%b-)B~i%pqE=Ksp- zcc{)fH2#9*ZSk^-EK8ow9U+DZ!f{79J(~~i8}o6hd^R~R@reE0AU7n$)Ut*pP+E@w zXT90*y))OaQPw|p!f(rSK5!Y}*jy14tY)D?zlx!DNG<6k-6>U?NH|F!6Z%O^E1MpN za+2W`TLHG1Zi?49>D9|wV4m+XnxzaD%VR7gTsiiq88WAHHRhR|tcLyuH{`mr$aH?z zG`=$#alb@}9Jj~M{R!jISll1)h_6q~x{^2ljCe-=(YzGQp3xlh;(G2}b}?f8f+arH`8u-1 z2Uk7$o_6-abQi*N2o3~0LW=^B>GhMAzUu5L2dkMpC^Z|;uXe*g zwZ&**`IXjVQ?z)xI>U(jm-ac)r$zDUhj_SC?IL+_U+siBEP z#%>lu7&g~6k_dcU=g)o(9eoHp5Oy+vfnpI%J~w$4N_}ok*`n+A#SrkhZ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H(=5fe#8Oxh{>%l8q*u&v5h6p|%ubb` zhk(Bje&h3CcF|(<9zs_7ESIGJIR?A^}V-y6aBg zHD_?h8T>J{c-Xn5%QRxn{doDV<-1pOsqU)t^*JLJ>z*0A+x7=`cZ|5a2OGa=`mE`| z@?lr#SjCWQTK|+GR|K4MDy+Thj%_)d9OQ@XWp}xpoRTvtXr1#@k-Lg;=k3vOWifw| z*Rjb(QxLIOQyI}-oWr9WLA*rtRc8K@iBy?Enp+UQhTASj7(u{8)B6a|m8Nnf18{ln z1~QPIS$0RAjYZS0Gc?54x2{R}X$->A{lY(Jx)gqhx`jXU| zUXAK=psk!ua?{bu?^VPJ|5hJ0VzuJK-hV{kA-< z0|pj3;9*@3xeBI*-#Pa*_B3@j^|lR0&qOarAMmOiLzm{R0KYH%x?G8J7+tBT7b6yq zUZwwWNAWO4yR9*qOi1xJ!Yy$zwo1xOZot(=4f*5I%8h``=U?59Iy=eG6kb{33DE_Et sI=<41l?2Pec)3bYglBW`p{{IGQrw(~MQACkUVPI$g-rU3W1wv5f2x-Tod5s; diff --git a/cls_mth_fc.py b/cls_mth_fc.py index f83f2cc..f78278c 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -111,7 +111,7 @@ class Create: print(f"Error with the following code... {process.returncode}") else: print(_("Ready for import")) - + @staticmethod def encrypt(): """ @@ -138,7 +138,7 @@ def uos(): This method displays the user name of the logged-in user, even if you are rooted in a shell """ - logname = str(Path.home())[6:] + logname = f"{Path.home()}"[6:] file = Path.home() / "/tmp/.loguser" with open(file, "w", encoding="utf-8") as f: f.write(logname) @@ -181,10 +181,10 @@ class GiteaUpdate: this is for download new Version of wirepy """ try: - to_down = "wget -qP " + str(Path.home()) + " " + urld + to_down = f"wget -qP {Path.home()} {" "} {urld}" result = subprocess.call(to_down, shell=True) if result == 0: - shutil.chown(str(Path.home()) + f"/{res}.zip", 1000, 1000) + shutil.chown(f"{Path.home()}/{res}.zip", 1000, 1000) # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/info.png" @@ -342,17 +342,17 @@ class Tunnel: in the user's home directory with correct right """ now_time = datetime.now() - now_datetime = now_time.strftime("wg-exp-" + "%m-%d-%Y" + "-" + "%H:%M") + now_datetime = now_time.strftime(f"wg-exp-%m-%d-%Y-%H:%M") tl = Tunnel.list() try: if len(tl) != 0: - wg_tar = str(Path.home()) + "/" + now_datetime + wg_tar = f"{Path.home()}/{now_datetime}" shutil.copytree("/tmp/tlecdcwg/", "/tmp/wire_py", dirs_exist_ok=True) source = Path("/tmp/wire_py") shutil.make_archive(wg_tar, "zip", source) shutil.rmtree(source) - with zipfile.ZipFile((wg_tar + ".zip"), "r") as zf: + with zipfile.ZipFile(f"{wg_tar}.zip", "r") as zf: if len(zf.namelist()) != 0: # img_w, img_i, w_title, w_txt hand over @@ -461,14 +461,21 @@ class Tooltip: return x, y, _, _ = self.widget.bbox("insert") - x += self.widget.winfo_rootx() + 40 + x += self.widget.winfo_rootx() + 65 y += self.widget.winfo_rooty() + 40 self.tooltip_window = tw = tk.Toplevel(self.widget) tw.wm_overrideredirect(True) tw.wm_geometry(f"+{x}+{y}") label = tk.Label( - tw, text=self.text, relief="solid", borderwidth=1, padx=5, pady=5 + tw, + text=self.text, + background="lightgreen", + foreground="black", + relief="solid", + borderwidth=1, + padx=5, + pady=5, ) label.grid() diff --git a/ssl_decrypt.py b/ssl_decrypt.py index 7cb4630..cb3ef98 100755 --- a/ssl_decrypt.py +++ b/ssl_decrypt.py @@ -33,16 +33,16 @@ if not keyfile.is_file(): ) shutil.chown(keyfile, 1000, 1000) -dirname2 = "/home/" + logname + "/.config/wire_py/" +dirname2 = f"/home/{logname}/.config/wire_py/" detl = os.listdir(dirname2) os.chdir(dirname2) detl.remove("keys") detl.remove("settings") -if os.path.exists(dirname2 + "pbwgk.pem"): +if os.path.exists(f"{dirname2}pbwgk.pem"): detl.remove("pbwgk.pem") for detunnels in detl: - tlname2 = detunnels[:-4] + ".conf" - extpath = str(dirname) + "/" + tlname2 + tlname2 = f"{detunnels[:-4]}.conf" + extpath = f"{dirname}/{tlname2}" check_call( [ "openssl", diff --git a/ssl_encrypt.py b/ssl_encrypt.py index 4f05032..4069f79 100755 --- a/ssl_encrypt.py +++ b/ssl_encrypt.py @@ -33,14 +33,14 @@ if not keyfile.is_file(): shutil.chown(keyfile, 1000, 1000) if dirname.exists(): - tl = os.listdir(str(dirname)) - CPTH = str(keyfile) + tl = os.listdir(f"{dirname}") + CPTH = f"{keyfile}" CRYPTFILES = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: - sourcetl = str(dirname) + "/" + tunnels - tlname = CRYPTFILES + tunnels[:-5] + ".dat" + sourcetl = f"{dirname}/{tunnels}" + tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat" check_call( [ "openssl", @@ -59,14 +59,14 @@ if not keyfile.is_file(): else: if dirname.exists(): - tl = os.listdir(str(dirname)) - CPTH = str(keyfile) + tl = os.listdir(f"{dirname}") + CPTH = f"{keyfile}" CRYPTFILES = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: - sourcetl = str(dirname) + "/" + tunnels - tlname = CRYPTFILES + tunnels[:-5] + ".dat" + sourcetl = f"{dirname}/{tunnels}" + tlname = f"{CRYPTFILES}{tunnels[:-5]}.dat" check_call( [ "openssl", diff --git a/wirepy.py b/wirepy.py index 0bc2fb8..d1a7074 100755 --- a/wirepy.py +++ b/wirepy.py @@ -67,7 +67,7 @@ class Wirepy(tk.Tk): self.rowconfigure(0, weight=1) self.style = ttk.Style(self) - self.tk.call("source", str(tcl_path) + "/water.tcl") + self.tk.call("source", f"{tcl_path}/water.tcl") with open(wg_set, "r", encoding="utf-8") as read_file: lines = read_file.readlines() if "light\n" in lines: @@ -261,7 +261,7 @@ class FrameWidgets(ttk.Frame): else: set_update.set(value=0) - text = f"Update {res} " + _("available!") + text = f"Update {res} {_("available!")}" # Update BTN Menu self.update_btn = ttk.Menubutton(self.menu_frame, text=text) @@ -303,9 +303,8 @@ class FrameWidgets(ttk.Frame): # Bottom Frame 4 self.lb_frame3 = ttk.Frame(self) self.lb_frame3.configure(relief="flat") - self.lb_frame3.grid( - column=0, row=5, columnspan=4, sticky="snew", padx=2, pady=2 - ) + self.lb_frame3.grid(column=0, row=5, columnspan=4, sticky="snew", + padx=2, pady=2) # Bottom Frame 5 self.lb_frame4 = ttk.Frame(self) @@ -364,7 +363,7 @@ class FrameWidgets(ttk.Frame): # Button Vpn if self.a != "": self.stop() - wg_read = "/tmp/tlecdcwg/" + str(self.a + ".conf") + wg_read = f"/tmp/tlecdcwg/{self.a}.conf" with open(wg_read, "r", encoding="utf-8") as file: data = Tunnel.con_to_dict(file) @@ -382,12 +381,8 @@ class FrameWidgets(ttk.Frame): self.show_data() # Button Import - self.btn_i = ttk.Button( - self.lb_frame_btn_lbox, - image=self.imp_pic, - command=self.import_sl, - padding=0, - ) + self.btn_i = ttk.Button(self.lb_frame_btn_lbox, image=self.imp_pic, + command=self.import_sl, padding=0) self.btn_i.grid(column=0, row=1, padx=15, pady=8) Tooltip(self.btn_i, _("Click to import a Wireguard Tunnel"), tips) @@ -399,8 +394,7 @@ class FrameWidgets(ttk.Frame): try: self.select_tunnel = self.l_box.curselection() select_tl = self.l_box.get(self.select_tunnel[0]) - with open( - "/tmp/tlecdcwg/" + select_tl + ".conf", "r+", encoding="utf-8" + with open(f"/tmp/tlecdcwg/{select_tl}.conf", "r+", encoding="utf-8" ) as file2: key = Tunnel.con_to_dict(file2) pre_key = key[3] @@ -417,24 +411,16 @@ class FrameWidgets(ttk.Frame): set_file7.writelines(lines6) self.selected_option.set(0) self.autoconnect_var.set(_("no Autoconnect")) - is_encrypt = Path.home() / ".config/wire_py" / str(select_tl + ".dat") + is_encrypt = Path.home() / f".config/wire_py/{select_tl}.dat" if is_encrypt.is_file(): - Path.unlink( - str(Path.home()) + "/.config/wire_py/" + str(select_tl + ".dat") - ) - Path.unlink(Path("/tmp/tlecdcwg") / str(select_tl + ".conf")) - with open( - str(Path.home()) + "/.config/wire_py/keys", "r", encoding="utf-8" - ) as readfile: - with open( - str(Path.home()) + "/.config/wire_py/keys2", - "w", - encoding="utf-8", - ) as writefile: + Path.unlink(f"{Path.home()}/.config/wire_py/{select_tl}.dat") + Path.unlink(f"/tmp/tlecdcwg/{select_tl}.conf") + with open(f"{Path.home()}/.config/wire_py/keys", "r", encoding="utf-8") as readfile: + with open(f"{Path.home()}/.config/wire_py/keys2", "w", encoding="utf-8") as writefile: for line in readfile: if pre_key not in line.strip("\n"): writefile.write(line) - file_one = Path(str(Path.home()) + "/.config/wire_py/keys2") + file_one = Path(f"{Path.home()}/.config/wire_py/keys2") file_two = file_one.with_name("keys") file_one.replace(file_two) self.wg_autostart.configure(state="disabled") @@ -443,21 +429,13 @@ class FrameWidgets(ttk.Frame): if self.l_box.size() == 0: self.wg_autostart.configure(state="disabled") self.lb_rename.configure(state="disabled") - Tooltip( - self.wg_autostart, - _( - "You must have at least one\ntunnel in the list,to use the autostart" - ), - tips, - ) + Tooltip(self.wg_autostart, _("You must have at least one\ntunnel", + "in the list,to use the autostart"), tips) Tooltip(self.btn_exp, _("No Tunnels in List for Export"), tips) Tooltip(self.btn_stst, _("No tunnels to start in the list"), tips) - Tooltip( - self.lb_rename, - _("To rename a tunnel, at least one must be in the list"), - tips, - ) + Tooltip(self.lb_rename, _("To rename a tunnel, at least one must", + "be in the list"), tips,) self.lb_rename.insert(0, _("Max. 12 characters!")) if self.a != "" and self.a == select_tl: @@ -503,9 +481,7 @@ class FrameWidgets(ttk.Frame): if self.l_box.size() == 0: Tooltip(self.btn_tr, _("No tunnels to delete in the list"), tips) else: - Tooltip( - self.btn_tr, - _("Click to delete a Wireguard Tunnel\nSelect from the list!"), + Tooltip(self.btn_tr, _("Click to delete a Wireguard Tunnel\nSelect from the list!"), tips, ) @@ -520,7 +496,7 @@ class FrameWidgets(ttk.Frame): else: Tooltip( self.btn_exp, - _(" Click to export all\nWireguard Tunnel to Zipfile"), + _("Click to export all\nWireguard Tunnel to Zipfile"), tips, ) @@ -593,12 +569,11 @@ class FrameWidgets(ttk.Frame): self.lb_rename.get(), ] ) - source = Path("/tmp/tlecdcwg") / str(select_tl + ".conf") - destination = source.with_name(str(self.lb_rename.get() + ".conf")) + source = Path(f"/tmp/tlecdcwg/{select_tl}.conf") + destination = source.with_name(f"{self.lb_rename.get()}.conf") source.replace(destination) - Path.unlink( - str(Path.home()) + "/.config/wire_py/" + str(select_tl + ".dat") - ) + Path.unlink(f"{Path.home()}/.config/wire_py/{select_tl}.dat") + self.l_box.delete(self.select_tunnel[0]) self.l_box.insert("end", self.lb_rename.get()) self.l_box.update() @@ -703,7 +678,7 @@ class FrameWidgets(ttk.Frame): try: filepath = filedialog.askopenfilename( - initialdir=str(Path.home()), + initialdir=f"{Path.home()}", title=_("Select Wireguard config File"), filetypes=[(_("WG config files"), "*.conf")], ) @@ -723,13 +698,9 @@ class FrameWidgets(ttk.Frame): key = Tunnel.con_to_dict(file) pre_key = key[3] if len(pre_key) != 0: - with open( - str(Path.home()) + "/.config/wire_py/keys", - "r", - encoding="utf-8", - ) as readfile: + with open(f"{Path.home()}/.config/wire_py/keys", "r", encoding="utf-8") as readfile: p_key = readfile.readlines() - if pre_key in p_key or pre_key + "\n" in p_key: + if pre_key in p_key or f"{pre_key}\n" in p_key: # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/error.png" @@ -742,21 +713,17 @@ class FrameWidgets(ttk.Frame): else: - with open( - str(Path.home()) + "/.config/wire_py/keys", - "a", - encoding="utf-8", - ) as keyfile: - keyfile.write(pre_key + "\r") + with open(f"{Path.home()}/.config/wire_py/keys", "a", encoding="utf-8") as keyfile: + keyfile.write(f"{pre_key}\r") if len(path_split1) > 17: p1 = shutil.copy(filepath, "/tmp/tlecdcwg/") path_split = path_split1[ len(path_split1) - 17 : ] os.rename( - p1, "/tmp/tlecdcwg/" + str(path_split) + p1, f"/tmp/tlecdcwg/{path_split}" ) - new_conf = "/tmp/tlecdcwg/" + path_split + new_conf = f"/tmp/tlecdcwg/{path_split}" if self.a != "": check_call( [ @@ -859,7 +826,7 @@ class FrameWidgets(ttk.Frame): self.str_var.set(self.a) self.color_label() self.stop() - wg_read = "/tmp/tlecdcwg/" + str(self.a + ".conf") + wg_read = f"/tmp/tlecdcwg/{self.a}.conf" with open( wg_read, "r", encoding="utf-8" ) as file_for_key: @@ -976,11 +943,11 @@ class FrameWidgets(ttk.Frame): # Address Label self.add = tk.StringVar() - self.add.set(_("Address: ") + data[0]) + self.add.set(f"{_("Address: ")}{data[0]}") self.DNS = tk.StringVar() - self.DNS.set(" DNS: " + data[1]) + self.DNS.set(f" DNS: {data[1]}") self.enp = tk.StringVar() - self.enp.set(_("Endpoint: ") + data[2]) + self.enp.set(f"{_("Endpoint: ")}{data[2]}") def label_empty(self): """ @@ -1078,7 +1045,7 @@ class FrameWidgets(ttk.Frame): self.select_tunnel = self.l_box.curselection() select_tl = self.l_box.get(self.select_tunnel[0]) check_call(["nmcli", "connection", "up", select_tl]) - wg_read = "/tmp/tlecdcwg/" + str(select_tl + ".conf") + wg_read = f"/tmp/tlecdcwg/{select_tl}.conf" with open(wg_read, "r", encoding="utf-8") as file: data = Tunnel.con_to_dict(file)