Skip to content

Commit

Permalink
paging mode is available now
Browse files Browse the repository at this point in the history
  • Loading branch information
MAGANER committed Mar 10, 2024
1 parent 6216067 commit 6117b48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@

converted = dict(json.loads(response.text))["results"]
found_packages = [aurwatcher.extract_required_info(x,args["s"]) for x in converted]
aurwatcher.print_result(found_packages,True)
aurwatcher.print_result(found_packages,args["o"])

30 changes: 22 additions & 8 deletions aurwatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@
import sys
from functools import reduce
import subprocess
from getch import read_single_char

def print_help():
options = '''
arch-watcher looks for packages in AUR or in official repository.\n\n
./arch-watcher p=emacs s=[aur|off]\n
./arch-watcher p=emacs s=[aur|off] o=[pt|ip]\n
p - package name \n
s - source(aur xor official repo) \n
o - output mode(plain text xor inner pager)\n
o - output mode(plain text xor inner pager) plain text is choosen by default\n
'''
print(options)

def process_mode(mode_value):
if mode_value not in ("pt","ip"):
print("incorrect value for ouput mode {}".format(mode_value))
print_help()
sys.exit(1)

return False if mode_value == "pt" else True
def parse_arguments():
'''returns the hash-table of arguments'''

Expand All @@ -27,10 +34,11 @@ def parse_arguments():
sys.exit(1)

table = {} #key is argument name and value is argument's value

#p - package
#s - source
available_keys = "ps"
#o - output
available_keys = "pso"

for arg in sys.argv[1:]:
#try to parse argument
Expand All @@ -44,11 +52,14 @@ def parse_arguments():
#key should exist as available key and it must not be added already
if left in available_keys and left not in table.keys():
table[left] = right
if left == "o":
table[left] = process_mode(right)
else:
print("key is used already or doesn't exist!")
print_help()
sys.exit(1)


if "o" not in table.keys(): table["o"] = False #plain text by default
return table

def compute_request(args):
Expand Down Expand Up @@ -79,14 +90,17 @@ def extract_required_info(response_result,source):
return data


def __print_all(response):
def print_result(response, paging_mode=False):
for id,item in enumerate(response):
print("found item #{}".format(id))
print("-"*40)
for k in item.keys():
print("{}:{}".format(k,item[k]))
print("-"*40)
if paging_mode:
if read_single_char() == 'q':
sys.exit(0)
else:
subprocess.run(["clear"])

def print_result(response,use_pager=False):
__print_all(response)

0 comments on commit 6117b48

Please sign in to comment.