Skip to content

Commit db4c86c

Browse files
committed
1.1.3
1 parent 85494dc commit db4c86c

File tree

4 files changed

+75
-32
lines changed

4 files changed

+75
-32
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __pycache__/
33
*.pyc
44
*.pyo
55
*$py.class
6+
theUnixManager.egg-info/
67

78
# Pyinstaller:
89
dist/

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# theUnixManager v1.1.1-stable
1+
# theUnixManager v1.1.3-stable
22

33
Next stable release of theUnixManager python version.
44

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
setup(
1616
name="theUnixManager",
17-
version="1.1.1",
17+
version="1.1.3",
1818
license="GNU Lesser General Public License v3, see LICENSE-LGPL.md file",
1919
author="Archetypum",
2020
author_email="archetypum@tutamail.com",
@@ -23,7 +23,7 @@
2323
),
2424
long_description=long_description,
2525
url="https://github.com/Archetypum/theUnixManager",
26-
download_url="https://github.com/Archetypum/theUnixManager/releases/tag/v1.1.1-stable",
26+
download_url="https://github.com/Archetypum/theUnixManager/releases/tag/v1.1.3-stable",
2727
packages=["the_unix_manager"],
2828
install_requires=[],
2929
classifiers=[

the_unix_manager/the_unix_manager.py

Lines changed: 71 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,12 @@
100100

101101
try:
102102
import os
103+
import shutil
103104
import platform
104105
import subprocess
105106
from sys import exit
106107
from time import sleep
107-
from typing import List
108+
from typing import List, NoReturn
108109
except ModuleNotFoundError as import_error:
109110
print(f"{RED}[!] Error: python modules not found. Broken installation?:\n{import_error}{RESET}")
110111

@@ -122,6 +123,62 @@ def the_unix_manager_version() -> str:
122123
return f"{RED}[!] Error: 'VERSION.txt' file not found.\nBroken installation?{RESET}"
123124

124125

126+
def generate_configs(log: bool = None) -> None:
127+
"""
128+
Generates config files for theUnixManager.
129+
130+
Args:
131+
log (bool): Enable/disable logging. None by default
132+
133+
Returns:
134+
NoReturn: [null].
135+
"""
136+
137+
the_unix_manager_config_path: str = "/etc/theunixmanager/python"
138+
the_unix_manager_version_path: str = "/etc/theunixmanager/python/VERSION.txt"
139+
the_unix_manager_preferred_editor_path: str = "/etc/theunixmanager/python/EDITOR.txt"
140+
the_unix_manager_root_command_path: str = "/etc/theunixmanager/python/COMMAND.txt"
141+
142+
try:
143+
if not os.path.exists(the_unix_manager_config_path):
144+
if log:
145+
print(f"{RED}[!] Error: '/etc/theunixmanager/python' not found.{RESET}")
146+
print(f"{BLUE}[<==] Creating directories...{RESET}")
147+
os.makedirs(the_unix_manager_config_path)
148+
else:
149+
if log:
150+
print(f"{GREEN}[*] theUnixManager config path found.{RESET}")
151+
152+
if not os.path.exists(the_unix_manager_version_path):
153+
if log:
154+
print(f"{RED}[!] Error: 'VERSION.txt' file not found.\nBroken installation?{RESET}")
155+
print(f"{BLUE}[<==] Creating file...{RESET}")
156+
subprocess.run(["touch", "/etc/theunixmanager/python/VERSION.txt"], check=True)
157+
else:
158+
if log:
159+
print(f"{GREEN}[*] theUnixManager version path found.{RESET}")
160+
161+
if not os.path.exists(the_unix_manager_preferred_editor_path):
162+
if log:
163+
print(f"{RED}[!] Error: 'EDITOR.txt' not found.\nBroken installation?{RESET}")
164+
print(f"{BLUE}[<==] Creating file...{RESET}")
165+
subprocess.run(["touch", "/etc/theunixmanager/python/EDITOR.txt"], check=True)
166+
else:
167+
if log:
168+
print(f"{GREEN}[*] theUnixManager preferred editor path found.{RESET}")
169+
170+
if not os.path.exists(the_unix_manager_root_command_path):
171+
if log:
172+
print(f"{RED}[!] Error: 'COMMAND.txt' not found.\nBroken installation?{RESET}")
173+
print(f"{BLUE}[<==] Creating file...{RESET}")
174+
subprocess.run(["touch", "/etc/theunixmanager/python/COMMAND.txt"], check=True)
175+
else:
176+
if log:
177+
print(f"{GREEN}[*] theUnixManager root command path found.{RESET}")
178+
except subprocess.CalledProcessError:
179+
pass
180+
181+
125182
def the_unix_manager_tester() -> None:
126183
"""
127184
Autotests.
@@ -528,58 +585,42 @@ def get_init_system() -> str:
528585

529586
def get_preferred_editor() -> str:
530587
"""
531-
Gets user preffered text editor and stores it in '/etc/theunixmanager/bash/EDITOR.txt'.
588+
Gets user preferred text editor and stores it in '/etc/theunixmanager/python/EDITOR.txt'.
532589
533590
Returns:
534591
text_editor (str): User's preferred editor.
535592
"""
536593

537594
editor_config_path: str = "/etc/theunixmanager/python/EDITOR.txt"
538595

539-
if os.path.isfile(editor_file):
540-
with open(editor_file, "r") as editor_config_file:
596+
if os.path.isfile(editor_config_path):
597+
with open(editor_config_path, "r") as editor_config_file:
541598
stored_editor: str = editor_config_file.read().strip()
542599
if stored_editor:
543600
return stored_editor
544601

545602
print(f"{ORANGE}\n[!] Error: No preferred editor found at {editor_config_path}.{RESET}")
546603
user_editor: str = input("[==>] Enter your preferred editor manually: ")
547-
with open(editor_file, "w") as editor_config_file:
548-
file.write(user_editor)
604+
with open(editor_config_path, "w") as editor_config_file:
605+
editor_config_file.write(user_editor)
549606

550607
return user_editor
551608

552609

553610
def sudo_or_doas() -> str | None:
554611
"""
555-
Checks for the preferred command (either sudo or doas) in '/etc/theunixmanager/bash/COMMAND.txt'.
556-
If no preference is found, it checks whether sudo or doas is available on the system and stores
557-
the preference accordingly. If both are available, sudo is chosen.
612+
Checks whether sudo or doas is available on the system and stores
613+
the preference accordingly.
558614
559615
Returns:
560-
result (str): The preferred command ('sudo' or 'doas').
616+
result (str | None): The preferred command ('sudo' or 'doas').
561617
"""
562-
563-
command_file: str = "/etc/theunixmanager/python/EDITOR.txt"
564-
565-
if os.path.isfile(command_file):
566-
with open(command_file, "r") as command_config_file:
567-
stored_command: str = command_config_file.read().strip()
568-
if stored_command in ["sudo", "doas"]:
569-
return stored_command
570618

571-
if which("sudo"):
572-
with open(command_file, "w") as command_config_file:
573-
command_config_file.write("sudo")
619+
if shutil.which("sudo"):
574620
return "sudo"
575-
576-
elif which("doas"):
577-
with open(command_file, "w") as file:
578-
file.write("doas")
621+
elif shutil.which("doas"):
579622
return "doas"
580-
581623
else:
582-
print(f"{RED}[!] Error: Neither sudo nor doas is available.{RESET}")
583624
return None
584625

585626

@@ -2282,6 +2323,7 @@ def check_privileges(log: bool = False) -> bool:
22822323
exit(1)
22832324

22842325

2285-
# if __name__ == "__main__":
2286-
# check_privileges()
2326+
if __name__ == "__main__":
2327+
check_privileges()
2328+
generate_configs()
22872329
# the_unix_manager_tester()

0 commit comments

Comments
 (0)