-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyWizard.py
223 lines (188 loc) · 8.73 KB
/
PyWizard.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
import os
import sys
import subprocess
import importlib
import pkgutil
if pkgutil.find_loader("colorama") is None:
subprocess.check_call(["pip", "install", "colorama"])
#installs colorama automatically
else:
pass
import colorama
from colorama import Fore, Back, Style
colorama.init(autoreset=True)
#clears terminal
os.system("cls")
print('''
█▀▀█ █ █ █ █ ▀█▀ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▄
█▄▄█ █▄▄▄█ █ █ █ █ ▄▄▄▀▀ █▄▄█ █▄▄▀ █ █
█ █ █▄▀▄█ ▄█▄ █▄▄▄█ █ █ █ █ █▄▄▀ v1.5.4''')
print(Fore.YELLOW + " PYTHON PACKAGE MANAGER")
print()
print(Fore.LIGHTBLACK_EX + " Copyright © Ashfaaq Rifath")
print('''
(1) Install package
(2) Batch install from requirements file
(3) Update package
(4) Uninstall package
(5) Batch uninstall from requirements file
(6) Check package status
(7) Display installed packages
(8) Save requirements file
(9) Upgrade PIP version
(10) Check PIP version
(11) Check Python version
(12) Create EXE for Python file''')
while True:
print()
option = input(Fore.CYAN + " Select option: " + Style.RESET_ALL)
if option == "1":
print()
install_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
try:
subprocess.check_call(["pip", "install", install_pkg])
print(" " + Fore.BLACK + Back.GREEN + f" Installed {install_pkg} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
elif option == "2":
print()
print(Fore.YELLOW + " NOTE: Make sure requirements.txt is in the root directory.")
if os.path.isfile("requirements.txt"):
print(Fore.GREEN + " Batch installing packages...")
with open("requirements.txt") as f:
reqs = f.read().splitlines()
for pkg in reqs:
try:
subprocess.check_call(["pip", "install", pkg])
print(" " + Fore.BLACK + Back.GREEN + f" Installed {pkg} ")
print()
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
else:
print(" " + Fore.BLACK + Back.RED + " REQUIREMENTS FILE DOES NOT EXIST ")
elif option == "3":
print()
update_pkg = input(Fore.GREEN + " Enter package name: " + Style.RESET_ALL)
try:
subprocess.check_call(["pip", "install", "--upgrade", update_pkg])
print(" " + Fore.BLACK + Back.GREEN + f" Updated {update_pkg} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
elif option == "4":
print()
uninstall_pkg = input(Fore.LIGHTRED_EX + " Enter package name: " + Style.RESET_ALL)
try:
subprocess.check_call(["pip", "uninstall", uninstall_pkg])
print(" " + Fore.BLACK + Back.RED + f" Uninstalled {uninstall_pkg} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
elif option == "5":
confirm = input(Fore.LIGHTRED_EX + " Do you want to proceed? (y/n): ")
if confirm == "y".lower():
print()
print(Fore.YELLOW + " NOTE: Input package names in the requirements file." + Style.RESET_ALL)
if os.path.isfile("requirements.txt"):
print(Fore.RED + " Batch uninstalling packages..." + Style.RESET_ALL)
print()
with open("requirements.txt") as f:
reqs = f.read().splitlines()
for pkg in reqs:
try:
subprocess.check_call(["pip", "uninstall", "-y", pkg])
print(" " + Fore.BLACK + Back.RED + f" Uninstalled {pkg} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
else:
print(" " + Fore.BLACK + Back.RED + " REQUIREMENTS FILE DOES NOT EXIST ")
else:
print(" " + Fore.BLACK + Back.RED + " UNINSTALL CANCELLED ")
elif option == "6":
print()
verify_pkg = input(Fore.CYAN + " Enter package name: " + Style.RESET_ALL)
try:
subprocess.check_call(["pip", "show", verify_pkg])
print(" " + Fore.BLACK + Back.GREEN + f" {verify_pkg} package exists ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
elif option == "7":
print()
print(Fore.GREEN + " Displaying all installed packages...")
subprocess.check_call(["pip", "list"])
elif option == "8":
print()
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
print(Fore.GREEN + " Saving project requirements to text file...")
try:
save = subprocess.run(["pip", "freeze"], stdout=subprocess.PIPE)
with open('requirements.txt', 'wb') as f:
f.write(save.stdout)
print(" " + Fore.BLACK + Back.GREEN + " PROJECT REQUIREMENTS SAVED ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
elif option == "9":
print()
print(Fore.GREEN + " Upgrading to new PIP version...")
try:
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"])
print(" " + Fore.BLACK + Back.GREEN + " PIP version upgrade successful ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
elif option == "10":
print()
print(Fore.GREEN + " Displaying PIP version")
subprocess.run(["pip", "--version"])
elif option == "11":
print()
print(Fore.GREEN + " Displaying Python version")
subprocess.run(["python", "--version"])
elif option == "12":
if pkgutil.find_loader("pyinstaller") is None:
subprocess.check_call(["pip", "install", "pyinstaller"])
#installs pyinstaller automatically
else:
pass
print()
file_name = input(Fore.CYAN + " Enter Python file name (.py): " + Style.RESET_ALL)
if os.path.isfile(file_name):
icon_option = input(Fore.YELLOW + " Do you want an icon for this file? (y/n): " + Style.RESET_ALL)
if icon_option == "y".lower():
icon_name = input(Fore.CYAN + " Enter ICO file name (.ico): " + Style.RESET_ALL)
if os.path.isfile(icon_name):
print()
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
print(Fore.GREEN + f" Creating EXE file for {file_name}...")
try:
subprocess.run(["pyinstaller", "--onefile", f"--icon={icon_name}", file_name])
print(" " + Fore.BLACK + Back.GREEN + f" Created EXE file for {file_name} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
else:
print(" " + Fore.BLACK + Back.RED + " FILE DOES NOT EXIST ")
if icon_option == "n".lower():
print()
print(Fore.YELLOW + " NOTE: Run this tool from the desired project folder.")
print(Fore.GREEN + f" Creating EXE file for {file_name}...")
try:
subprocess.run(["pyinstaller", "--onefile", file_name])
print(" " + Fore.BLACK + Back.GREEN + f" Created EXE file for {file_name} ")
except subprocess.CalledProcessError:
print(" " + Fore.BLACK + Back.RED + " ERROR OCCURRED ")
else:
print(" " + Fore.BLACK + Back.RED + " FILE DOES NOT EXIST ")
elif option == "help":
print('''
(1) Install package
(2) Batch install from requirements file
(3) Update package
(4) Uninstall package
(5) Batch uninstall from requirements file
(6) Check package status
(7) Display installed packages
(8) Save requirements file
(9) Upgrade PIP version
(10) Check PIP version
(11) Check Python version
(12) Create EXE for Python file''')
else:
print(" " + Fore.BLACK + Back.RED + " INVALID OPTION ")
# Copyright © 2023 Ashfaaq Rifath - PyWizard v1.5.4