Compare commits

...

1 Commits

Author SHA1 Message Date
f09e6eed0d in delete replace open with Path
install fixes
2024-09-15 02:09:43 +02:00
5 changed files with 46 additions and 40 deletions

View File

@ -4,8 +4,7 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <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"> <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$/message.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test.py" afterDir="false" /> <change afterPath="$PROJECT_DIR$/test.py" afterDir="false" />
<change afterPath="$PROJECT_DIR$/test2.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" /> <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" /> <option name="project" value="LOCAL" />
<updated>1725991610908</updated> <updated>1725991610908</updated>
</task> </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 /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -399,7 +406,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="ADD_EXTERNAL_FILES_SILENTLY" value="true" /> <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 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 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" /> <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" />
<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 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" /> <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> </component>
</project> </project>

View File

@ -8,20 +8,21 @@ config_path = Path.home() / ".config" / "wire_py" / "wg_py"
start_file = f'''\ start_file = f'''\
#!/usr/bin/python3 #!/usr/bin/python3
from subprocess import check_call 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) Path("start_wg.py").write_text(start_file)
config_path.parent.mkdir(exist_ok=True) 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 # Prompt the user for the sudo password
#sudo_password = getpass('Enter 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) self.btn_i.grid(column=0, row=1, padx=15, pady=8)
def delete(): def delete():
try: try:
self.select_tunnel = self.l_box.curselection() self.select_tunnel = self.l_box.curselection()
select_tl = self.l_box.get(self.select_tunnel[0]) select_tl = self.l_box.get(self.select_tunnel[0])
check_call(['nmcli', 'connection', 'delete', select_tl]) check_call(['nmcli', 'connection', 'delete', select_tl])
self.l_box.delete(self.select_tunnel[0]) 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' path_to_file = Path.home() / '.config/wire_py/wg_py'
with open(path_to_file, 'r') as file2: if Path.exists(path_to_file):
for line in file2.readlines(): a_con = Path.read_text(path_to_file)
a_con = line[5:]
if select_tl == a_con: if select_tl == a_con:
self.selected_option.set(0) self.selected_option.set(0)
self.autoconnect_var.set('no Autoconnect') self.autoconnect_var.set('no Autoconnect')
Path.unlink(path_to_file)
# for disable checkbox when Listbox empty # for disable checkbox when Listbox empty
tl = ListTunnels.tl_list() tl = ListTunnels.tl_list()
if len(tl) == 0: if len(tl) == 0:
self.wg_autostart.configure(state='disabled') self.wg_autostart.configure(state='disabled')
with open(path_to_file, 'w') as file2: Path.unlink(path_to_file)
file2.write('false')
if self.a != '' and self.a == select_tl: if self.a != '' and self.a == select_tl:
self.StrVar.set(value='') self.StrVar.set(value='')

View File

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