Skip to content

Commit

Permalink
Merge pull request #4 from grubyhs/feature/placzykowski/move-choco-to…
Browse files Browse the repository at this point in the history
…-seperate-py

Feature/placzykowski/move choco to seperate py
  • Loading branch information
piotrlaczykowski authored Jun 10, 2024
2 parents 6e6bb4f + 0678af7 commit 7a53e98
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 33 deletions.
39 changes: 39 additions & 0 deletions chocolatey.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from utilities import *
# Check if Chocolatey (choco) is installed
def is_choco_installed():
try:
subprocess.run(["choco", "--version"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
check=True)
return True
except subprocess.CalledProcessError:
return False
except FileNotFoundError:
return False


# Function to install Chocolatey (choco)
def install_choco():
try:
subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-Command", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"], check=True)
print("Chocolatey (choco) installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error installing Chocolatey (choco): {e}")

# Function to upgrade packages using Chocolatey (choco)
def upgrade_choco_packages():
try:
subprocess.run(["choco", "upgrade", "all", "-y"], check=True)
print("All Chocolatey packages upgraded successfully.")
except subprocess.CalledProcessError as e:
print(f"Error upgrading Chocolatey packages: {e}")

def choco_upgrade():
if not is_choco_installed():
print("Chocolatey (choco) is not installed. Installing it now...")
install_choco()
if is_choco_installed():
upgrade_choco_packages()
else:
upgrade_choco_packages()
4 changes: 4 additions & 0 deletions dell_support_assist.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import os
import sys
import ctypes
import subprocess
import requests
import wmi
import winreg
from utilities import *
from motherboard import *
Expand Down
2 changes: 1 addition & 1 deletion motherboard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from dell_support_assist import *
from dell_support_assist import dell
from msi import *
from utilities import *

Expand Down
6 changes: 6 additions & 0 deletions msi.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import os
import sys
import ctypes
import subprocess
import requests
import wmi
from utilities import *
import glob

Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ whichcraft==0.6.1
WMI==1.5.1
zope.event==5.0
zope.interface==6.3
requests
wmi
1 change: 1 addition & 0 deletions update-pc-script-auto.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from utilities import *
from motherboard import *
from chocolatey import *

if __name__ == "__main__":
if run_as_admin():
Expand Down
1 change: 1 addition & 0 deletions update-pc-script.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from motherboard import *
from utilities import *
from chocolatey import *

if __name__ == "__main__":
if run_as_admin():
Expand Down
32 changes: 0 additions & 32 deletions utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,6 @@ def run_as_admin():
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
return False

# Check if Chocolatey (choco) is installed
def is_choco_installed():
try:
subprocess.run(["choco", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True)
return True
except subprocess.CalledProcessError:
return False

# Function to install Chocolatey (choco)
def install_choco():
try:
subprocess.run(["powershell", "-ExecutionPolicy", "Bypass", "-Command", "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))"], check=True)
print("Chocolatey (choco) installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error installing Chocolatey (choco): {e}")

# Function to upgrade packages using Chocolatey (choco)
def upgrade_choco_packages():
try:
subprocess.run(["choco", "upgrade", "all", "-y"], check=True)
print("All Chocolatey packages upgraded successfully.")
except subprocess.CalledProcessError as e:
print(f"Error upgrading Chocolatey packages: {e}")

def download_installer(url, user_download_folder, installer_path):
response = requests.get(url, stream=True)
if response.status_code == 200:
Expand Down Expand Up @@ -107,14 +83,6 @@ def winget_upgrade():
print("All installed packages upgraded successfully.")
except subprocess.CalledProcessError as e:
print(f"Error upgrading packages with winget: {e}")

def choco_upgrade():
if not is_choco_installed():
print("Chocolatey (choco) is not installed. Installing it now...")
install_choco()
upgrade_choco_packages()
else:
upgrade_choco_packages()

def windows_update():
try:
Expand Down

0 comments on commit 7a53e98

Please sign in to comment.