Use dicts instead of tuples for the qcommands.
This commit is contained in:
parent
487302ea30
commit
98c59bce13
1 changed files with 13 additions and 10 deletions
23
q.py
23
q.py
|
|
@ -47,19 +47,20 @@ def filter_collaborate(files, collaborate):
|
||||||
return newfiles
|
return newfiles
|
||||||
|
|
||||||
def get_extension_command(extension):
|
def get_extension_command(extension):
|
||||||
for (key, (command, argument)) in qcommands.EXTENSION_COMMANDS.items():
|
for (key, qcommand) in qcommands.EXTENSION_COMMANDS.items():
|
||||||
if isinstance(key, str):
|
if isinstance(key, str):
|
||||||
if key == extension:
|
if key == extension:
|
||||||
return (command, argument)
|
return qcommand
|
||||||
continue
|
continue
|
||||||
match = re.match(key, extension)
|
match = re.match(key, extension)
|
||||||
if not match:
|
if not match:
|
||||||
continue
|
continue
|
||||||
groups = match.groups()
|
groups = match.groups()
|
||||||
if not groups:
|
if not groups:
|
||||||
return (command, argument)
|
return qcommand
|
||||||
command = re.sub(key, command, extension)
|
qcommand = qcommand.copy()
|
||||||
return (command, argument)
|
qcommand['command'] = re.sub(key, qcommand['command'], extension)
|
||||||
|
return qcommand
|
||||||
|
|
||||||
def handle_blacklist(file, reason=''):
|
def handle_blacklist(file, reason=''):
|
||||||
if reason:
|
if reason:
|
||||||
|
|
@ -137,16 +138,18 @@ def process_file(file, args=None):
|
||||||
|
|
||||||
commands = []
|
commands = []
|
||||||
|
|
||||||
if file.size > 0:
|
qcommand = get_extension_command(extension)
|
||||||
|
command = qcommand['command']
|
||||||
|
argument = qcommand['argument']
|
||||||
|
|
||||||
|
if file.size > 0 and qcommand.get('read_file', True):
|
||||||
links = read_file_links(file)
|
links = read_file_links(file)
|
||||||
(command, argument) = get_extension_command(extension)
|
|
||||||
commands.extend(f'{command} "{link}"' for link in links)
|
commands.extend(f'{command} "{link}"' for link in links)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
(command, argument) = get_extension_command(extension)
|
|
||||||
base = file.replace_extension('').basename
|
base = file.replace_extension('').basename
|
||||||
argument = argument.format(id=base)
|
argument = argument.format(id=base, abspath=file.absolute_path)
|
||||||
commands.append(f'{command} {argument}')
|
commands.append(f'{command} -- {argument}')
|
||||||
|
|
||||||
exit_code = 0
|
exit_code = 0
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue