Skip to content

Commit

Permalink
So many new things. Read description
Browse files Browse the repository at this point in the history
-- spkg v1.4.4 --
- Plugin Marketplace for browsing available plugins
- Plugin Market Lister for listing available plugins in a compact form
- Plugin Installer for installing new plugins
- Language Fixes
- Added list command to the help command (Why wasn't it added???)
- Changed order of commands in the help command
- Fixed Formatting Errors
- Alias for config (conf)
- Added Table plugins to the Package Database (package.db)
- Added rmcache.sh Script for removing the __pycache__ directories before publishing to github
- General Plugin Update
- Added requirements.txt
- Patched spkg-scripts for configuring spkg after installing it
  • Loading branch information
Juliandev02 authored Apr 29, 2023
1 parent 4577208 commit 6641209
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 13 deletions.
Binary file modified package.db
Binary file not shown.
82 changes: 80 additions & 2 deletions plugin_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from sys import exit
import importlib
import sqlite3 as sql
from halo import Halo
import urllib
from urllib.error import HTTPError
import time

class Colors:
BOLD = '\033[1m'
Expand Down Expand Up @@ -44,6 +48,14 @@ class Colors:
UserConfigNotExists = f"{Fore.RED + Colors.BOLD}Error:{Fore.RESET + Colors.RESET} Deine Nutzerkonfiguration existiert nicht."
PackageDatabaseNotSynced = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} Die Paketdatenbank wurde noch nicht synchronisiert. Führe {Fore.CYAN}spkg sync{Fore.RESET} aus, um die Datenbank zu synchronisieren{Colors.RESET}"
PluginMarketplace = "Advanced Source Package Managment - Plugin Marketplace"
UsageInstall = f"{Fore.CYAN + Colors.BOLD}Aufruf:{Fore.RESET} spkg plugin get{Fore.GREEN} [Plugin]\n"
SearchingDatabaseForPackage = f"{Colors.BOLD}Durchsuche Datenbank nach Plugin ...{Colors.RESET}"
StrGet = "Holen"
FinishedDownloading = f"Download abgeschlossen für"
UnknownError = f"{Fore.RED + Colors.BOLD}[?]{Fore.RESET} Unbekannter Fehler{Colors.RESET}"
PackageNotFound = f"{Fore.RED + Colors.BOLD}[E]{Fore.RESET} Plugin wurde nicht gefunden{Colors.RESET}"
Canceled = f"{Fore.RED + Colors.BOLD}[!!!]{Fore.RESET} Prozess wurde abgebrochen!{Colors.RESET}"
PluginInstalledSuccess = f"{Colors.BOLD}Plugin {Fore.CYAN}%s{Fore.RESET} wurde installiert{Colors.RESET}"

elif language == "en":
PluginManagement = "Plugin Management"
Expand All @@ -59,6 +71,15 @@ class Colors:
ErrCode = "Errorcode"
UserConfigNotExists = f"{Fore.RED + Colors.BOLD}Error:{Fore.RESET + Colors.RESET} Your user configuration doesn't exist."
PackageDatabaseNotSynced = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} The package database has not been synchronized yet. Run {Fore.CYAN}spkg sync{Fore.RESET} to synchronize the database{Colors.RESET}"
PluginMarketplace = "Advanced Source Package Managment - Plugin Marketplace"
UsageInstall = f"{Fore.CYAN + Colors.BOLD}Usage:{Fore.RESET} spkg plugin get{Fore.GREEN} [plugin]\n"
SearchingDatabaseForPackage = f"{Colors.BOLD}Searching through the database ...{Colors.RESET}"
StrGet = "Get"
FinishedDownloading = f"Finished downloading"
UnknownError = f"{Fore.RED + Colors.BOLD}[?]{Fore.RESET} Unknown Error{Colors.RESET}"
PackageNotFound = f"{Fore.RED + Colors.BOLD}[E]{Fore.RESET} Plugin not found{Colors.RESET}"
Canceled = f"{Fore.RED + Colors.BOLD}[!!!]{Fore.RESET} Process canceled!{Colors.RESET}"
PluginInstalledSuccess = f"{Colors.BOLD}Plugin {Fore.CYAN}%s{Fore.RESET} has been installed{Colors.RESET}"


# Try to connect to the locally saved package database
Expand Down Expand Up @@ -114,6 +135,7 @@ def list_plugins():
except FileNotFoundError:
print(UserConfigNotExists)


def exec(cmd):
try:
plugin_handler = module.PluginHandler
Expand All @@ -125,7 +147,8 @@ def exec(cmd):


def marketplace():
print(f"{Colors.BOLD + Colors.UNDERLINE + Fore.CYAN}{PluginMarketplace}\n")
print(f"{Colors.BOLD + Colors.UNDERLINE + Fore.CYAN}{PluginMarketplace}")
print(UsageInstall)
try:
c.execute("SELECT * FROM plugins")
for row in c:
Expand All @@ -137,4 +160,59 @@ def marketplace():
exit()

except OperationalError:
print(PackageDatabaseNotSynced)
print(PackageDatabaseNotSynced)


