From 39550b392def60e9dedfcb867d5a3eb8d2506047 Mon Sep 17 00:00:00 2001 From: punix Date: Fri, 18 Apr 2025 20:50:32 +0200 Subject: [PATCH] format with blank and pylint --- cls_mth_fc.py | 97 ++++++++++++++++++++++++++++---------------------- ssl_decrypt.py | 10 +++--- ssl_encrypt.py | 20 +++++------ start_wg.py | 6 +++- 4 files changed, 75 insertions(+), 58 deletions(-) diff --git a/cls_mth_fc.py b/cls_mth_fc.py index 3eec3b6..dceb4bf 100755 --- a/cls_mth_fc.py +++ b/cls_mth_fc.py @@ -1,4 +1,4 @@ -""" Classes Method and functions for lx apps """ +""" Classes Method and Functions for lx Apps """ import gettext import locale @@ -33,6 +33,9 @@ class Create: @staticmethod def dir_and_files(): + """ + check and create folders and files if not present + """ pth = Path.home() / ".config/wire_py" pth.mkdir(parents=True, exist_ok=True) @@ -56,6 +59,9 @@ class Create: @staticmethod def files_for_autostart(): + """ + check and create file for auto start if not present and enable the service + """ pth2 = Path.home() / ".config/systemd/user" pth2.mkdir(parents=True, exist_ok=True) @@ -85,6 +91,9 @@ class Create: @staticmethod def decrypt(): + """ + This start ssl_decrypt file + """ process = subprocess.run( ["pkexec", "/usr/local/bin/ssl_decrypt.py"], stdout=subprocess.PIPE, @@ -98,6 +107,9 @@ class Create: @staticmethod def encrypt(): + """ + this start ssl_encrypt file + """ process = subprocess.run( ["pkexec", "/usr/local/bin/ssl_encrypt.py"], stdout=subprocess.PIPE, @@ -116,24 +128,20 @@ class UOS: """ - """ - This method displays the user name of the logged-in user, - even if you are rooted in a shell - """ - @staticmethod def username(): + """ + This method displays the user name of the logged-in user, + even if you are rooted in a shell + """ logname = str(Path.home())[6:] file = Path.home() / "/tmp/.loguser" - with open(file, "w") as f: + with open(file, "w", encoding="utf-8") as f: f.write(logname) class GiteaUpdate: """ - Calling api_down requests the URL and the version of the running script. - Example: version = 'v. 1.1.1.1' GiteaUpdate.api_down(http://example.de, version) - Calling download requests the download URL of the running script, the taskbar image for the “Download OK” window, the taskbar image for the “Download error” window and the variable res @@ -141,11 +149,15 @@ class GiteaUpdate: @staticmethod def api_down(update_api_url, version): + """ + Calling api_down requests the URL and the version of the running script. + Example: version = 'v. 1.1.1.1' GiteaUpdate.api_down(http://example.de, version) + """ try: response = requests.get(update_api_url) response_dict = response.json() response_dict = response_dict[0] - with open(wg_set, "r") as set_file: + with open(wg_set, "r", encoding="utf-8") as set_file: set_file = set_file.read() if "on\n" in set_file: if version[3:] != response_dict["tag_name"]: @@ -159,12 +171,15 @@ class GiteaUpdate: @staticmethod def download(urld, down_ok_image, down_not_ok_image, res): + """ + this is for download new Version of wirepy + """ try: to_down = "wget -qP " + str(Path.home()) + " " + urld result = subprocess.call(to_down, shell=True) if result == 0: shutil.chown(str(Path.home()) + f"/{res}.zip", 1000, 1000) - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/info.png" ii = down_ok_image wt = _("Download Successful") @@ -172,14 +187,14 @@ class GiteaUpdate: msg_window(iw, ii, wt, msg_t) else: - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/error.png" ii = down_not_ok_image wt = _("Download error") msg_t = _("Download failed! Please try again") msg_window(iw, ii, wt, msg_t) except subprocess.CalledProcessError: - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/error.png" ii = down_not_ok_image wt = _("Download error") @@ -190,7 +205,8 @@ class GiteaUpdate: def msg_window(img_w, img_i, w_title, w_txt, txt2=None, com=None): """ Function for different message windows for the user. with 4 arguments to be passed. - To create messages with your own images, icons, and titles. As an alternative to Python Messagebox. + To create messages with your own images, icons, and titles. + As an alternative to Python Messagebox. Paths to images must be specified: r'/usr/share/icons/lx-icons/64/info.png' img_w = Image for Tk Window img_i = Image for Icon @@ -236,13 +252,12 @@ class Tunnel: Class of Methods for Wire-Py """ - """ - The config file is packed into a dictionary, - to display the values Address , DNS and Peer in the labels - """ - @classmethod def con_to_dict(cls, file): + """ + The config file is packed into a dictionary, + to display the values Address , DNS and Peer in the labels + """ dictlist = [] for lines in file.readlines(): @@ -256,7 +271,7 @@ class Tunnel: if items == "::/0": dictlist.remove(items) - """ Here is the beginning (Loop) of convert List to Dictionary """ + # Here is the beginning (Loop) of convert List to Dictionary for _ in dictlist: a = [dictlist[0], dictlist[1]] b = [dictlist[2], dictlist[3]] @@ -271,7 +286,7 @@ class Tunnel: for elements in new_list: final_dict[elements[0]] = elements[1] - """ end... result a Dictionary """ + # end... result a Dictionary address = final_dict["Address"] dns = final_dict["DNS"] @@ -284,13 +299,11 @@ class Tunnel: pre_key = final_dict["PreSharedKey"] return address, dns, endpoint, pre_key - """ - Shows the Active Tunnel - """ - @staticmethod def active(): - + """ + Shows the Active Tunnel + """ active = ( os.popen('nmcli con show --active | grep -iPo "(.*)(wireguard)"') .read() @@ -303,26 +316,23 @@ class Tunnel: return active - """ - Shows all existing Wireguard tunnels a login user - """ - @staticmethod def list(): - + """ + Shows all existing Wireguard tunnels a login user + """ dirname = Path("/tmp/tlecdcwg/") wg_s = os.listdir(dirname) return wg_s - """ - This will export the tunnels. - A zipfile with current date and time is created - in the user's home directory with correct right - """ - @staticmethod def export(): + """ + This will export the tunnels. + A zipfile with current date and time is created + 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") tl = Tunnel.list() @@ -338,7 +348,7 @@ class Tunnel: with zipfile.ZipFile((wg_tar + ".zip"), "r") as zf: if len(zf.namelist()) != 0: - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/info.png" ii = r"/usr/share/icons/lx-icons/48/wg_vpn.png" wt = _("Export Successful") @@ -347,7 +357,7 @@ class Tunnel: else: - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/error.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Export error") @@ -356,7 +366,7 @@ class Tunnel: else: - """img_w, img_i, w_title, w_txt hand over""" + # img_w, img_i, w_title, w_txt hand over iw = r"/usr/share/icons/lx-icons/64/info.png" ii = r"/usr/share/icons/lx-icons/48/wg_msg.png" wt = _("Select tunnel") @@ -375,7 +385,10 @@ class Tipi: @staticmethod def if_tip(path): - with open(path, "r") as set_file2: + """ + method that writes in file whether tooltip is displayed or not + """ + with open(path, "r", encoding="utf-8") as set_file2: lines2 = set_file2.readlines() if "False\n" in lines2: return False diff --git a/ssl_decrypt.py b/ssl_decrypt.py index 6098525..7cb4630 100755 --- a/ssl_decrypt.py +++ b/ssl_decrypt.py @@ -8,13 +8,13 @@ from subprocess import check_call uname = Path("/tmp/.loguser") -with open(uname, "r") as f: +with open(uname, "r", encoding="utf-8") as f: logname = f.readline() -""" Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard """ +# Dirname "tlecdewg" = Tunnel Encrypt Decrypt Wireguard dirname = Path("/tmp/tlecdcwg/") keyfile = Path(f"/home/{logname}/.config/wire_py/pbwgk.pem") -pkeyfile = "/usr/local/etc/ssl/pwgk.pem" +PKEYFILE = "/usr/local/etc/ssl/pwgk.pem" if not keyfile.is_file(): @@ -23,7 +23,7 @@ if not keyfile.is_file(): "openssl", "rsa", "-in", - pkeyfile, + PKEYFILE, "-out", keyfile, "-outform", @@ -49,7 +49,7 @@ if os.path.exists(dirname2 + "pbwgk.pem"): "pkeyutl", "-decrypt", "-inkey", - pkeyfile, + PKEYFILE, "-in", detunnels, "-out", diff --git a/ssl_encrypt.py b/ssl_encrypt.py index 083020e..4f05032 100755 --- a/ssl_encrypt.py +++ b/ssl_encrypt.py @@ -1,5 +1,5 @@ #!/usr/bin/python3 -""" This Script encrypt Wireguardfiles for Wirepy users for more Security""" +""" This Script encrypt Wireguardfiles for Wirepy users for more Security """ import os import shutil @@ -8,12 +8,12 @@ from subprocess import check_call uname = Path("/tmp/.loguser") -with open(uname, "r") as f: +with open(uname, "r", encoding="utf-8") as f: logname = f.readline() keyfile = Path(f"/home/{logname}/.config/wire_py/pbwgk.pem") dirname = Path("/tmp/tlecdcwg/") -pkeyfile = "/usr/local/etc/ssl/pwgk.pem" +PKEYFILE = "/usr/local/etc/ssl/pwgk.pem" if not keyfile.is_file(): @@ -22,7 +22,7 @@ if not keyfile.is_file(): "openssl", "rsa", "-in", - pkeyfile, + PKEYFILE, "-out", keyfile, "-outform", @@ -34,13 +34,13 @@ if not keyfile.is_file(): if dirname.exists(): tl = os.listdir(str(dirname)) - cpth = str(keyfile) - cryptfiles = cpth[:-9] + CPTH = str(keyfile) + CRYPTFILES = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: sourcetl = str(dirname) + "/" + tunnels - tlname = cryptfiles + tunnels[:-5] + ".dat" + tlname = CRYPTFILES + tunnels[:-5] + ".dat" check_call( [ "openssl", @@ -60,13 +60,13 @@ else: if dirname.exists(): tl = os.listdir(str(dirname)) - cpth = str(keyfile) - cryptfiles = cpth[:-9] + CPTH = str(keyfile) + CRYPTFILES = CPTH[:-9] if keyfile.exists() and len(tl) != 0: for tunnels in tl: sourcetl = str(dirname) + "/" + tunnels - tlname = cryptfiles + tunnels[:-5] + ".dat" + tlname = CRYPTFILES + tunnels[:-5] + ".dat" check_call( [ "openssl", diff --git a/start_wg.py b/start_wg.py index 527fafc..b5aff30 100755 --- a/start_wg.py +++ b/start_wg.py @@ -1,10 +1,14 @@ #!/usr/bin/python3 +""" + This script belongs to wirepy and is for the auto start of the tunnel +""" from pathlib import Path from subprocess import check_call path_to_file = Path(Path.home() / ".config/wire_py/settings") -with open(path_to_file, "r") as a_con: +with open(path_to_file, "r", encoding="utf-8") as a_con: + # This funtion is for the independent autostart of the previously selected tunnel lines = a_con.readlines() a_con = lines[7].strip() if a_con != "off":