Skip to content

Commit 8c7fead

Browse files
authored
Add files via upload
1 parent d252e69 commit 8c7fead

19 files changed

+1043
-0
lines changed
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import shutil
3+
import subprocess
4+
import platform
5+
6+
def delete_older_directories(directory):
7+
# Delete the specified directory if it exists
8+
if os.path.exists(directory):
9+
shutil.rmtree(directory)
10+
print(f"Deleted directory: {directory}")
11+
else:
12+
print(f"Directory not found: {directory}")
13+
14+
def find_and_delete_dist_and_build(cwd):
15+
# Delete 'dist' and 'build' directories
16+
delete_older_directories(os.path.join(cwd, 'dist'))
17+
delete_older_directories(os.path.join(cwd, 'build'))
18+
19+
def find_and_activate_venv():
20+
# Get the current working directory
21+
cwd = os.getcwd()
22+
23+
# Delete 'dist' and 'build' directories
24+
find_and_delete_dist_and_build(cwd)
25+
26+
# Walk through the current directory and its subdirectories
27+
for root, dirs, files in os.walk(cwd):
28+
# Check if the directory contains a virtual environment
29+
if 'Scripts' in dirs or 'bin' in dirs:
30+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
31+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
32+
33+
# Check if the required activation file is present in the Scripts/bin directory
34+
if required_files.issubset(set(os.listdir(scripts_path))):
35+
print(f"Virtual environment found and activated at: {root}")
36+
37+
# Activate the virtual environment, upgrade pip, and check pip version
38+
if platform.system() == 'Windows':
39+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip && pyinstaller -F -c main.py"'
40+
else:
41+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip && pyinstaller -F -c main.py'
42+
43+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
44+
return
45+
46+
print("No virtual environment found.")
47+
48+
if __name__ == "__main__":
49+
find_and_activate_venv()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import subprocess
3+
import platform
4+
import winreg
5+
import ctypes
6+
import sys
7+
import re
8+
9+
def is_admin():
10+
try:
11+
return ctypes.windll.shell32.IsUserAnAdmin()
12+
except:
13+
return False
14+
15+
def run_as_admin():
16+
params = " ".join([f'"{arg}"' for arg in sys.argv])
17+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
18+
19+
def get_python_versions(base_path):
20+
python_versions = []
21+
for folder in os.listdir(base_path):
22+
match = re.match(r'^Python(\d{3})$', folder)
23+
if match and match.group(1) != '310':
24+
python_versions.append(folder)
25+
return python_versions
26+
27+
def update_environment_variable(variable_name, new_value, scope):
28+
try:
29+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
30+
value, regtype = winreg.QueryValueEx(key, variable_name)
31+
value_list = value.split(os.pathsep)
32+
# Remove any existing instances of the new value
33+
value_list = [v for v in value_list if v != new_value]
34+
# Add the new value to the top
35+
value_list.insert(0, new_value)
36+
new_value_str = os.pathsep.join(value_list)
37+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
38+
print(f"Updated {variable_name} in system variables.")
39+
except FileNotFoundError:
40+
print(f"{variable_name} not found in system variables.")
41+
42+
def create_virtual_environment(directory):
43+
print(f"Creating a virtual environment in {directory}...")
44+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
45+
print("Virtual environment created.")
46+
47+
def find_and_activate_venv():
48+
cwd = os.getcwd()
49+
for root, dirs, files in os.walk(cwd):
50+
if 'Scripts' in dirs or 'bin' in dirs:
51+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
52+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
53+
if required_files.issubset(set(os.listdir(scripts_path))):
54+
print(f"Virtual environment found and activated at: {root}")
55+
if platform.system() == 'Windows':
56+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
57+
else:
58+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
59+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
60+
return
61+
print("No virtual environment found.")
62+
63+
if __name__ == "__main__":
64+
if not is_admin():
65+
print("Requesting administrative privileges...")
66+
run_as_admin()
67+
sys.exit()
68+
69+
base_path = r"C:\Program Files"
70+
new_path = r"C:\Program Files\Python310"
71+
new_path_scripts = os.path.join(new_path, 'Scripts')
72+
73+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
74+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
75+
76+
print("All changes to the System and User Variables have been made!")
77+
create_virtual_environment(os.getcwd())
78+
find_and_activate_venv()
79+
80+
if platform.system() == 'Windows':
81+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import subprocess
3+
import platform
4+
import winreg
5+
import ctypes
6+
import sys
7+
import re
8+
9+
def is_admin():
10+
try:
11+
return ctypes.windll.shell32.IsUserAnAdmin()
12+
except:
13+
return False
14+
15+
def run_as_admin():
16+
params = " ".join([f'"{arg}"' for arg in sys.argv])
17+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
18+
19+
def get_python_versions(base_path):
20+
python_versions = []
21+
for folder in os.listdir(base_path):
22+
match = re.match(r'^Python(\d{3})$', folder)
23+
if match and match.group(1) != '310':
24+
python_versions.append(folder)
25+
return python_versions
26+
27+
def update_environment_variable(variable_name, new_value, scope):
28+
try:
29+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
30+
value, regtype = winreg.QueryValueEx(key, variable_name)
31+
value_list = value.split(os.pathsep)
32+
# Remove any existing instances of the new value
33+
value_list = [v for v in value_list if v != new_value]
34+
# Add the new value to the top
35+
value_list.insert(0, new_value)
36+
new_value_str = os.pathsep.join(value_list)
37+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
38+
print(f"Updated {variable_name} in system variables.")
39+
except FileNotFoundError:
40+
print(f"{variable_name} not found in system variables.")
41+
42+
def create_virtual_environment(directory):
43+
print(f"Creating a virtual environment in {directory}...")
44+
subprocess.run(["python", "-m", "venv", ".venv310"], cwd=directory, shell=True)
45+
print("Virtual environment created.")
46+
47+
def find_and_activate_venv():
48+
cwd = os.getcwd()
49+
for root, dirs, files in os.walk(cwd):
50+
if 'Scripts' in dirs or 'bin' in dirs:
51+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
52+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
53+
if required_files.issubset(set(os.listdir(scripts_path))):
54+
print(f"Virtual environment found and activated at: {root}")
55+
if platform.system() == 'Windows':
56+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
57+
else:
58+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
59+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
60+
return
61+
print("No virtual environment found.")
62+
63+
if __name__ == "__main__":
64+
if not is_admin():
65+
print("Requesting administrative privileges...")
66+
run_as_admin()
67+
sys.exit()
68+
69+
base_path = r"C:\Program Files"
70+
new_path = r"C:\Program Files\Python310"
71+
new_path_scripts = os.path.join(new_path, 'Scripts')
72+
73+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
74+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
75+
76+
print("All changes to the System and User Variables have been made!")
77+
create_virtual_environment(os.getcwd())
78+
find_and_activate_venv()
79+
80+
if platform.system() == 'Windows':
81+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import subprocess
3+
import platform
4+
import winreg
5+
import ctypes
6+
import sys
7+
import re
8+
9+
def is_admin():
10+
try:
11+
return ctypes.windll.shell32.IsUserAnAdmin()
12+
except:
13+
return False
14+
15+
def run_as_admin():
16+
params = " ".join([f'"{arg}"' for arg in sys.argv])
17+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
18+
19+
def get_python_versions(base_path):
20+
python_versions = []
21+
for folder in os.listdir(base_path):
22+
match = re.match(r'^Python(\d{3})$', folder)
23+
if match and match.group(1) != '310':
24+
python_versions.append(folder)
25+
return python_versions
26+
27+
def update_environment_variable(variable_name, new_value, scope):
28+
try:
29+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
30+
value, regtype = winreg.QueryValueEx(key, variable_name)
31+
value_list = value.split(os.pathsep)
32+
# Remove any existing instances of the new value
33+
value_list = [v for v in value_list if v != new_value]
34+
# Add the new value to the top
35+
value_list.insert(0, new_value)
36+
new_value_str = os.pathsep.join(value_list)
37+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
38+
print(f"Updated {variable_name} in system variables.")
39+
except FileNotFoundError:
40+
print(f"{variable_name} not found in system variables.")
41+
42+
def create_virtual_environment(directory):
43+
print(f"Creating a virtual environment in {directory}...")
44+
subprocess.run(["python", "-m", "venv", "venv"], cwd=directory, shell=True)
45+
print("Virtual environment created.")
46+
47+
def find_and_activate_venv():
48+
cwd = os.getcwd()
49+
for root, dirs, files in os.walk(cwd):
50+
if 'Scripts' in dirs or 'bin' in dirs:
51+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
52+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
53+
if required_files.issubset(set(os.listdir(scripts_path))):
54+
print(f"Virtual environment found and activated at: {root}")
55+
if platform.system() == 'Windows':
56+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
57+
else:
58+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
59+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
60+
return
61+
print("No virtual environment found.")
62+
63+
if __name__ == "__main__":
64+
if not is_admin():
65+
print("Requesting administrative privileges...")
66+
run_as_admin()
67+
sys.exit()
68+
69+
base_path = r"C:\Program Files"
70+
new_path = r"C:\Program Files\Python310"
71+
new_path_scripts = os.path.join(new_path, 'Scripts')
72+
73+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
74+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
75+
76+
print("All changes to the System and User Variables have been made!")
77+
create_virtual_environment(os.getcwd())
78+
find_and_activate_venv()
79+
80+
if platform.system() == 'Windows':
81+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import os
2+
import subprocess
3+
import platform
4+
import winreg
5+
import ctypes
6+
import sys
7+
import re
8+
9+
def is_admin():
10+
try:
11+
return ctypes.windll.shell32.IsUserAnAdmin()
12+
except:
13+
return False
14+
15+
def run_as_admin():
16+
params = " ".join([f'"{arg}"' for arg in sys.argv])
17+
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, params, None, 1)
18+
19+
def get_python_versions(base_path):
20+
python_versions = []
21+
for folder in os.listdir(base_path):
22+
match = re.match(r'^Python(\d{3})$', folder)
23+
if match and match.group(1) != '313':
24+
python_versions.append(folder)
25+
return python_versions
26+
27+
def update_environment_variable(variable_name, new_value, scope):
28+
try:
29+
with winreg.OpenKey(scope, r'SYSTEM\CurrentControlSet\Control\Session Manager\Environment', 0, winreg.KEY_ALL_ACCESS) as key:
30+
value, regtype = winreg.QueryValueEx(key, variable_name)
31+
value_list = value.split(os.pathsep)
32+
# Remove any existing instances of the new value
33+
value_list = [v for v in value_list if v != new_value]
34+
# Add the new value to the top
35+
value_list.insert(0, new_value)
36+
new_value_str = os.pathsep.join(value_list)
37+
winreg.SetValueEx(key, variable_name, 0, regtype, new_value_str)
38+
print(f"Updated {variable_name} in system variables.")
39+
except FileNotFoundError:
40+
print(f"{variable_name} not found in system variables.")
41+
42+
def create_virtual_environment(directory):
43+
print(f"Creating a virtual environment in {directory}...")
44+
subprocess.run(["python", "-m", "venv", ".venv"], cwd=directory, shell=True)
45+
print("Virtual environment created.")
46+
47+
def find_and_activate_venv():
48+
cwd = os.getcwd()
49+
for root, dirs, files in os.walk(cwd):
50+
if 'Scripts' in dirs or 'bin' in dirs:
51+
scripts_path = os.path.join(root, 'Scripts' if platform.system() == 'Windows' else 'bin')
52+
required_files = {'activate.bat' if platform.system() == 'Windows' else 'activate'}
53+
if required_files.issubset(set(os.listdir(scripts_path))):
54+
print(f"Virtual environment found and activated at: {root}")
55+
if platform.system() == 'Windows':
56+
activate_command = f'cmd /k ""{os.path.join(scripts_path, "activate.bat")}" && python.exe -m pip install --upgrade pip"'
57+
else:
58+
activate_command = f'source "{os.path.join(scripts_path, "activate")}" && python3 -m pip install --upgrade pip'
59+
subprocess.run(activate_command, shell=True, executable='/bin/bash' if platform.system() != 'Windows' else None)
60+
return
61+
print("No virtual environment found.")
62+
63+
if __name__ == "__main__":
64+
if not is_admin():
65+
print("Requesting administrative privileges...")
66+
run_as_admin()
67+
sys.exit()
68+
69+
base_path = r"C:\Program Files"
70+
new_path = r"C:\Program Files\Python313"
71+
new_path_scripts = os.path.join(new_path, 'Scripts')
72+
73+
update_environment_variable('Path', new_path_scripts, winreg.HKEY_LOCAL_MACHINE)
74+
update_environment_variable('Path', new_path, winreg.HKEY_LOCAL_MACHINE)
75+
76+
print("All changes to the System and User Variables have been made!")
77+
create_virtual_environment(os.getcwd())
78+
find_and_activate_venv()
79+
80+
if platform.system() == 'Windows':
81+
subprocess.run(['cmd', '/k', 'echo Virtual environment setup complete.'], shell=True)

0 commit comments

Comments
 (0)