You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
164 lines
4.5 KiB
164 lines
4.5 KiB
#!/usr/bin/env python3
|
|
'''
|
|
Specify a label or search term, optionally with a page #.
|
|
|
|
Examples:
|
|
# label:
|
|
enlynx.py Bucket_Game
|
|
# Use a different binary name or path other than lynx:
|
|
enlynx.py Bucket_Game --browser surfraw
|
|
# label and page number:
|
|
enlynx.py Bucket_Game page 2
|
|
# multiple labels:
|
|
enlynx.py Bucket_Game urgent
|
|
# closed issues only:
|
|
enlynx.py Bucket_Game --closed
|
|
# both closed and open issues:
|
|
enlynx.py Bucket_Game --closed --open
|
|
# search:
|
|
enlynx.py find SIGSEGV
|
|
# search for 2 terms:
|
|
enlynx.py find mobs find walk
|
|
# or
|
|
enlynx.py find mobs AND walk
|
|
# search for a closed issue:
|
|
enlynx.py find SIGSEGV --closed
|
|
# label with search:
|
|
enlynx.py Bucket_Game find mobs
|
|
# label with search, next page:
|
|
enlynx.py Bucket_Game find node page 2
|
|
|
|
|
|
'''
|
|
import sys
|
|
import subprocess
|
|
me = "enlynx.py"
|
|
browserPath = "lynx"
|
|
sessionPath = "/tmp/enlynx.lynx-session"
|
|
|
|
enc = {} # URL Encoded single characters
|
|
enc[':'] = '%3A'
|
|
# ^ Do this with urllib if there are many more
|
|
|
|
verbose = True
|
|
|
|
|
|
def echo0(*args, **kwargs):
|
|
print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
|
def echo1(*args, **kwargs):
|
|
if not verbose:
|
|
return
|
|
print(*args, file=sys.stderr, **kwargs)
|
|
|
|
|
|
def usage():
|
|
echo0(__doc__)
|
|
|
|
|
|
def toSubQueryValue(value):
|
|
'''
|
|
Convert the value to one that will fit in a
|
|
key+urlencoded(colon)+value string for GitHub queries.
|
|
|
|
This function is copied to multiple scripts so they have no
|
|
dependencies:
|
|
- enissue.py
|
|
- enlynx.py
|
|
'''
|
|
if " " in value:
|
|
value = '"' + value.replace(" ", "+") + '"'
|
|
return value
|
|
|
|
|
|
def toSubQuery(key, value):
|
|
return key + enc[':'] + value
|
|
|
|
|
|
base_url = "https://github.com/poikilos/EnlivenMinetest"
|
|
query_url = base_url + "/issues"
|
|
open_q = "?q=" + toSubQuery("is", "issue") + '+' + toSubQuery("is", "open")
|
|
any_q = "?q=" + toSubQuery("is", "issue")
|
|
closed_q = "?q=" + toSubQuery("is", "issue") + '+' + toSubQuery("is", "closed")
|
|
|
|
|
|
def main():
|
|
global browserPath
|
|
prev_arg = None
|
|
findStrings = []
|
|
base_q = open_q + "+"
|
|
page_param = ""
|
|
_closed = None
|
|
_open = None
|
|
labels_subqueries = ""
|
|
for arg in sys.argv[1:]:
|
|
# ^ skip arg 0 since it is self
|
|
# Erase prev_arg in each case except "else" to turn off
|
|
# context-sensitivity after the term after the command is found.
|
|
if (prev_arg == "find") or (prev_arg == "AND"):
|
|
findStrings.append(arg)
|
|
prev_arg = None
|
|
elif prev_arg == "--browser":
|
|
browserPath = arg
|
|
elif prev_arg == "page":
|
|
page_param = "&page=2"
|
|
prev_arg = None
|
|
else:
|
|
if arg == "--closed":
|
|
_closed = True
|
|
elif arg == "--open":
|
|
_open = True
|
|
elif arg == "find":
|
|
prev_arg = arg
|
|
elif arg == "--browser":
|
|
prev_arg = arg
|
|
elif arg == "AND":
|
|
if len(findStrings) == 0:
|
|
usage()
|
|
echo0("Error: You can only use AND after find"
|
|
" and after another keyword. To literally"
|
|
" search for the word \"AND\" itself,"
|
|
" say find before the word:\n"
|
|
" {} find CREEPS find AND find WEIRDOS\n"
|
|
"".format(me))
|
|
return 1
|
|
prev_arg = arg
|
|
elif arg == "page":
|
|
prev_arg = arg
|
|
else:
|
|
encArg = toSubQueryValue(arg)
|
|
# if encArg != arg:
|
|
# echo1("* encoding label as '{}'".format(encArg))
|
|
# else:
|
|
echo1("* adding label {}".format(encArg))
|
|
|
|
labels_subqueries += toSubQuery('label', encArg) + "+"
|
|
|
|
# Ensure there aren't any dangling commands *after* the loop:
|
|
if prev_arg is not None:
|
|
usage()
|
|
echo0("Error: You must specify a search term after {}."
|
|
"".format(prev_arg))
|
|
return 1
|
|
|
|
if (_closed is True) and (_open is True):
|
|
base_q = any_q + '+'
|
|
elif _open is True:
|
|
base_q = open_q + '+' # This is the default
|
|
elif _closed is True:
|
|
base_q = closed_q + '+'
|
|
|
|
for find_str in findStrings:
|
|
base_q += find_str + "+"
|
|
# else: (dangling '+' at the end when labels_subqueries=="" is ok)
|
|
|
|
query = base_q + labels_subqueries + page_param
|
|
url = query_url + query
|
|
print("URL: {}".format(url))
|
|
|
|
subprocess.call([browserPath, '-session=' + sessionPath, url])
|
|
return 0
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|
|
|