-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
import os | ||
import subprocess | ||
from rich.panel import Panel | ||
from rich.columns import Columns | ||
from rich.console import Console | ||
from dankware import title, cls, clr, align, rm_line | ||
from dankware import white, white_normal, red, red_normal, red_dim, green | ||
|
||
def winget_installed(): | ||
try: | ||
result = subprocess.run(['winget', '--info'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if result.returncode == 0: | ||
return True | ||
else: | ||
return False | ||
except FileNotFoundError: | ||
return False | ||
|
||
def print_banner(): | ||
banner = "\n\n _ _ _ _ \n _| |___ ___| |_ _ _ _|_|___ ___ ___| |_ \n| . | .'| | '_|_| | | | | | . | -_| _|\n|___|__,|_|_|_,_|_|_____|_|_|_|_ |___|_| \n |___| \n\n\n" | ||
cls(); print(clr(align(banner),4,colours=[white, white_normal, red, red_normal, red_dim])) | ||
print(clr(" [ Commands ]\n\n - search NAME (to find software)\n\n - installed (installed software, winget only)\n\n - updates\n\n - clear (refresh screen)\n\n - exit\n")) | ||
|
||
def handle_response(cmd, results, mode): | ||
|
||
cmd = cmd.stdout.decode('utf-8').split('Source')[1].splitlines()[2:] | ||
indexes = [] | ||
|
||
prev = '' | ||
for index, char in enumerate(cmd[0]): | ||
if prev == ' ' and char != ' ': | ||
indexes.append(index) | ||
prev = char | ||
for line in cmd[1:]: | ||
prev = '' | ||
for index, char in enumerate(line): | ||
if prev == ' ' and char != ' ' and index in indexes: | ||
indexes.append(index) | ||
prev = char | ||
|
||
max_count = max([indexes.count(_) for _ in sorted(list(set(indexes)))]) | ||
indexes = [_ for _ in sorted(list(set(indexes))) if indexes.count(_) == max_count] | ||
indexes.insert(0,0) | ||
results.clear() | ||
index = 1 | ||
|
||
for line in cmd: | ||
parts = [line[i:j] for i,j in zip(indexes, indexes[1:]+[None])] | ||
if '.' in parts[1].strip(): | ||
results[index] = {'name': parts[0].strip(), 'id': parts[1].strip()}#, 'version': parts[2].strip(), 'source': parts[3].strip()} | ||
index += 1 | ||
|
||
console = Console() | ||
user_renderables = [f"[b][bright_white]{key} [bright_red]- [bright_white]{value['name']}[/b]" for key, value in results.items()] | ||
results['mode'] = mode; print() | ||
console.print(Panel(title=f"[red1]> [bright_white][b]R E S U L T S[/b] [red1]<", title_align="center", renderable=Columns(user_renderables, expand=True), style="bright_red", expand=True)) | ||
|
||
if mode == 'search': | ||
print(clr("\n - Type number to install.\n")) | ||
elif mode == 'installed': | ||
print(clr("\n - Type number to display info.\n")) | ||
elif mode == 'updates': | ||
print(clr("\n - Type number to update.\n")) | ||
|
||
def print_info(id): | ||
cmd = subprocess.run(['winget', 'show', '--id', id], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if cmd.returncode == 0: | ||
print(clr(cmd.stdout.decode('utf-8'))) | ||
else: | ||
print(clr(f"\n [ERROR]: {cmd.stderr.decode('utf-8')}\n",2)) | ||
|
||
def main(): | ||
|
||
results = {} | ||
print_banner() | ||
|
||
while True: | ||
|
||
cmd = input(clr(' > ') + green) | ||
|
||
if cmd.lower().startswith('search '): | ||
cmd = subprocess.run(['winget', 'search', '--accept-source-agreements', cmd[7:]], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if cmd.returncode == 0: | ||
handle_response(cmd, results, 'search') | ||
else: | ||
print(clr(f"\n [ERROR]: {cmd.stderr.decode('utf-8')}\n",2)) | ||
|
||
elif cmd.lower().startswith('installed'): | ||
cmd = subprocess.run(['winget', 'list', '--accept-source-agreements'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if cmd.returncode == 0: | ||
handle_response(cmd, results, 'installed') | ||
else: | ||
print(clr(f"\n [ERROR]: {cmd.stderr.decode('utf-8')}\n",2)) | ||
|
||
elif cmd.lower().startswith('updates'): | ||
cmd = subprocess.run(['winget', 'upgrade', '--accept-source-agreements'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
if cmd.returncode == 0: | ||
handle_response(cmd, results, 'updates') | ||
else: | ||
print(clr(f"\n [ERROR]: {cmd.stderr.decode('utf-8')}\n",2)) | ||
|
||
elif cmd.isdigit(): | ||
|
||
if results: | ||
cmd = int(cmd) | ||
if cmd in results.keys(): | ||
|
||
if results['mode'] == 'search': | ||
if input(clr("\n > Display info? [y/n]: ") + green).lower().startswith('y'): | ||
print_info(results[cmd]['id']) | ||
else: rm_line(); rm_line() | ||
if input(clr("\n > Install? [y/n]: ") + green).lower().startswith('y'): | ||
print() | ||
os.system(f"winget install --interactive --id {results[cmd]['id']}") | ||
print() | ||
else: rm_line() | ||
|
||
elif results['mode'] == 'installed': | ||
print_info(results[cmd]['id']) | ||
|
||
elif results['mode'] == 'updates': | ||
print() | ||
os.system(f"winget upgrade --interactive --id {results[cmd]['id']}") | ||
print() | ||
|
||
else: rm_line() | ||
else: rm_line() | ||
else: rm_line() | ||
|
||
elif cmd.lower().startswith('clear'): | ||
print_banner() | ||
|
||
elif cmd.lower().startswith('exit'): | ||
break | ||
|
||
else: | ||
rm_line() | ||
|
||
if __name__ == "__main__": | ||
|
||
title("𝚍𝚊𝚗𝚔.𝚠𝚒𝚗𝚐𝚎𝚝") | ||
|
||
if os.name != 'nt': | ||
input(clr("\n - This module only works for Windows! Press ENTER to exit... ",2)) | ||
elif not winget_installed(): | ||
input(clr("\n - This module requires winget to be installed! Press ENTER to exit... ",2)) | ||
else: | ||
main() | ||
|
||
if "DANK_TOOL_VERSION" in os.environ: | ||
del main, winget_installed, print_banner, handle_response, print_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
3.2.1 | ||
3.2.2 |
Binary file not shown.