initialise project
This commit is contained in:
Executable
+132
@@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
#importe
|
||||
from shutil import get_terminal_size
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import platform
|
||||
|
||||
#helper funktions
|
||||
def line(content=None):
|
||||
print("-"*int(get_terminal_size().columns))
|
||||
if content is not None:
|
||||
print(content)
|
||||
print("-"*int(get_terminal_size().columns))
|
||||
|
||||
def box(content):
|
||||
content_lines = content.split("\n")
|
||||
width = max(len(x) for x in content_lines)
|
||||
|
||||
print("+" + "-" * width + "+")
|
||||
|
||||
for text in content_lines:
|
||||
print("|" + text.ljust(width) + "|")
|
||||
|
||||
print("+" + "-"* width + "+")
|
||||
|
||||
path = os.path.join(os.path.dirname(__file__), "prg")
|
||||
|
||||
|
||||
programs = {}
|
||||
|
||||
for root, dirs, files in os.walk(path):
|
||||
matching = []
|
||||
|
||||
for f in files:
|
||||
if f.startswith("SJNet_") and f.endswith(".py"):
|
||||
matching.append(f)
|
||||
|
||||
if matching:
|
||||
folder = os.path.relpath(root, path)
|
||||
|
||||
if folder == ".":
|
||||
folder = ""
|
||||
|
||||
programs[folder] = matching
|
||||
|
||||
def detect():
|
||||
try:
|
||||
distro = platform.freedesktop_os_release()
|
||||
except:
|
||||
return
|
||||
|
||||
name = distro.get("NAME", "").lower()
|
||||
|
||||
if "arch" in name:
|
||||
box("Arch Linux detected.\nRespect. You chose the hard mode.")
|
||||
elif "gentoo" in name:
|
||||
box("Gentoo detected.\nThe compiler has awakened.")
|
||||
elif "debian" in name:
|
||||
box("Debian detected.\nStable mode activated.")
|
||||
elif "ubuntu" in name:
|
||||
box("Ubuntu detected.\nThe beginner gateway has opened.")
|
||||
elif os.geteuid() == 0:
|
||||
box("Running as root.\nPlease don't delete the universe.")
|
||||
|
||||
#main
|
||||
|
||||
|
||||
def menu():
|
||||
detect()
|
||||
|
||||
if not programs:
|
||||
box("Keine SJNet_*.py Programme gefunden.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
box("Available programs:")
|
||||
|
||||
counter = 1
|
||||
program_map = {}
|
||||
|
||||
for folder, files in programs.items():
|
||||
|
||||
if folder:
|
||||
print(folder)
|
||||
|
||||
for file in files:
|
||||
print(f" {counter}: {file}")
|
||||
|
||||
program_map[counter] = os.path.join(
|
||||
path,
|
||||
folder,
|
||||
file
|
||||
)
|
||||
|
||||
counter += 1
|
||||
|
||||
else:
|
||||
for file in files:
|
||||
print(f"{counter}: {file}")
|
||||
|
||||
program_map[counter] = os.path.join(
|
||||
path,
|
||||
file
|
||||
)
|
||||
|
||||
counter += 1
|
||||
|
||||
try:
|
||||
choose = int(input("enter number of the programm you want: > "))
|
||||
chosen = program_map[choose]
|
||||
|
||||
except ValueError:
|
||||
print("Es muss eine Nummer sein.")
|
||||
sys.exit(1)
|
||||
|
||||
except KeyError:
|
||||
print("Es muss eine der angebotenen Nummern sein.")
|
||||
sys.exit(1)
|
||||
|
||||
print("\n")
|
||||
try:
|
||||
subprocess.run([sys.executable, chosen])
|
||||
except KeyboardInterrupt:
|
||||
print("Interrupt signal recived...")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
|
||||
menu()
|
||||
Reference in New Issue
Block a user