-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
77 lines (67 loc) · 2.73 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import sys
import ctypes
import subprocess
import requests
import wmi
import zipfile
# Function to display the update menu
def display_update_menu():
print("Select an option to update:")
print("1. Launch/Install Motherboard Manufacturer Software")
print("2. Winget Update")
print("3. Choco Update")
print("4. Windows Update")
print("5. All")
while True:
choice = input("Enter your choice (1/2/3/4/5): ")
if choice in ["1", "2", "3", "4", "5"]:
return int(choice)
else:
print("Invalid choice. Please enter a valid option.")
def user_download_folder():
user_download_folder = os.path.join(os.path.expanduser("~"), "Downloads")
return user_download_folder
def unzip(file_name_to_unzip, unzip_destination):
with zipfile.ZipFile(file_name_to_unzip,"r") as zip_ref:
zip_ref.extractall(unzip_destination)
def mobo_manufacturer():
motherboard = wmi.WMI().Win32_ComputerSystem()[0].Manufacturer
return motherboard
def run_as_admin():
if ctypes.windll.shell32.IsUserAnAdmin():
return True
script = os.path.abspath(sys.argv[0])
params = ' '.join([script] + sys.argv[1:])
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
return False
def download_installer(url, user_download_folder, installer_path):
response = requests.get(url, stream=True)
if response.status_code == 200:
if not os.path.exists(user_download_folder):
os.makedirs(user_download_folder)
with open(installer_path, 'wb') as installer_file:
for chunk in response.iter_content(chunk_size=1024):
installer_file.write(chunk)
def unsecured_download_installer(url, user_download_folder, installer_path):
try:
response = requests.get(url, stream=True, verify=False)
if response.status_code == 200:
os.makedirs(user_download_folder, exist_ok=True)
with open(installer_path, 'wb') as installer_file:
for chunk in response.iter_content(chunk_size=1024):
installer_file.write(chunk)
print(f"Downloaded installer to {installer_path}")
else:
print(f"Error downloading installer: {response.status_code}")
except requests.exceptions.RequestException as e:
print(f"Request error: {e}")
def install_program(installer_path, program_name):
if os.path.exists(installer_path):
try:
subprocess.run([installer_path], check=True)
print(f"{program_name} installed successfully.")
except subprocess.CalledProcessError as e:
print(f"Error installing {program_name}: {e}")
else:
print("Error: Installer not found.")