From 43a37d11e19c019c9119de530b88335718b690d8 Mon Sep 17 00:00:00 2001
From: archetipico <43927507+archetipico@users.noreply.github.com>
Date: Tue, 16 Apr 2024 23:21:50 +0200
Subject: [PATCH 1/5] Huge refactor
---
.gitignore | 8 +-
setup.py | 24 ++++++
src/logo/big_name.svg | 78 +++++++++----------
src/package/MacOS/MacOSUpdate.sh | 29 -------
src/package/Windows/privileges.ps1 | 3 -
system/darwin/package/arm.sh | 31 ++++++++
.../debian.sh => system/linux/package/apt.sh | 11 +--
.../linux/package/emerge.sh | 0
.../Linux => system/linux/package}/flatpak.sh | 0
.../nix.sh => system/linux/package/nixos.sh | 0
.../arch.sh => system/linux/package/pacman.sh | 4 -
.../termux.sh => system/linux/package/pkg.sh | 0
.../Linux => system/linux/package}/rpm.sh | 0
.../Linux => system/linux/package}/snap.sh | 0
system/linux/package/yay.sh | 13 ++++
.../linux/package/zypper.sh | 0
system/windows/package/choco.ps1 | 3 +
system/windows/package/nuget.ps1 | 3 +
system/windows/package/scoop.ps1 | 3 +
.../Windows => system/windows}/winUpdate.ps1 | 44 +++++++----
utils.py | 53 +++++++++++++
21 files changed, 207 insertions(+), 100 deletions(-)
create mode 100644 setup.py
delete mode 100644 src/package/MacOS/MacOSUpdate.sh
delete mode 100644 src/package/Windows/privileges.ps1
create mode 100644 system/darwin/package/arm.sh
rename src/package/Linux/debian.sh => system/linux/package/apt.sh (84%)
mode change 100755 => 100644
rename src/package/Linux/gentoo.sh => system/linux/package/emerge.sh (100%)
mode change 100755 => 100644
rename {src/package/Linux => system/linux/package}/flatpak.sh (100%)
mode change 100755 => 100644
rename src/package/Linux/nix.sh => system/linux/package/nixos.sh (100%)
mode change 100755 => 100644
rename src/package/Linux/arch.sh => system/linux/package/pacman.sh (81%)
mode change 100755 => 100644
rename src/package/Linux/termux.sh => system/linux/package/pkg.sh (100%)
mode change 100755 => 100644
rename {src/package/Linux => system/linux/package}/rpm.sh (100%)
mode change 100755 => 100644
rename {src/package/Linux => system/linux/package}/snap.sh (100%)
mode change 100755 => 100644
create mode 100644 system/linux/package/yay.sh
rename src/package/Linux/opensuse.sh => system/linux/package/zypper.sh (100%)
mode change 100755 => 100644
create mode 100644 system/windows/package/choco.ps1
create mode 100644 system/windows/package/nuget.ps1
create mode 100644 system/windows/package/scoop.ps1
rename {src/package/Windows => system/windows}/winUpdate.ps1 (70%)
create mode 100644 utils.py
diff --git a/.gitignore b/.gitignore
index 7297e23..78aa392 100644
--- a/.gitignore
+++ b/.gitignore
@@ -5,4 +5,10 @@ src/utils/.md5
*.aux
*.log
*.synctex.gz
-.idea
\ No newline at end of file
+.idea
+
+
+
+
+__pycache__/
+cache.json
\ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..fca4693
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,24 @@
+from colorama import init, Fore
+from platform import system
+from utils import check_packages, update_cache
+
+# Initialize colorama
+init()
+
+# Check system
+match system():
+ case 'Darwin':
+ # Update system in cache
+ update_cache({'system': 'darwin'})
+ print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
+ check_packages()
+ case 'Linux':
+ # Update system in cache
+ update_cache({'system': 'linux'})
+ print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
+ check_packages()
+ case 'Windows':
+ # Update system in cache
+ update_cache({'system': 'windows'})
+ print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
+ check_packages()
diff --git a/src/logo/big_name.svg b/src/logo/big_name.svg
index 4153f9b..6448645 100644
--- a/src/logo/big_name.svg
+++ b/src/logo/big_name.svg
@@ -1,40 +1,38 @@
-
-
+
\ No newline at end of file
diff --git a/src/package/MacOS/MacOSUpdate.sh b/src/package/MacOS/MacOSUpdate.sh
deleted file mode 100644
index 3862175..0000000
--- a/src/package/MacOS/MacOSUpdate.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/bash
-#Fetch MacOS version
-osVersion=$(sw_vers -productVersion)
-
-installerPath=""
-#Get major and minor version
-majorVersion=$(echo $osVersion | cut -d "." -f 1)
-minorVersion=$(echo $osVersion | cut -d "." -f 2)
-
-#Check which version is installed
-if [ $majorVersion == "12" ];then
- installerPath="install macOS Monterey.app"
-elif [ $majorVersion == "11" ];then
- installerPath="Install macOS Big Sur.app"
-elif [ $minorVersion == "15"* ];then
- installerPath="Install macOS Catalina.app"
-elif
- echo "Unsupported MacOS version."
- exit 1
-fi
-
-#get full path
-fullPath="/Applications/$installerPath/Contents/Resources/startosinstall"
-
-#command which updates system
-softwareupdate --fetch-full-installer –full-installer-version $osVersion
-echo "Inserire la password:"
-#get privileges
-sudo "$fullPath" --agreetolicense --forcequitapps --nointeraction --user "$USER"
diff --git a/src/package/Windows/privileges.ps1 b/src/package/Windows/privileges.ps1
deleted file mode 100644
index 15b4fb3..0000000
--- a/src/package/Windows/privileges.ps1
+++ /dev/null
@@ -1,3 +0,0 @@
-# Start Powershell as administrator
-Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"winUpdate.ps1`""
-
diff --git a/system/darwin/package/arm.sh b/system/darwin/package/arm.sh
new file mode 100644
index 0000000..94578bd
--- /dev/null
+++ b/system/darwin/package/arm.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+osVersion=$(sw_vers -productVersion)
+
+installerPath=""
+# Extract major and minor version numbers
+majorVersion=$(echo $macOSVersion | cut -d '.' -f 1)
+minorVersion=$(echo $macOSVersion | cut -d '.' -f 2)
+
+# Check which version is installed
+if [ $majorVersion == "11" ]; then
+ installerPath="Install macOS Big Sur.app"
+elif [ $majorVersion == "12" ]; then
+ installerPath="Install macOS Monterey.app"
+elif [ $majorVersion == "13" ]; then
+ installerPath="Install macOS Ventura.app"
+elif [ $majorVersion == "14" ]; then
+ installerPath="Install macOS Sonoma.app"
+else
+ echo "Unsupported MacOS version."
+ exit 1
+fi
+
+# Get full path
+fullPath="/Applications/$installerPath/Contents/Resources/startosinstall"
+
+# Command which updates system
+softwareupdate --fetch-full-installer –full-installer-version $osVersion
+echo "Insert password:"
+# Get privileges
+sudo "$fullPath" --agreetolicense --forcequitapps --nointeraction --user "$USER"
diff --git a/src/package/Linux/debian.sh b/system/linux/package/apt.sh
old mode 100755
new mode 100644
similarity index 84%
rename from src/package/Linux/debian.sh
rename to system/linux/package/apt.sh
index dc26403..4960a70
--- a/src/package/Linux/debian.sh
+++ b/system/linux/package/apt.sh
@@ -6,15 +6,12 @@ source $SRC/utils/global.sh
PWR=$(source $SRC/utils/check_pwr.sh)
PKG="apt-get"
-
if [[ $(command -v apt) ]]; then
PKG="apt"
-
- #These lines works on some systems only, for example I receive an error on a raspberry.
- #puts RED "configuration: starting"
- #try $PWR $PKG --configure -a
- #puts GREEN "configuration: completed"
- #puts RED "Error on --configure option"
+
+ puts RED "configuration: starting"
+ try $PWR $PKG --configure -a
+ puts GREEN "configuration: completed"
puts BLUE "Using $PKG $DEBIAN"
diff --git a/src/package/Linux/gentoo.sh b/system/linux/package/emerge.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/gentoo.sh
rename to system/linux/package/emerge.sh
diff --git a/src/package/Linux/flatpak.sh b/system/linux/package/flatpak.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/flatpak.sh
rename to system/linux/package/flatpak.sh
diff --git a/src/package/Linux/nix.sh b/system/linux/package/nixos.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/nix.sh
rename to system/linux/package/nixos.sh
diff --git a/src/package/Linux/arch.sh b/system/linux/package/pacman.sh
old mode 100755
new mode 100644
similarity index 81%
rename from src/package/Linux/arch.sh
rename to system/linux/package/pacman.sh
index a98b49b..c404a7a
--- a/src/package/Linux/arch.sh
+++ b/system/linux/package/pacman.sh
@@ -19,7 +19,3 @@ puts GREEN "upgrade: completed"
puts RED "clean pacman caches: starting"
try $PWR paccache -r
puts GREEN "clean pacman caches: starting"
-
-puts RED "update AUR packages: starting"
-try yay -Syu
-puts GREEN "update AUR packages: starting"
diff --git a/src/package/Linux/termux.sh b/system/linux/package/pkg.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/termux.sh
rename to system/linux/package/pkg.sh
diff --git a/src/package/Linux/rpm.sh b/system/linux/package/rpm.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/rpm.sh
rename to system/linux/package/rpm.sh
diff --git a/src/package/Linux/snap.sh b/system/linux/package/snap.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/snap.sh
rename to system/linux/package/snap.sh
diff --git a/system/linux/package/yay.sh b/system/linux/package/yay.sh
new file mode 100644
index 0000000..28b31da
--- /dev/null
+++ b/system/linux/package/yay.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+SRC=$(dirname "$(readlink -f "$0")")
+source $SRC/utils/global.sh
+
+PWR=$(source $SRC/utils/check_pwr.sh)
+PKG="yay"
+
+puts BLUE "Using $PKG $ARCH"
+
+puts RED "update AUR packages: starting"
+try $PKG -Syu
+puts GREEN "update AUR packages: starting"
diff --git a/src/package/Linux/opensuse.sh b/system/linux/package/zypper.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/package/Linux/opensuse.sh
rename to system/linux/package/zypper.sh
diff --git a/system/windows/package/choco.ps1 b/system/windows/package/choco.ps1
new file mode 100644
index 0000000..921f984
--- /dev/null
+++ b/system/windows/package/choco.ps1
@@ -0,0 +1,3 @@
+Write-Host "Updating Chocolatey packages ..."
+choco upgrade all -y
+Write-Host "Chocolatey packages updated"
\ No newline at end of file
diff --git a/system/windows/package/nuget.ps1 b/system/windows/package/nuget.ps1
new file mode 100644
index 0000000..ae7c9be
--- /dev/null
+++ b/system/windows/package/nuget.ps1
@@ -0,0 +1,3 @@
+Write-Host "Updating NuGet packages ..."
+Update-Package
+Write-Host "NuGet packages updated"
\ No newline at end of file
diff --git a/system/windows/package/scoop.ps1 b/system/windows/package/scoop.ps1
new file mode 100644
index 0000000..5abfe2d
--- /dev/null
+++ b/system/windows/package/scoop.ps1
@@ -0,0 +1,3 @@
+Write-Host "Updating Scoop packages ..."
+scoop update
+Write-Host "Scoop packages updated"
\ No newline at end of file
diff --git a/src/package/Windows/winUpdate.ps1 b/system/windows/winUpdate.ps1
similarity index 70%
rename from src/package/Windows/winUpdate.ps1
rename to system/windows/winUpdate.ps1
index f5cb2b6..1627815 100644
--- a/src/package/Windows/winUpdate.ps1
+++ b/system/windows/winUpdate.ps1
@@ -1,4 +1,27 @@
-# This script is focused on update Windows OS
+# TODO RIMUOVERE
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Start-Process powershell -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"winUpdate.ps1`""
# Install PSWindowsUpdate if not installed
if (!(Get-Module -Name PSWindowsUpdate -ListAvailable)) {
@@ -7,20 +30,16 @@ if (!(Get-Module -Name PSWindowsUpdate -ListAvailable)) {
}
# Windows Update
-Write-Host "Updating Windows..."
-Write-Host "At the end your system will be rebooted..."
-Get-WUInstall -AcceptAll -AutoReboot
+Write-Host "Updating Windows ..."
+Write-Host "At the end reboot your system"
+Get-WUInstall -AcceptAll
####### Check installation and update of Chocolatey #######
# If you wanna install Chocolatey, you need this command
# Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
if (!(Get-Command choco -ErrorAction SilentlyContinue)) {
- Write-Host "Chocolatey not found. Skipping..."
-} else {
- Write-Host "Chocolatey is installed..."
- Write-Host "Updating Chocolatey packages..."
- choco upgrade all -y
+ #Write-Host "Chocolatey not found. Skipping..."
}
######## Check installation and update Nuget #######
@@ -29,10 +48,6 @@ if (!(Get-Command choco -ErrorAction SilentlyContinue)) {
# Move-Item -Path "$env:temp\nuget.exe" -Destination "$env:ProgramFiles\NuGet" -Force
if (!(Get-Command nuget -ErrorAction SilentlyContinue)) {
Write-Host "NuGet not found. Skipping..."
-} else {
- Write-Host "NuGet is installed..."
- Write-Host "Updating Nuget packages..."
- Update-Package -ProjectName YourProjectName -Reinstall
}
####### Check installation and update scoop #######
@@ -40,9 +55,6 @@ if (!(Get-Command nuget -ErrorAction SilentlyContinue)) {
# Set-ExecutionPolicy RemoteSigned -scope Process; iex (new-object net.webclient).downloadstring('https://get.scoop.sh')
if (!(Test-Path $env:USERPROFILE\scoop)) {
Write-Host "Scoop not found. Skipping..."
-} else {
- Write-Host "Scoop is installed..."
- scoop update
}
Write-Host "Update completed."
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..dbb306a
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,53 @@
+from colorama import Fore
+from json import dump, load
+from os import path
+from shutil import which
+
+CACHE_PATH = 'cache.json'
+PACKAGES = {
+ "apt-get": "apt",
+ "osascript": "arm",
+ "choco": "choco",
+ "emerge": "emerge",
+ "flatpak": "flatpak",
+ "nixos-rebuild": "nixos",
+ "nuget": "nuget",
+ "scoop": "scoop",
+ "pacman": "pacman",
+ "pkg": "pkg",
+ "rpm": "rpm",
+ "snap": "snap",
+ "yay": "yay",
+ "zypper": "zypper"
+}
+
+# Add value to caches
+def update_cache(kv):
+ try:
+ # If the file exists
+ if path.exists(CACHE_PATH):
+ # Load its content
+ with open(CACHE_PATH, 'r') as file:
+ data = load(file)
+ else:
+ # New cache
+ data = {}
+
+ # Add data to the cache
+ data.update(kv)
+
+ # Write the updated data back to the file
+ with open(CACHE_PATH, 'w') as file:
+ dump(data, file, indent=4)
+ except Exception as e:
+ print(e)
+
+def check_packages():
+ # For each package check if it exists and add it to the cache
+ installed_packages = []
+ for k in PACKAGES.keys():
+ path = which(k)
+ if path:
+ installed_packages.append(k)
+ update_cache({'packages': installed_packages})
+ print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
From 0a2df2e39b7a3fb1b6bb11fd7cfdff1cea8a345a Mon Sep 17 00:00:00 2001
From: archetipico <43927507+archetipico@users.noreply.github.com>
Date: Tue, 16 Apr 2024 23:40:04 +0200
Subject: [PATCH 2/5] Fix
---
utils.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/utils.py b/utils.py
index dbb306a..8ab3fde 100644
--- a/utils.py
+++ b/utils.py
@@ -45,9 +45,9 @@ def update_cache(kv):
def check_packages():
# For each package check if it exists and add it to the cache
installed_packages = []
- for k in PACKAGES.keys():
- path = which(k)
+ for key, value in PACKAGES.items():
+ path = which(key)
if path:
- installed_packages.append(k)
+ installed_packages.append(value)
update_cache({'packages': installed_packages})
print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
From fb2d0178f1912bf561d370a20e8c3fbb0d3a19b4 Mon Sep 17 00:00:00 2001
From: archetipico <43927507+archetipico@users.noreply.github.com>
Date: Wed, 17 Apr 2024 00:04:14 +0200
Subject: [PATCH 3/5] Refactor
---
README.md | 6 ++-
setup.py | 49 ++++++++++--------
system/linux/package/nixos.sh | 8 +++
utils.py | 94 ++++++++++++++++++-----------------
4 files changed, 90 insertions(+), 67 deletions(-)
diff --git a/README.md b/README.md
index 7aaecae..28e3b42 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,7 @@ eMerger is a simple script to clean update your system and your packages by just
Raspbian
Termux
Ubuntu
+ Windows 11
Systems tested and not working (help wanted)
@@ -37,13 +38,16 @@ eMerger is a simple script to clean update your system and your packages by just
- apt
- apt-get
+ - choco
- dnf
- emerge
- flatpak
- - nixos
+ - nixos-rebuild
+ - nuget
- pacman
- pkg
- rpm
+ - scoop
- snap
- yay
- yum
diff --git a/setup.py b/setup.py
index fca4693..01cc61b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,24 +1,33 @@
from colorama import init, Fore
from platform import system
-from utils import check_packages, update_cache
+from utils import Utils
-# Initialize colorama
-init()
+if __name__ == '__main__':
+ # Initialize colorama
+ init()
+ print('{}----- SETUP PROCESS -----{}'.format(Fore.GREEN, Fore.RESET))
-# Check system
-match system():
- case 'Darwin':
- # Update system in cache
- update_cache({'system': 'darwin'})
- print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
- check_packages()
- case 'Linux':
- # Update system in cache
- update_cache({'system': 'linux'})
- print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
- check_packages()
- case 'Windows':
- # Update system in cache
- update_cache({'system': 'windows'})
- print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
- check_packages()
+ # Check system
+ utils = Utils()
+ match system():
+ case 'Darwin':
+ # Update system in cache
+ utils.update_cache({'system': 'darwin'})
+ print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ utils.check_packages()
+ case 'Linux':
+ # Update system in cache
+ utils.update_cache({'system': 'linux'})
+ print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ utils.check_packages()
+ case 'Windows':
+ # Update system in cache
+ utils.update_cache({'system': 'windows'})
+ print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ utils.check_packages()
+ case _:
+ print('{}> THE SYSTEM IS NOT SUPPORTED: ABORTING SETUP{}'.format(Fore.RED, Fore.RESET))
+ exit()
diff --git a/system/linux/package/nixos.sh b/system/linux/package/nixos.sh
index 18b268d..8f878c8 100644
--- a/system/linux/package/nixos.sh
+++ b/system/linux/package/nixos.sh
@@ -8,6 +8,10 @@ PKG="nixos-rebuild switch"
puts BLUE "Using $PKG $NIX"
+puts RED "upgrade: starting"
+try $PWR nix-channel --update
+puts GREEN "upgrade: completed"
+
puts RED "upgrade: starting"
try $PWR $PKG --upgrade
puts GREEN "upgrade: completed"
@@ -15,3 +19,7 @@ puts GREEN "upgrade: completed"
puts RED "repair: starting"
try $PWR $PKG --repair
puts GREEN "repair: completed"
+
+puts RED "repair: starting"
+try $PWR nix-collect-garbage -d
+puts GREEN "repair: completed"
diff --git a/utils.py b/utils.py
index 8ab3fde..0544efe 100644
--- a/utils.py
+++ b/utils.py
@@ -3,51 +3,53 @@
from os import path
from shutil import which
-CACHE_PATH = 'cache.json'
-PACKAGES = {
- "apt-get": "apt",
- "osascript": "arm",
- "choco": "choco",
- "emerge": "emerge",
- "flatpak": "flatpak",
- "nixos-rebuild": "nixos",
- "nuget": "nuget",
- "scoop": "scoop",
- "pacman": "pacman",
- "pkg": "pkg",
- "rpm": "rpm",
- "snap": "snap",
- "yay": "yay",
- "zypper": "zypper"
-}
+class Utils:
+ def __init__(self):
+ self.CACHE_PATH = 'cache.json'
+ self.PACKAGES = {
+ "apt-get": "apt",
+ "osascript": "arm",
+ "choco": "choco",
+ "emerge": "emerge",
+ "flatpak": "flatpak",
+ "nixos-rebuild": "nixos",
+ "nuget": "nuget",
+ "scoop": "scoop",
+ "pacman": "pacman",
+ "pkg": "pkg",
+ "rpm": "rpm",
+ "snap": "snap",
+ "yay": "yay",
+ "zypper": "zypper"
+ }
-# Add value to caches
-def update_cache(kv):
- try:
- # If the file exists
- if path.exists(CACHE_PATH):
- # Load its content
- with open(CACHE_PATH, 'r') as file:
- data = load(file)
- else:
- # New cache
- data = {}
-
- # Add data to the cache
- data.update(kv)
-
- # Write the updated data back to the file
- with open(CACHE_PATH, 'w') as file:
- dump(data, file, indent=4)
- except Exception as e:
- print(e)
+ # Add value to caches
+ def update_cache(self, kv) -> None:
+ try:
+ # If the file exists
+ if path.exists(self.CACHE_PATH):
+ # Load its content
+ with open(self.CACHE_PATH, 'r') as file:
+ data = load(file)
+ else:
+ # New cache
+ data = {}
+
+ # Add data to the cache
+ data.update(kv)
+
+ # Write the updated data back to the file
+ with open(self.CACHE_PATH, 'w') as file:
+ dump(data, file, indent=4)
+ except Exception as e:
+ print(e)
-def check_packages():
- # For each package check if it exists and add it to the cache
- installed_packages = []
- for key, value in PACKAGES.items():
- path = which(key)
- if path:
- installed_packages.append(value)
- update_cache({'packages': installed_packages})
- print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
+ def check_packages(self) -> None:
+ # For each package check if it exists and add it to the cache
+ installed_packages = []
+ for key, value in self.PACKAGES.items():
+ path = which(key)
+ if path:
+ installed_packages.append(value)
+ self.update_cache({'packages': installed_packages})
+ print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
From ce262ec738718bf054f0ed5f8bea8487030016c6 Mon Sep 17 00:00:00 2001
From: archetipico <43927507+archetipico@users.noreply.github.com>
Date: Wed, 17 Apr 2024 22:14:42 +0200
Subject: [PATCH 4/5] Still refactoring
---
.gitignore | 5 +-
emerger.py | 14 +++
setup.py | 70 ++++++++-------
{system => src/system}/darwin/package/arm.sh | 0
{system => src/system}/linux/package/apt.sh | 0
.../system}/linux/package/emerge.sh | 0
.../system}/linux/package/flatpak.sh | 0
{system => src/system}/linux/package/nixos.sh | 0
.../system}/linux/package/pacman.sh | 0
{system => src/system}/linux/package/pkg.sh | 0
{system => src/system}/linux/package/rpm.sh | 0
{system => src/system}/linux/package/snap.sh | 0
{system => src/system}/linux/package/yay.sh | 0
.../system}/linux/package/zypper.sh | 0
.../system}/windows/package/choco.ps1 | 0
.../system}/windows/package/nuget.ps1 | 0
.../system}/windows/package/scoop.ps1 | 0
{system => src/system}/windows/winUpdate.ps1 | 0
src/utils/{.logo => banner} | 3 +-
src/utils/utils.py | 80 ++++++++++++++++++
{src => src_tobedeleted}/emerger.sh | 0
{src => src_tobedeleted}/logo/README.md | 0
{src => src_tobedeleted}/logo/big_name.png | Bin
{src => src_tobedeleted}/logo/big_name.svg | 0
.../test/argument_check.sh | 0
.../test/integrity_check.sh | 0
{src => src_tobedeleted}/test/list/.packages | 0
{src => src_tobedeleted}/test/list/.tests | 0
{src => src_tobedeleted}/test/list/.utils | 0
{src => src_tobedeleted}/utils/cache.sh | 0
{src => src_tobedeleted}/utils/cache_gen.sh | 0
{src => src_tobedeleted}/utils/check_pwr.sh | 0
{src => src_tobedeleted}/utils/global.sh | 0
{src => src_tobedeleted}/utils/help | 0
{src => src_tobedeleted}/utils/privileges.sh | 0
{src => src_tobedeleted}/utils/trash.sh | 0
update.py | 20 +++++
update.sh | 20 -----
utils.py | 55 ------------
39 files changed, 159 insertions(+), 108 deletions(-)
create mode 100644 emerger.py
rename {system => src/system}/darwin/package/arm.sh (100%)
rename {system => src/system}/linux/package/apt.sh (100%)
rename {system => src/system}/linux/package/emerge.sh (100%)
rename {system => src/system}/linux/package/flatpak.sh (100%)
rename {system => src/system}/linux/package/nixos.sh (100%)
rename {system => src/system}/linux/package/pacman.sh (100%)
rename {system => src/system}/linux/package/pkg.sh (100%)
rename {system => src/system}/linux/package/rpm.sh (100%)
rename {system => src/system}/linux/package/snap.sh (100%)
rename {system => src/system}/linux/package/yay.sh (100%)
rename {system => src/system}/linux/package/zypper.sh (100%)
rename {system => src/system}/windows/package/choco.ps1 (100%)
rename {system => src/system}/windows/package/nuget.ps1 (100%)
rename {system => src/system}/windows/package/scoop.ps1 (100%)
rename {system => src/system}/windows/winUpdate.ps1 (100%)
rename src/utils/{.logo => banner} (98%)
create mode 100644 src/utils/utils.py
rename {src => src_tobedeleted}/emerger.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/logo/README.md (100%)
rename {src => src_tobedeleted}/logo/big_name.png (100%)
rename {src => src_tobedeleted}/logo/big_name.svg (100%)
rename {src => src_tobedeleted}/test/argument_check.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/test/integrity_check.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/test/list/.packages (100%)
rename {src => src_tobedeleted}/test/list/.tests (100%)
rename {src => src_tobedeleted}/test/list/.utils (100%)
rename {src => src_tobedeleted}/utils/cache.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/utils/cache_gen.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/utils/check_pwr.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/utils/global.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/utils/help (100%)
rename {src => src_tobedeleted}/utils/privileges.sh (100%)
mode change 100755 => 100644
rename {src => src_tobedeleted}/utils/trash.sh (100%)
mode change 100755 => 100644
create mode 100644 update.py
delete mode 100755 update.sh
delete mode 100644 utils.py
diff --git a/.gitignore b/.gitignore
index 78aa392..8833c02 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-.log
src/utils/.cache
src/utils/.md5
.hist
@@ -11,4 +10,6 @@ src/utils/.md5
__pycache__/
-cache.json
\ No newline at end of file
+application.json
+preferences.json
+src/utils/log
\ No newline at end of file
diff --git a/emerger.py b/emerger.py
new file mode 100644
index 0000000..52f975e
--- /dev/null
+++ b/emerger.py
@@ -0,0 +1,14 @@
+from json import load
+
+try:
+ # Read preferences
+ with open('preferences.json', 'r') as f:
+ preferences = load(f)
+
+ # Print the banner
+ if (preferences.get('logo') == True):
+ with open('src/utils/banner', 'r') as f:
+ banner = f.read()
+ print(banner)
+except Exception as e:
+ print(e)
diff --git a/setup.py b/setup.py
index 01cc61b..877d87f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,33 +1,45 @@
from colorama import init, Fore
+from os import path, remove
from platform import system
-from utils import Utils
+from src.utils.utils import Utils
-if __name__ == '__main__':
- # Initialize colorama
- init()
- print('{}----- SETUP PROCESS -----{}'.format(Fore.GREEN, Fore.RESET))
+class Setup():
+ def __init__(self):
+ init()
+ self.utils = Utils()
+
+ def run_setup(self) -> None:
+ print('{}----- SETUP PROCESS -----{}'.format(Fore.GREEN, Fore.RESET))
+
+ # If the application cache exists then delete it
+ if path.exists(self.utils.APPLICATION_CACHE):
+ remove(self.utils.APPLICATION_CACHE)
+
+ # Initialize preferences
+ self.utils.init_preferences()
+ # Check system
+ match system():
+ case 'Darwin':
+ # Update system in cache
+ self.utils.update_cache({'system': 'darwin'})
+ print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ self.utils.check_packages()
+ case 'Linux':
+ # Update system in cache
+ self.utils.update_cache({'system': 'linux'})
+ print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ self.utils.check_packages()
+ case 'Windows':
+ # Update system in cache
+ self.utils.update_cache({'system': 'windows'})
+ print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
+ # Update packages
+ self.utils.check_packages()
+ case _:
+ print('{}> THE SYSTEM IS NOT SUPPORTED: ABORTING SETUP{}'.format(Fore.RED, Fore.RESET))
+ exit()
- # Check system
- utils = Utils()
- match system():
- case 'Darwin':
- # Update system in cache
- utils.update_cache({'system': 'darwin'})
- print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
- # Update packages
- utils.check_packages()
- case 'Linux':
- # Update system in cache
- utils.update_cache({'system': 'linux'})
- print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
- # Update packages
- utils.check_packages()
- case 'Windows':
- # Update system in cache
- utils.update_cache({'system': 'windows'})
- print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
- # Update packages
- utils.check_packages()
- case _:
- print('{}> THE SYSTEM IS NOT SUPPORTED: ABORTING SETUP{}'.format(Fore.RED, Fore.RESET))
- exit()
+if __name__ == '__main__':
+ Setup().run_setup()
diff --git a/system/darwin/package/arm.sh b/src/system/darwin/package/arm.sh
similarity index 100%
rename from system/darwin/package/arm.sh
rename to src/system/darwin/package/arm.sh
diff --git a/system/linux/package/apt.sh b/src/system/linux/package/apt.sh
similarity index 100%
rename from system/linux/package/apt.sh
rename to src/system/linux/package/apt.sh
diff --git a/system/linux/package/emerge.sh b/src/system/linux/package/emerge.sh
similarity index 100%
rename from system/linux/package/emerge.sh
rename to src/system/linux/package/emerge.sh
diff --git a/system/linux/package/flatpak.sh b/src/system/linux/package/flatpak.sh
similarity index 100%
rename from system/linux/package/flatpak.sh
rename to src/system/linux/package/flatpak.sh
diff --git a/system/linux/package/nixos.sh b/src/system/linux/package/nixos.sh
similarity index 100%
rename from system/linux/package/nixos.sh
rename to src/system/linux/package/nixos.sh
diff --git a/system/linux/package/pacman.sh b/src/system/linux/package/pacman.sh
similarity index 100%
rename from system/linux/package/pacman.sh
rename to src/system/linux/package/pacman.sh
diff --git a/system/linux/package/pkg.sh b/src/system/linux/package/pkg.sh
similarity index 100%
rename from system/linux/package/pkg.sh
rename to src/system/linux/package/pkg.sh
diff --git a/system/linux/package/rpm.sh b/src/system/linux/package/rpm.sh
similarity index 100%
rename from system/linux/package/rpm.sh
rename to src/system/linux/package/rpm.sh
diff --git a/system/linux/package/snap.sh b/src/system/linux/package/snap.sh
similarity index 100%
rename from system/linux/package/snap.sh
rename to src/system/linux/package/snap.sh
diff --git a/system/linux/package/yay.sh b/src/system/linux/package/yay.sh
similarity index 100%
rename from system/linux/package/yay.sh
rename to src/system/linux/package/yay.sh
diff --git a/system/linux/package/zypper.sh b/src/system/linux/package/zypper.sh
similarity index 100%
rename from system/linux/package/zypper.sh
rename to src/system/linux/package/zypper.sh
diff --git a/system/windows/package/choco.ps1 b/src/system/windows/package/choco.ps1
similarity index 100%
rename from system/windows/package/choco.ps1
rename to src/system/windows/package/choco.ps1
diff --git a/system/windows/package/nuget.ps1 b/src/system/windows/package/nuget.ps1
similarity index 100%
rename from system/windows/package/nuget.ps1
rename to src/system/windows/package/nuget.ps1
diff --git a/system/windows/package/scoop.ps1 b/src/system/windows/package/scoop.ps1
similarity index 100%
rename from system/windows/package/scoop.ps1
rename to src/system/windows/package/scoop.ps1
diff --git a/system/windows/winUpdate.ps1 b/src/system/windows/winUpdate.ps1
similarity index 100%
rename from system/windows/winUpdate.ps1
rename to src/system/windows/winUpdate.ps1
diff --git a/src/utils/.logo b/src/utils/banner
similarity index 98%
rename from src/utils/.logo
rename to src/utils/banner
index 78ecb0c..2dfbe4e 100644
--- a/src/utils/.logo
+++ b/src/utils/banner
@@ -11,5 +11,4 @@
\$$$$$$ |
\______/
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-MIT License
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/src/utils/utils.py b/src/utils/utils.py
new file mode 100644
index 0000000..a3db48a
--- /dev/null
+++ b/src/utils/utils.py
@@ -0,0 +1,80 @@
+from colorama import Fore
+from json import dump, load
+from os import path
+from shutil import which
+
+class Utils:
+ def __init__(self):
+ self.APPLICATION_CACHE = 'application.json'
+ self.APPLICATION_PREFERENCES = 'preferences.json'
+ self.LOG = 'src/utils/log'
+ self.PACKAGES = {
+ "apt-get": "apt",
+ "osascript": "arm",
+ "choco": "choco",
+ "emerge": "emerge",
+ "flatpak": "flatpak",
+ "nixos-rebuild": "nixos",
+ "nuget": "nuget",
+ "scoop": "scoop",
+ "pacman": "pacman",
+ "pkg": "pkg",
+ "rpm": "rpm",
+ "snap": "snap",
+ "yay": "yay",
+ "zypper": "zypper"
+ }
+
+ # Check application cache for installed packages
+ def check_packages(self) -> None:
+ # For each package check if it exists and add it to the cache
+ installed_packages = []
+ for key, value in self.PACKAGES.items():
+ path = which(key)
+ if path:
+ installed_packages.append(value)
+ self.update_cache({'packages': installed_packages})
+ print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
+
+ # Initialize application preferences
+ def init_preferences(self) -> None:
+ # Do nothing if preferences are already set
+ if not path.exists(self.APPLICATION_PREFERENCES):
+ with open(self.APPLICATION_PREFERENCES, 'w') as f:
+ dump({
+ "logo": True,
+ }, f, indent=4)
+
+ # Add value to caches
+ def update_cache(self, kv) -> None:
+ try:
+ # If the file exists
+ if path.exists(self.APPLICATION_CACHE):
+ # Load its content
+ with open(self.APPLICATION_CACHE, 'r') as f:
+ data = load(f)
+ else:
+ # New cache
+ data = {}
+
+ # Add data to the cache
+ data.update(kv)
+
+ # Write the updated data back to the file
+ with open(self.APPLICATION_CACHE, 'w') as f:
+ dump(data, f, indent=4)
+ self.update_log({"SUCCESS": "UPDATE CACHE -> ADD {}".format(kv)})
+ except Exception as e:
+ self.update_log({"ERROR": "UPDATE CACHE -> {}".format(e)})
+
+ def update_log(self, kv) -> None:
+ try:
+ # Open the log file in append mode
+ with open(self.LOG, 'a') as file:
+ # Iterate over each key-value pair in kv
+ for key, value in kv.items():
+ # Write the key-value pair as a new line in the log file
+ file.write('{}: {}\n'.format(key, value))
+ except Exception as e:
+ print('{}> SOMETHING WENT WRONG{}'.format(Fore.RED, Fore.RESET))
+ print('CORRUPTED FOLDER -> UPDATE LOG\n{}'.format(e))
diff --git a/src/emerger.sh b/src_tobedeleted/emerger.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/emerger.sh
rename to src_tobedeleted/emerger.sh
diff --git a/src/logo/README.md b/src_tobedeleted/logo/README.md
similarity index 100%
rename from src/logo/README.md
rename to src_tobedeleted/logo/README.md
diff --git a/src/logo/big_name.png b/src_tobedeleted/logo/big_name.png
similarity index 100%
rename from src/logo/big_name.png
rename to src_tobedeleted/logo/big_name.png
diff --git a/src/logo/big_name.svg b/src_tobedeleted/logo/big_name.svg
similarity index 100%
rename from src/logo/big_name.svg
rename to src_tobedeleted/logo/big_name.svg
diff --git a/src/test/argument_check.sh b/src_tobedeleted/test/argument_check.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/test/argument_check.sh
rename to src_tobedeleted/test/argument_check.sh
diff --git a/src/test/integrity_check.sh b/src_tobedeleted/test/integrity_check.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/test/integrity_check.sh
rename to src_tobedeleted/test/integrity_check.sh
diff --git a/src/test/list/.packages b/src_tobedeleted/test/list/.packages
similarity index 100%
rename from src/test/list/.packages
rename to src_tobedeleted/test/list/.packages
diff --git a/src/test/list/.tests b/src_tobedeleted/test/list/.tests
similarity index 100%
rename from src/test/list/.tests
rename to src_tobedeleted/test/list/.tests
diff --git a/src/test/list/.utils b/src_tobedeleted/test/list/.utils
similarity index 100%
rename from src/test/list/.utils
rename to src_tobedeleted/test/list/.utils
diff --git a/src/utils/cache.sh b/src_tobedeleted/utils/cache.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/cache.sh
rename to src_tobedeleted/utils/cache.sh
diff --git a/src/utils/cache_gen.sh b/src_tobedeleted/utils/cache_gen.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/cache_gen.sh
rename to src_tobedeleted/utils/cache_gen.sh
diff --git a/src/utils/check_pwr.sh b/src_tobedeleted/utils/check_pwr.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/check_pwr.sh
rename to src_tobedeleted/utils/check_pwr.sh
diff --git a/src/utils/global.sh b/src_tobedeleted/utils/global.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/global.sh
rename to src_tobedeleted/utils/global.sh
diff --git a/src/utils/help b/src_tobedeleted/utils/help
similarity index 100%
rename from src/utils/help
rename to src_tobedeleted/utils/help
diff --git a/src/utils/privileges.sh b/src_tobedeleted/utils/privileges.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/privileges.sh
rename to src_tobedeleted/utils/privileges.sh
diff --git a/src/utils/trash.sh b/src_tobedeleted/utils/trash.sh
old mode 100755
new mode 100644
similarity index 100%
rename from src/utils/trash.sh
rename to src_tobedeleted/utils/trash.sh
diff --git a/update.py b/update.py
new file mode 100644
index 0000000..5300b84
--- /dev/null
+++ b/update.py
@@ -0,0 +1,20 @@
+from colorama import init, Fore
+from setup import Setup
+from subprocess import PIPE, run
+
+if __name__ == "__main__":
+ # Initialize colorama
+ init()
+ print('{}----- UPDATE PROCESS -----{}'.format(Fore.GREEN, Fore.RESET))
+
+ # Pull from source
+ url = 'https://github.com/TheMergers/eMerger.git'
+ result = run(['git', 'pull', url], stdout=PIPE, stderr=PIPE)
+ if result.returncode == 0:
+ print('{}>{} Application successfully updated!\n'.format(Fore.BLUE, Fore.RESET))
+ else:
+ print('{}> SOMETHING WENT WRONG{}'.format(Fore.RED, Fore.RESET))
+ print(result.stderr.decode())
+
+ # Recreate application.json
+ Setup().run_setup()
diff --git a/update.sh b/update.sh
deleted file mode 100755
index c17b1a1..0000000
--- a/update.sh
+++ /dev/null
@@ -1,20 +0,0 @@
-#!/bin/bash
-
-# Keeping track of exact time
-date "+%D %T:%N" >> $1.log
-
-source $1src/utils/global.sh
-
-# git pull from main
-puts RED "Update repository: starting"
-if [[ $1 != "" ]]; then
- git -C $1 pull https://github.com/MasterCruelty/eMerger.git/
-else
- git pull https://github.com/MasterCruelty/eMerger.git/
-fi
-
-# Instead of re-installing, use our tests to check if everything is okay
-source $1src/test/integrity_check.sh $1 2>>$1.log
-puts GREEN "Update repository: completed"
-
-exit 0
diff --git a/utils.py b/utils.py
deleted file mode 100644
index 0544efe..0000000
--- a/utils.py
+++ /dev/null
@@ -1,55 +0,0 @@
-from colorama import Fore
-from json import dump, load
-from os import path
-from shutil import which
-
-class Utils:
- def __init__(self):
- self.CACHE_PATH = 'cache.json'
- self.PACKAGES = {
- "apt-get": "apt",
- "osascript": "arm",
- "choco": "choco",
- "emerge": "emerge",
- "flatpak": "flatpak",
- "nixos-rebuild": "nixos",
- "nuget": "nuget",
- "scoop": "scoop",
- "pacman": "pacman",
- "pkg": "pkg",
- "rpm": "rpm",
- "snap": "snap",
- "yay": "yay",
- "zypper": "zypper"
- }
-
- # Add value to caches
- def update_cache(self, kv) -> None:
- try:
- # If the file exists
- if path.exists(self.CACHE_PATH):
- # Load its content
- with open(self.CACHE_PATH, 'r') as file:
- data = load(file)
- else:
- # New cache
- data = {}
-
- # Add data to the cache
- data.update(kv)
-
- # Write the updated data back to the file
- with open(self.CACHE_PATH, 'w') as file:
- dump(data, file, indent=4)
- except Exception as e:
- print(e)
-
- def check_packages(self) -> None:
- # For each package check if it exists and add it to the cache
- installed_packages = []
- for key, value in self.PACKAGES.items():
- path = which(key)
- if path:
- installed_packages.append(value)
- self.update_cache({'packages': installed_packages})
- print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
From f93ecba940761794068534934baa64a7492b2901 Mon Sep 17 00:00:00 2001
From: archetipico <43927507+archetipico@users.noreply.github.com>
Date: Wed, 17 Apr 2024 23:29:40 +0200
Subject: [PATCH 5/5] First attempt
---
emerger.py | 31 +++++++++++++++++++++++++++++++
setup.py | 35 ++++++++++++++++++++++++-----------
src/utils/utils.py | 31 ++++++++++++++++++-------------
update.py | 1 +
4 files changed, 74 insertions(+), 24 deletions(-)
diff --git a/emerger.py b/emerger.py
index 52f975e..d2108f4 100644
--- a/emerger.py
+++ b/emerger.py
@@ -1,6 +1,16 @@
+from colorama import Fore
from json import load
+from os import path
+from src.utils.utils import Utils
+from subprocess import PIPE, Popen
+
+utils = Utils()
try:
+ # Read application data
+ with open('application.json', 'r') as f:
+ data = load(f)
+
# Read preferences
with open('preferences.json', 'r') as f:
preferences = load(f)
@@ -10,5 +20,26 @@
with open('src/utils/banner', 'r') as f:
banner = f.read()
print(banner)
+
+ # Print the system
+ system = data.get('system')
+ file_extension = data.get('file_extension')
+ global_path = data.get('global_path')
+ path_divisor = data.get('path_divisor')
+ print('{}>{} System detected: {}'.format(Fore.BLUE, Fore.RESET, system.capitalize()))
+
+ # Use packages
+ packages = utils.check_packages(False)
+ execution_folder = path.join(global_path, 'src', 'system', system, 'package')
+ for pkg in packages:
+ # The file to execute
+ execution_file = '{}{}{}.{}'.format(execution_folder, path_divisor, pkg, file_extension)
+ # Create a process
+ process = Popen(['powershell.exe', execution_file], stdout=PIPE, stderr=PIPE, text=True, shell=True)
+ # Read stdout
+ for line in process.stdout:
+ print(line.strip())
+ # Wait for the process to finish and get the return code
+ return_code = process.wait()
except Exception as e:
print(e)
diff --git a/setup.py b/setup.py
index 877d87f..cab092b 100644
--- a/setup.py
+++ b/setup.py
@@ -1,8 +1,9 @@
from colorama import init, Fore
-from os import path, remove
+from os import getcwd, path, remove
from platform import system
from src.utils.utils import Utils
+
class Setup():
def __init__(self):
init()
@@ -11,29 +12,41 @@ def __init__(self):
def run_setup(self) -> None:
print('{}----- SETUP PROCESS -----{}'.format(Fore.GREEN, Fore.RESET))
- # If the application cache exists then delete it
- if path.exists(self.utils.APPLICATION_CACHE):
- remove(self.utils.APPLICATION_CACHE)
+ # If the application data exists then delete it
+ if path.exists(self.utils.APPLICATION_DATA):
+ remove(self.utils.APPLICATION_DATA)
# Initialize preferences
- self.utils.init_preferences()
+ self.utils.init_preferences()
+
+ # Get global path
+ cwd = getcwd()
+ self.utils.update_data({'global_path': cwd})
+ print('{}>{} Working directory set to: {}'.format(Fore.BLUE, Fore.RESET, cwd))
+
# Check system
match system():
case 'Darwin':
- # Update system in cache
- self.utils.update_cache({'system': 'darwin'})
+ # Update system in data
+ self.utils.update_data({'system': 'darwin'})
+ self.utils.update_data({'file_extension': 'sh'})
+ self.utils.update_data({'path_divisor': '/'})
print('{}>{} System set to Darwin'.format(Fore.BLUE, Fore.RESET))
# Update packages
self.utils.check_packages()
case 'Linux':
- # Update system in cache
- self.utils.update_cache({'system': 'linux'})
+ # Update system in data
+ self.utils.update_data({'system': 'linux'})
+ self.utils.update_data({'file_extension': 'sh'})
+ self.utils.update_data({'path_divisor': '/'})
print('{}>{} System set to Linux'.format(Fore.BLUE, Fore.RESET))
# Update packages
self.utils.check_packages()
case 'Windows':
- # Update system in cache
- self.utils.update_cache({'system': 'windows'})
+ # Update system in data
+ self.utils.update_data({'system': 'windows'})
+ self.utils.update_data({'file_extension': 'ps1'})
+ self.utils.update_data({'path_divisor': '\\'})
print('{}>{} System set to Windows'.format(Fore.BLUE, Fore.RESET))
# Update packages
self.utils.check_packages()
diff --git a/src/utils/utils.py b/src/utils/utils.py
index a3db48a..6665bd5 100644
--- a/src/utils/utils.py
+++ b/src/utils/utils.py
@@ -3,9 +3,10 @@
from os import path
from shutil import which
+
class Utils:
def __init__(self):
- self.APPLICATION_CACHE = 'application.json'
+ self.APPLICATION_DATA = 'application.json'
self.APPLICATION_PREFERENCES = 'preferences.json'
self.LOG = 'src/utils/log'
self.PACKAGES = {
@@ -25,16 +26,20 @@ def __init__(self):
"zypper": "zypper"
}
- # Check application cache for installed packages
- def check_packages(self) -> None:
- # For each package check if it exists and add it to the cache
+ # Check application data for installed packages
+ def check_packages(self, verbose=True) -> list:
+ # For each package check if it exists and add it to the data
installed_packages = []
for key, value in self.PACKAGES.items():
path = which(key)
if path:
installed_packages.append(value)
- self.update_cache({'packages': installed_packages})
- print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
+ self.update_data({'packages': installed_packages})
+
+ if verbose:
+ print('{}>{} The following packages were found: {}'.format(Fore.BLUE, Fore.RESET, installed_packages))
+
+ return installed_packages
# Initialize application preferences
def init_preferences(self) -> None:
@@ -45,23 +50,23 @@ def init_preferences(self) -> None:
"logo": True,
}, f, indent=4)
- # Add value to caches
- def update_cache(self, kv) -> None:
+ # Add value to data
+ def update_data(self, kv) -> None:
try:
# If the file exists
- if path.exists(self.APPLICATION_CACHE):
+ if path.exists(self.APPLICATION_DATA):
# Load its content
- with open(self.APPLICATION_CACHE, 'r') as f:
+ with open(self.APPLICATION_DATA, 'r') as f:
data = load(f)
else:
- # New cache
+ # New data dictionary
data = {}
- # Add data to the cache
+ # Add data to the dictionary
data.update(kv)
# Write the updated data back to the file
- with open(self.APPLICATION_CACHE, 'w') as f:
+ with open(self.APPLICATION_DATA, 'w') as f:
dump(data, f, indent=4)
self.update_log({"SUCCESS": "UPDATE CACHE -> ADD {}".format(kv)})
except Exception as e:
diff --git a/update.py b/update.py
index 5300b84..a416bc9 100644
--- a/update.py
+++ b/update.py
@@ -2,6 +2,7 @@
from setup import Setup
from subprocess import PIPE, run
+
if __name__ == "__main__":
# Initialize colorama
init()