Skip to content

Commit 2850d38

Browse files
author
Stew Alexander
committed
Add concise, meaningful comments explaining what and how
- Added sparse comments to Desktop-Linux-Tools.py explaining error handling, installation methods, and key logic - Added comments to Debian-CLI-Tool_Installer.py clarifying system checks, package verification, and binary installation - Comments focus on why decisions were made and how operations work
1 parent d367e96 commit 2850d38

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

Debian-CLI-Tool_Installer.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
file_pass = 'a'
2222

23-
#Check if the system is debian, else halt program
23+
# Verify Debian-based system via apt-get presence
2424
is_debian = which("apt-get")
2525

2626
if is_debian:
@@ -61,7 +61,7 @@
6161

6262

6363

64-
#Check if these programs exist [chkservice,htop,nnn,ncdu,network-manager,ne,hping3,nmap,lynis,apt-show-versions,vim,fish,tig,bmon,dnsutils,most], if not install them
64+
# Check each program in PATH; install missing ones via apt
6565
def check_programs():
6666
programs = ['chkservice','htop','nnn','ncdu','network-manager','ne','hping3','nmap','lynis','apt-show-versions','vim','fish','tig','bmon','dnsutils','most','curl']
6767
os.system('sudo apt update')
@@ -73,7 +73,7 @@ def check_programs():
7373
print("- \"" + program + '\" is installed')
7474

7575

76-
# Check if program in list programs appears to be available in apt, if so download it
76+
# Verify package exists in apt cache before installing
7777
def install_program(program):
7878
try:
7979
output = subprocess.run(["apt-cache", "search",program], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
@@ -86,21 +86,19 @@ def install_program(program):
8686
print(f"Error: {e}")
8787

8888

89-
#Check if eget is installed, if not install eget
89+
# Install eget if missing; downloads to current dir, then moves to /usr/bin
9090
def eget_installer ():
91-
#check if eget exists as a program
9291
eget_exists = os.path.exists('/usr/bin/eget')
9392
if not eget_exists:
9493
print("Eget does not exist, installing",'\n')
95-
#install eget
94+
# Pipe curl output directly to sh for installation
9695
os.system("curl https://zyedidia.github.io/eget.sh | sh")
97-
#move eget to /usr/bin
9896
os.system("sudo mv eget /usr/bin/eget")
9997
else:
10098
print("- \"eget\" is is installed",'\n')
10199
pass
102100

103-
#Install eget programs from github source
101+
# Download binaries from GitHub releases using eget
104102
def eget_install():
105103
if eget_program == 'lsd':
106104
os.system("eget Peltoche/lsd")
@@ -112,8 +110,7 @@ def eget_install():
112110
print('Program not found\n')
113111

114112

115-
#Copies the file downloaded via eget to the /usr/bin/
116-
113+
# Move eget-downloaded binaries from current dir to PATH
117114
def eget_copy():
118115
for eget_program in eget_programs:
119116
if os.path.exists(eget_program):

Desktop-Linux-Tools.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,15 @@ def run_command(cmd: List[str], check: bool = False, capture_output: bool = Fals
8282
timeout=timeout
8383
)
8484
except subprocess.TimeoutExpired:
85+
# Return CompletedProcess with timeout exit code (124) to avoid crashes
8586
print(f"Command timed out after {timeout}s: {' '.join(cmd)}")
86-
return subprocess.CompletedProcess(cmd, 124) # 124 is timeout exit code
87+
return subprocess.CompletedProcess(cmd, 124)
8788
except subprocess.CalledProcessError as e:
8889
print(f"Error running command: {' '.join(cmd)}")
8990
print(f"Error: {e}")
9091
return e
9192
except FileNotFoundError:
93+
# Command missing from PATH - return error code without crashing
9294
print(f"Command not found: {cmd[0]}")
9395
return subprocess.CompletedProcess(cmd, 1)
9496

@@ -138,7 +140,7 @@ def install_via_eget(repo: str, binary_name: str) -> bool:
138140
)
139141

140142
if result.returncode == 0 and os.path.exists(binary_name):
141-
# Move to /usr/local/bin (better than /usr/bin for user-installed tools)
143+
# eget downloads to current dir; move to PATH for system-wide access
142144
move_cmd = ["sudo", "mv", binary_name, "/usr/local/bin/"]
143145
move_result = Installer.run_command(move_cmd)
144146
return move_result.returncode == 0
@@ -148,10 +150,11 @@ def install_via_eget(repo: str, binary_name: str) -> bool:
148150
def install_eget() -> bool:
149151
"""Install eget if not present."""
150152
print("Installing eget...")
153+
# Timeout flags prevent hanging on slow networks; pipe directly to sh for install
151154
result = Installer.run_command(
152155
["sh", "-c", "curl --connect-timeout 10 --max-time 30 https://zyedidia.github.io/eget.sh | sh"],
153156
capture_output=True,
154-
timeout=60 # Longer timeout for network operations
157+
timeout=60
155158
)
156159

157160
if result.returncode == 0 and os.path.exists("eget"):
@@ -173,6 +176,7 @@ def install_croc() -> bool:
173176
@staticmethod
174177
def check_apt_available(package: str) -> bool:
175178
"""Check if package is available in apt repositories."""
179+
# Regex anchors (^$) ensure exact match, not substring
176180
result = Installer.run_command(
177181
["apt-cache", "search", "--names-only", "^" + package + "$"],
178182
capture_output=True
@@ -413,6 +417,7 @@ def get_user_consent() -> bool:
413417
print(" • Skip tools that are already installed")
414418
print("\n" + "="*70)
415419

420+
# Limit retries to prevent infinite loops on invalid input
416421
max_attempts = 5
417422
attempts = 0
418423

@@ -431,6 +436,7 @@ def get_user_consent() -> bool:
431436
print("Maximum attempts reached. Defaulting to 'no'.")
432437
return False
433438
except (EOFError, KeyboardInterrupt):
439+
# Handle Ctrl+C and EOF gracefully without crashing
434440
print("\n\nInterrupted by user. Exiting.")
435441
return False
436442

@@ -480,6 +486,7 @@ def main():
480486
print(f"\n[{category}]")
481487
print("-" * 70)
482488

489+
# Sort alphabetically for consistent output
483490
for tool in sorted(tools, key=lambda t: t.name):
484491
if ToolManager.check_tool_installed(tool):
485492
print(f"✓ {tool.name:30} - Already installed")

0 commit comments

Comments
 (0)