in delete replace open with Path

install fixes
This commit is contained in:
Désiré Werner Menrath 2024-09-15 02:09:43 +02:00
parent d1a822fff0
commit f09e6eed0d
5 changed files with 46 additions and 40 deletions

View File

@ -4,8 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" />
</component>
<component name="ChangeListManager">
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes a labels when stop and start, installer first functions works">
<change afterPath="$PROJECT_DIR$/message.py" afterDir="false" />
<list default="true" id="940e1630-c825-4d4c-be80-bc11f543c122" name="Changes" comment="little fixes, add msg_window() &#10;function for Messagebox to show a tk.Toplevel()&#10;replace var = open() with: &#10;with open() as var:&#10;and remove by classes (tk.tk) and super()">
<change afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test2.py" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
@ -361,7 +360,15 @@
<option name="project" value="LOCAL" />
<updated>1725991610908</updated>
</task>
<option name="localTasksCounter" value="30" />
<task id="LOCAL-00030" summary="little fixes, add msg_window() &#10;function for Messagebox to show a tk.Toplevel()&#10;replace var = open() with: &#10;with open() as var:&#10;and remove by classes (tk.tk) and super()">
<option name="closed" value="true" />
<created>1726349168248</created>
<option name="number" value="00030" />
<option name="presentableId" value="LOCAL-00030" />
<option name="project" value="LOCAL" />
<updated>1726349168248</updated>
</task>
<option name="localTasksCounter" value="31" />
<servers />
</component>
<component name="Vcs.Log.Tabs.Properties">
@ -399,7 +406,6 @@
</component>
<component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" />
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window" />
<MESSAGE value="add class Frame and class Massage, delete funktion go 100%, add resize window, add warning pic" />
<MESSAGE value="add class ListTunnels and class ImportTunnel, and add class ExportTunnels (ExportTunnels no finish)" />
<MESSAGE value="add Label Interface and Peer to new FrameWidget one and two. when import Tunnel then add to list works and remove of list when Tunnel delete.(with Label active on and off) &#10;add to class and methods open a avtive Tunnel when Wire-Py open, when import and start a Tunnel" />
@ -424,6 +430,7 @@
<MESSAGE value="little fixes" />
<MESSAGE value="little fixes replace os.system with check_call&#10;first steps in install Script add wg_start.service file" />
<MESSAGE value="little fixes a labels when stop and start, installer first functions works" />
<option name="LAST_COMMIT_MESSAGE" value="little fixes a labels when stop and start, installer first functions works" />
<MESSAGE value="little fixes, add msg_window() &#10;function for Messagebox to show a tk.Toplevel()&#10;replace var = open() with: &#10;with open() as var:&#10;and remove by classes (tk.tk) and super()" />
<option name="LAST_COMMIT_MESSAGE" value="little fixes, add msg_window() &#10;function for Messagebox to show a tk.Toplevel()&#10;replace var = open() with: &#10;with open() as var:&#10;and remove by classes (tk.tk) and super()" />
</component>
</project>

View File

@ -8,20 +8,21 @@ config_path = Path.home() / ".config" / "wire_py" / "wg_py"
start_file = f'''\
#!/usr/bin/python3
from subprocess import check_call
from pathlib import Path
path_to_file = {str(config_path)!r}
path_to_file = Path.home() / '.config/wire_py/wg_py'
if Path.exists(path_to_file):
a_con = Path.read_text(path_to_file)
check_call(['nmcli', 'connection', 'up', a_con])
else:
pass
with open(path_to_file, 'r') as file:
*_, line = file
a_con = line[5:]
check_call(['nmcli', 'connection', 'up', a_con])
'''
Path("start_wg.py").write_text(start_file)
config_path.parent.mkdir(exist_ok=True)
if not Path.exists(config_path):
config_path.write_text("false")
# Prompt the user for the sudo password
#sudo_password = getpass('Enter sudo password: ')

13
main.py
View File

@ -148,26 +148,27 @@ class FrameWidgets(ttk.Frame):
self.btn_i.grid(column=0, row=1, padx=15, pady=8)
def delete():
try:
self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0])
check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0])
os.remove(Path.home() / 'tester/' / str(select_tl + '.conf'))
Path.unlink(Path.home() / 'tester/' / str(select_tl + '.conf'))
path_to_file = Path.home() / '.config/wire_py/wg_py'
with open(path_to_file, 'r') as file2:
for line in file2.readlines():
a_con = line[5:]
if Path.exists(path_to_file):
a_con = Path.read_text(path_to_file)
if select_tl == a_con:
self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect')
Path.unlink(path_to_file)
# for disable checkbox when Listbox empty
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
with open(path_to_file, 'w') as file2:
file2.write('false')
Path.unlink(path_to_file)
if self.a != '' and self.a == select_tl:
self.StrVar.set(value='')

View File

@ -1,9 +1,12 @@
#!/usr/bin/python3
from subprocess import check_call
from pathlib import Path
path_to_file = '/home/punix/.config/wire_py/wg_py'
path_to_file = Path.home() / '.config/wire_py/wg_py'
if Path.exists(path_to_file):
a_con = Path.read_text(path_to_file)
check_call(['nmcli', 'connection', 'up', a_con])
else:
pass
with open(path_to_file, 'r') as file:
*_, line = file
a_con = line[5:]
check_call(['nmcli', 'connection', 'up', a_con])

View File

@ -2,7 +2,7 @@
import os
import shutil
from datetime import datetime
from tkinter import filedialog, ttk
from tkinter import filedialog
import tkinter as tk
from pathlib import Path
from subprocess import check_call
@ -248,15 +248,12 @@ class FileHandle:
select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(select_tunnel[0])
if self.selected_option.get() == 0:
with open(path_to_file, 'w') as off:
off.write('false ' + '\n')
Path.unlink(path_to_file)
tl = ListTunnels.tl_list()
if len(tl) == 0:
self.wg_autostart.configure(state='disabled')
if self.selected_option.get() >= 1:
with open(path_to_file, 'w') as set_on:
set_on.write('true ' + select_tl)
Path.write_text(path_to_file, select_tl)
except IndexError:
self.selected_option.set(1)
@ -273,17 +270,14 @@ class OnOff:
self.lb_frame_buttons = None
def on_off(self):
with open(path_to_file, 'r') as file:
for line in file.readlines():
a_connect = line
if 'true' in a_connect:
self.selected_option.set(1)
self.autoconnect_var.set('')
self.auto_con = a_connect[5:]
else:
self.wg_autostart.configure(state='disabled')
self.auto_con = 'no Autoconnect'
if Path.exists(path_to_file):
self.selected_option.set(1)
self.autoconnect_var.set('')
self.auto_con = Path.read_text(path_to_file)
else:
self.wg_autostart.configure(state='disabled')
self.auto_con = 'no Autoconnect'
self.autoconnect_var.set('')
self.autoconnect_var = tk.StringVar()
self.autoconnect_var.set(self.auto_con)
self.autoconnect = tk.Label(self, textvariable=self.autoconnect_var, fg='blue', padx=5)