|
1 | 1 | import os
|
| 2 | +import sys |
2 | 3 | import subprocess
|
3 | 4 | import importlib
|
4 | 5 | import pkgutil
|
5 | 6 |
|
6 | 7 | if pkgutil.find_loader("colorama") is None:
|
7 | 8 | subprocess.check_call(["pip", "install", "colorama"])
|
| 9 | + #installs colorama automatically |
8 | 10 | else:
|
9 | 11 | pass
|
10 | 12 | import colorama
|
11 | 13 | from colorama import Fore, Back, Style
|
12 | 14 | colorama.init(autoreset=True)
|
13 | 15 |
|
| 16 | +#clears terminal |
14 | 17 | os.system("cls")
|
15 | 18 | print('''
|
16 | 19 | █▀▀█ ▀█▀ █▀▀█ █ █ ▀█▀ █▀▀▀█ █▀▀█ █▀▀█ █▀▀▄
|
17 | 20 | █▄▄█ █ █▄▄█ █ █ █ █ ▄▄▄▀▀ █▄▄█ █▄▄▀ █ █
|
18 |
| - █ ▄█▄ █ █▄▀▄█ ▄█▄ █▄▄▄█ █ █ █ █ █▄▄▀ v1.5.0''') |
| 21 | + █ ▄█▄ █ █▄▀▄█ ▄█▄ █▄▄▄█ █ █ █ █ █▄▄▀ v1.5.1''') |
19 | 22 | print(Fore.YELLOW + " PYTHON PACKAGE MANAGER")
|
20 | 23 | print('''
|
21 | 24 | (1) Install package
|
|
25 | 28 | (5) Batch uninstall from requirements file
|
26 | 29 | (6) Check package status
|
27 | 30 | (7) Display installed packages
|
28 |
| - (8) Save requirements file''') |
| 31 | + (8) Save requirements file |
| 32 | + (9) Exit''') |
29 | 33 |
|
30 | 34 |
|
31 | 35 | while True:
|
| 36 | + print() |
32 | 37 | option = input(Fore.CYAN + " Enter option: " + Style.RESET_ALL)
|
33 | 38 | if option == "1":
|
34 | 39 | print()
|
|
37 | 42 | try:
|
38 | 43 | subprocess.check_call(["pip", "install", install_pkg])
|
39 | 44 | print(" " + Fore.BLACK + Back.GREEN + f" Installed {install_pkg} ")
|
40 |
| - print() |
41 |
| - input(" Press Enter to exit...") |
| 45 | + #input(" Press Enter to exit...") |
42 | 46 | except subprocess.CalledProcessError:
|
43 | 47 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
44 |
| - print() |
45 |
| - input(" Press Enter to exit...") |
46 |
| - break |
| 48 | + #input(" Press Enter to exit...") |
| 49 | + #break |
47 | 50 |
|
48 | 51 | elif option == "2":
|
49 | 52 | print()
|
|
59 | 62 | print()
|
60 | 63 | except subprocess.CalledProcessError:
|
61 | 64 | print(" " + Fore.BLACK + Back.RED + " AN ERROR OCCURED ")
|
62 |
| - print() |
63 |
| - input(" Press Enter to exit...") |
64 |
| - break |
| 65 | + #input(" Press Enter to exit...") |
| 66 | + #break |
65 | 67 |
|
66 | 68 | elif option == "3":
|
67 | 69 | print()
|
|
70 | 72 | try:
|
71 | 73 | subprocess.check_call(["pip", "install", "--upgrade", update_pkg])
|
72 | 74 | print(" " + Fore.BLACK + Back.GREEN + f" Updated {update_pkg} ")
|
73 |
| - print() |
74 |
| - input(" Press Enter to exit...") |
| 75 | + #input(" Press Enter to exit...") |
75 | 76 | except subprocess.CalledProcessError:
|
76 | 77 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
77 |
| - print() |
78 |
| - input(" Press Enter to exit...") |
79 |
| - break |
| 78 | + #input(" Press Enter to exit...") |
| 79 | + #break |
80 | 80 |
|
81 | 81 | elif option == "4":
|
82 | 82 | print()
|
|
86 | 86 | subprocess.check_call(["pip", "uninstall", uninstall_pkg])
|
87 | 87 | print(" " + Fore.BLACK + Back.RED + f" Uninstalled {uninstall_pkg} ")
|
88 | 88 | print()
|
89 |
| - input(" Press Enter to exit...") |
| 89 | + #input(" Press Enter to exit...") |
90 | 90 | except subprocess.CalledProcessError:
|
91 | 91 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
92 |
| - print() |
93 |
| - input(" Press Enter to exit...") |
94 |
| - break |
| 92 | + #input(" Press Enter to exit...") |
| 93 | + #break |
95 | 94 |
|
96 | 95 | elif option == "5":
|
97 | 96 | print()
|
|
105 | 104 | try:
|
106 | 105 | subprocess.check_call(["pip", "uninstall", "-y", pkg])
|
107 | 106 | print(" " + Fore.BLACK + Back.RED + f" Uinstalled {pkg} ")
|
108 |
| - print() |
109 | 107 | except subprocess.CalledProcessError:
|
110 | 108 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
111 |
| - print() |
112 |
| - input(" Press Enter to exit...") |
113 |
| - #os._exit(0) |
114 |
| - break |
115 | 109 |
|
116 | 110 | elif option == "6":
|
117 | 111 | print()
|
|
120 | 114 | try:
|
121 | 115 | subprocess.check_call(["pip", "show", verify_pkg])
|
122 | 116 | print(" " + Fore.BLACK + Back.GREEN + f" {verify_pkg} package exists ")
|
123 |
| - print() |
124 |
| - input(" Press Enter to exit...") |
| 117 | + #input(" Press Enter to exit...") |
125 | 118 | except subprocess.CalledProcessError:
|
126 | 119 | print(" " + Fore.BLACK + Back.RED + " PACKAGE NOT FOUND ")
|
127 |
| - print() |
128 |
| - input(" Press Enter to exit...") |
129 |
| - break |
| 120 | + #input(" Press Enter to exit...") |
| 121 | + #break |
130 | 122 |
|
131 | 123 | elif option == "7":
|
132 | 124 | print()
|
133 | 125 | print(Fore.GREEN + " Displaying all installed packages...")
|
134 |
| - |
135 | 126 | subprocess.check_call(["pip", "list"])
|
136 |
| - print() |
137 |
| - input(" Press Enter to exit...") |
138 |
| - break |
| 127 | + |
| 128 | + # run pip list command and capture output |
| 129 | + output = subprocess.check_output(["pip", "list"]) |
| 130 | + with open("packages.txt", "w") as f: |
| 131 | + f.write(output.decode("utf-8")) |
139 | 132 |
|
140 | 133 | elif option == "8":
|
141 | 134 | print()
|
|
146 | 139 | save = subprocess.run(["pip", "freeze"], stdout=subprocess.PIPE)
|
147 | 140 | with open('requirements.txt', 'wb') as f:
|
148 | 141 | f.write(save.stdout)
|
149 |
| - |
150 | 142 | print(" " + Fore.BLACK + Back.GREEN + " PROJECT REQUIREMENTS SAVED ")
|
151 |
| - print() |
152 |
| - input(" Press Enter to exit...") |
153 | 143 | except subprocess.CalledProcessError:
|
154 | 144 | print(" " + Fore.BLACK + Back.RED + " AN ERROR OCCURED ")
|
155 |
| - print() |
156 |
| - input(" Press Enter to exit...") |
157 |
| - break |
| 145 | + |
| 146 | + elif option == "help": |
| 147 | + print(''' |
| 148 | + (1) Install package |
| 149 | + (2) Batch install from requirements file |
| 150 | + (3) Update package |
| 151 | + (4) Uninstall package |
| 152 | + (5) Batch uninstall from requirements file |
| 153 | + (6) Check package status |
| 154 | + (7) Display installed packages |
| 155 | + (8) Save requirements file |
| 156 | + (9) Exit''') |
| 157 | + |
| 158 | + elif option == "9": |
| 159 | + os._exit(0) #exits program |
158 | 160 | else:
|
159 | 161 | print(" " + Fore.BLACK + Back.RED + " INVALID OPTION ")
|
160 |
| - print() |
161 | 162 |
|
162 | 163 |
|
163 |
| -# Copyright © 2023 Ashfaaq Rifath - PipWizard v1.5.0 |
| 164 | + |
| 165 | +# Copyright © 2023 Ashfaaq Rifath - PipWizard v1.5.1 |
0 commit comments