def get(name):
spinner_db_search = Halo(text=f"{SearchingDatabaseForPackage}", spinner={'interval': 150, 'frames': ['[-]', '[\\]', '[|]', '[/]']}, text_color="white", color="green")
spinner_db_search.start()


c.execute("SELECT name, fetch_url, filename FROM plugins where name = ?", (name,))

for row in c:
url = row[1]
filename = row[2]

spinner_db_search.stop()
print(f"{Fore.GREEN + Colors.BOLD}[/] {Fore.RESET + Colors.RESET}{SearchingDatabaseForPackage}")

download_time_start = time.time()

spinner = Halo(text=f"{StrGet}: {url}", spinner={'interval': 150, 'frames': [
'[-]', '[\\]', '[|]', '[/]']}, text_color="white", color="green")
spinner.start()

try:
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
}
)

f = urllib.request.urlopen(req)



download_time_end = time.time()
# spinner.stop()
print(f"\n{FinishedDownloading} {Fore.LIGHTCYAN_EX + Colors.BOLD}{filename}{Colors.RESET} in {round(download_time_end - download_time_start, 2)} s{Colors.RESET}")

with open(f"/usr/share/spkg/plugins/{filename}", 'wb') as file:
file.write(f.read())

print(PluginInstalledSuccess % name)

except HTTPError as e:
print(UnknownError)
print(e)

except NameError as e:
print(f"\n{PackageNotFound}")
exit()

except KeyboardInterrupt as e:
print(f"\n{Canceled}")
exit()
2 changes: 2 additions & 0 deletions rmcache.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
sudo rm -r __pycache__/; sudo rm -r plugins/__pycache__; sudo rm -r src/__pycache__
49 changes: 38 additions & 11 deletions spkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Colors:
PluginIsAlreadyEnabled = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} Plugin ist bereits aktiviert.{Colors.RESET}"
PluginIsAlreadyDisabled = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} Plugin ist bereits deaktiviert.{Colors.RESET}"
MissingPermissonsPluginConfig = f"{Fore.RED + Colors.BOLD}Die Plugin-Config konnte nicht bearbeitet werden. (Wird spkg als Root ausgeführt?){Colors.RESET}"
MissingPermissonsPluginInstallation = f"{Fore.RED + Colors.BOLD}Das Plugin konnte nicht installiert werden. (Wird spkg als Root ausgeführt?){Colors.RESET}"
UnknownOperation = f"{Fore.RED + Colors.BOLD}[E]{Fore.RESET} Ungültige Operation: {Colors.RESET}"
MissingPermissonsSpkgConfig = f"{Fore.RED + Colors.BOLD}Die Spkg-Config konnte nicht bearbeitet werden. (Wird spkg als Root ausgeführt?){Colors.RESET}"
ChangedLanguage = f"{Colors.BOLD}Sprache wurde zu {Fore.CYAN}%s{Fore.RESET} geändert{Colors.RESET}"
Expand Down Expand Up @@ -139,6 +140,7 @@ class Colors:
PluginIsAlreadyEnabled = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} Plugin is already enabled.{Colors.RESET}"
PluginIsAlreadyDisabled = f"{Fore.RED + Colors.BOLD}[!]{Fore.RESET} Plugin is already disabled.{Colors.RESET}"
MissingPermissonsPluginConfig = f"{Fore.RED + Colors.BOLD}The plugin config could not be edited. (Is spkg running as root?){Colors.RESET}"
MissingPermissonsPluginInstallation = f"{Fore.RED + Colors.BOLD}The plugin could not be installed. (Is spkg running as root?){Colors.RESET}"
UnknownOperation = f"{Fore.RED + Colors.BOLD}[E]{Fore.RESET} Invalid Operation: {Colors.RESET}"
MissingPermissonsSpkgConfig = f"{Fore.RED + Colors.BOLD}The spkg config could not be edited. (Is spkg running as root?){Colors.RESET}"
ChangedLanguage = f"{Colors.BOLD}Changed language to {Fore.CYAN}%s{Fore.RESET}{Colors.RESET}"
Expand All @@ -153,20 +155,24 @@ def help_en():
print(f"By compiling the package, the program is optimized for your device and can run faster.")
print(f"So spkg offers you a high security, so you don't have to worry about viruses in packages.\n")
print(f"{Colors.UNDERLINE + Colors.BOLD}Commands:{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}info:{Fore.RESET} Gives you information about a specific package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}download:{Fore.RESET} Downloads a specific package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}install:{Fore.RESET} Installs the specified package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}install:{Fore.RESET} Reinstalls the specified package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}sync:{Fore.RESET} Syncronizes the package database{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}reinstall:{Fore.RESET} Reinstalls the specified package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}update:{Fore.RESET} Checks if an update is available for an installed package{Colors.RESET} (not available yet)")
print(f"{Colors.BOLD} -> {Fore.BLUE}upgrade:{Fore.RESET} Updates all available package updates{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}sync:{Fore.RESET} Syncronizes the package database{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}info:{Fore.RESET} Gives you information about a specific package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}info:{Fore.RESET} Lists all available packages{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}download:{Fore.RESET} Downloads a specific package{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}build:{Fore.RESET} Builts various things{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}world:{Fore.RESET} Rebuilds the World database{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}plugins:{Fore.RESET} Plugin manager{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}list:{Fore.RESET} Lists all plugins{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}exec:{Fore.RESET} Executes a command from the plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}enable:{Fore.RESET} Enables a Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}disable:{Fore.RESET} Disables a Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}marketplace/market:{Fore.RESET} Plugin Marketplace{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}list:{Fore.RESET} Lists available Plugins{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}get:{Fore.RESET} Installs a Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}config:{Fore.RESET} Configuration manager{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}language:{Fore.RESET} Configure the language of spkg{Colors.RESET}")
print(f"\n{Colors.BOLD}Copyright Juliandev02 2023 (C) - Made with <3")
Expand All @@ -181,20 +187,24 @@ def help_de():
print(f"Durch das kompilieren des Paketes ist das Programm für dein Gerät optimiert und kann schneller laufen.")
print(f"So bietet dir spkg eine hohe Sicherheit, sodass du dir keine Sorgen um Viren in Paketen machen musst.\n")
print(f"{Colors.UNDERLINE + Colors.BOLD}Befehle:{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}info:{Fore.RESET} Gibt dir Informationen über ein bestimmtes Paket aus{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}download:{Fore.RESET} Lädt ein bestimmtes Paket herunter{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}install:{Fore.RESET} Installiert das angegebene Paket{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}reinstall:{Fore.RESET} Installiert das angegebene Paket neu{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}sync:{Fore.RESET} Syncronisiert die Paketdatenbank{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}update:{Fore.RESET} Überprüft, ob ein Update für die installierten Pakete verfügbar ist{Colors.RESET} (Noch nicht verfügbar)")
print(f"{Colors.BOLD} -> {Fore.BLUE}upgrade:{Fore.RESET} Aktualisiert alle verfügbaren Paketupdates{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}sync:{Fore.RESET} Syncronisiert die Paketdatenbank{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}info:{Fore.RESET} Gibt dir Informationen über ein bestimmtes Paket aus{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}list:{Fore.RESET} Zählt alle verfügbaren Pakete auf{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}download:{Fore.RESET} Lädt ein bestimmtes Paket herunter{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}build:{Fore.RESET} Erstellt verschiedene Dinge{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}world:{Fore.RESET} Baut die World Datenbank neu auf{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}plugins:{Fore.RESET} Plugin Verwaltung{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}list:{Fore.RESET} Zählt alle Plugins auf{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}exec:{Fore.RESET} Führt einen Befehl vom Plugin aus{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}enable:{Fore.RESET} Aktiviert ein Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}disable:{Fore.RESET} Deaktiviert ein Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}marketplace/market:{Fore.RESET} Plugin Marketplace{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}list:{Fore.RESET} Zählt verfügbare Plugins auf{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}get:{Fore.RESET} Installiert ein Plugin{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}config:{Fore.RESET} Konfigurationsverwaltung{Colors.RESET}")
print(f"{Colors.BOLD} -> {Fore.BLUE}language:{Fore.RESET} Konfiguriere die Sprache von spkg{Colors.RESET}")
print(f"\n{Colors.BOLD}Copyright Juliandev02 2023 (C) - Made with <3")
Expand Down Expand Up @@ -400,6 +410,10 @@ def help_de():
print(f"{Fore.CYAN + Colors.BOLD}{filename}{Fore.RESET}{MissingPermissons}")
print(MissingPermissonsPackageDatabaseUpdate)
exit()

