Try to figure out revision, drop -rv/--revision argument

This commit is contained in:
Erovia 2019-10-10 22:58:52 +02:00 committed by skullydazed
parent c3b168e6fd
commit e46cc2db8c

View file

@ -26,11 +26,12 @@ def unicode_lines(filename):
def parse_rules_mk(keyboard, revision = ""):
base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep
rules_mk = dict()
if os.path.exists(base_path + os.path.sep + revision):
rules_mk_path_wildcard = os.path.join(base_path, "**", "rules.mk")
rules_mk_regex = re.compile(r"^" + base_path + "(?:" + revision + os.path.sep + ")?rules.mk")
paths = [path for path in glob.iglob(rules_mk_path_wildcard, recursive = True) if rules_mk_regex.search(path)]
rules_mk = dict()
config_regex = re.compile(r"^\s*(\S+)\s*=\s*((?:\s*\S+)+)")
for file_path in paths:
rules_mk_content = unicode_lines(file_path)
@ -47,31 +48,32 @@ def find_keymaps(base_path, revision = "", community = False):
path_wildcard = os.path.join(base_path, "**", "keymap.c")
if community:
path_regex = re.compile(r"^" + re.escape(base_path) + "(\S+)" + os.path.sep + "keymap\.c")
names = [revision + os.path.sep + path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True)]
else:
path_regex = re.compile(r"^" + re.escape(base_path) + "(?:" + re.escape(revision) + os.path.sep + ")?keymaps" + os.path.sep + "(\S+)" + os.path.sep + "keymap\.c")
names = [revision + os.path.sep + path_regex.sub(lambda name: name.group(1), path) if revision else path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True) if path_regex.search(path)]
names = [path_regex.sub(lambda name: name.group(1), path) for path in glob.iglob(path_wildcard, recursive = True) if path_regex.search(path)]
return names
@cli.argument("-kb", "--keyboard", help="Specify keyboard name. Example: 1upkeyboards/1up60hse")
@cli.argument("-rv", "--revision", help="Specify the revison name. Example: rev6")
@cli.subcommand("List the keymaps for a specific keyboard")
def list_keymaps(cli):
"""List the keymaps for a specific keyboard
"""
# ask for user input if keyboard was not provided in the command line
keyboard = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ")
revision = cli.config.list_keymaps.revision if cli.config.list_keymaps.revision else ""
keyboard_name = cli.config.list_keymaps.keyboard if cli.config.list_keymaps.keyboard else input("Keyboard Name: ")
if os.path.sep in keyboard_name:
keyboard, revision = os.path.split(os.path.normpath(keyboard_name))
else:
keyboard = keyboard_name
revision = ""
# get all the rules.mk files for the keyboard
rules_mk = parse_rules_mk(keyboard, revision)
names = list()
if rules_mk:
if "base" in rules_mk or revision:
keyboard_name = keyboard + os.path.sep + revision
kb_base_path = os.path.join(os.getcwd(), "keyboards", keyboard) + os.path.sep
names = find_keymaps(kb_base_path, revision)
else:
names = list()
for rev, data in rules_mk.items():
if "LAYOUTS" in data:
@ -83,4 +85,4 @@ def list_keymaps(cli):
for name in names:
# We echo instead of cli.log.info to allow easier piping of this output
cli.echo(keyboard + os.path.sep + name)
cli.echo(keyboard_name + os.path.sep + name)