spinner = Halo(text=f"{SyncingPackageDatabase} {data['main']} ...", spinner={
'interval': 150, 'frames': ['[-]', '[\\]', '[|]', '[/]']}, text_color="white", color="green")
spinner.start()

try:
req = urllib.request.Request(
Expand All @@ -414,9 +428,7 @@ def help_de():

download_time_start = time.time()

spinner = Halo(text=f"{SyncingPackageDatabase} {data['main']} ...", spinner={
'interval': 150, 'frames': ['[-]', '[\\]', '[|]', '[/]']}, text_color="white", color="green")
spinner.start()


with open(filename, 'wb') as file:
file.write(f.read())
Expand Down Expand Up @@ -688,6 +700,21 @@ def help_de():

with open(enabled_plugins_cfg, 'w') as f:
json.dump(data, f)


# Installs a plugin
elif len(sys.argv) > 3 and sys.argv[2] == "get":
plugin = sys.argv[3]

if os.geteuid() == 0:
None

else:
print(f"{Fore.CYAN + Colors.BOLD}/usr/share/spkg/plugins/{Fore.RESET}{MissingPermissons}")
print(MissingPermissonsPluginInstallation)
exit()

plugin_management.get(plugin)

# Execution of a plugin-command without 'exec'
elif len(sys.argv) > 3:
Expand All @@ -705,7 +732,7 @@ def help_de():
else:
plugin_daemon.import_plugin(plugin)
plugin_management.exec(sys.argv[3])


# If no Argument was passed, print an error
else:
Expand Down

0 comments on commit 6641209

Please sign in to comment.