mirror of
https://github.com/iluvcapra/mfbatch.git
synced 2025-12-31 08:50:51 +00:00
Implemented substitutions in field values
This commit is contained in:
@@ -8,6 +8,7 @@ from re import match
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
import shlex
|
import shlex
|
||||||
import shutil
|
import shutil
|
||||||
|
from string import Template
|
||||||
|
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
@@ -32,7 +33,7 @@ from tqdm import tqdm
|
|||||||
# An alias for :set DESCRIPTION
|
# An alias for :set DESCRIPTION
|
||||||
# unset KEY
|
# unset KEY
|
||||||
# KEY in each subsequent file will be unset.
|
# KEY in each subsequent file will be unset.
|
||||||
# unset-all
|
# unset *
|
||||||
# No keys in each subsequent file will be set.
|
# No keys in each subsequent file will be set.
|
||||||
# set+ KEY INITIAL
|
# set+ KEY INITIAL
|
||||||
# KEY in next file will be set to INITIAL which will be incremented by
|
# KEY in next file will be set to INITIAL which will be incremented by
|
||||||
@@ -57,12 +58,8 @@ class CommandEnv:
|
|||||||
|
|
||||||
|
|
||||||
def render_substitutions(env: CommandEnv, in_str: str) -> str:
|
def render_substitutions(env: CommandEnv, in_str: str) -> str:
|
||||||
# for key in env.metadatums.keys():
|
template = Template(in_str)
|
||||||
# val = env.metadatums[key]
|
return template.substitute(env.metadatums)
|
||||||
# needle = "$" + key
|
|
||||||
# in_str = in_str.replace(needle,val)
|
|
||||||
#
|
|
||||||
return in_str
|
|
||||||
|
|
||||||
|
|
||||||
def handle_command(env: CommandEnv, line: str, dry_run: bool):
|
def handle_command(env: CommandEnv, line: str, dry_run: bool):
|
||||||
@@ -73,21 +70,21 @@ def handle_command(env: CommandEnv, line: str, dry_run: bool):
|
|||||||
if command == 'set':
|
if command == 'set':
|
||||||
key = args[1]
|
key = args[1]
|
||||||
value = args[2]
|
value = args[2]
|
||||||
env.metadatums[key] = value
|
env.metadatums[key] = render_substitutions(env, value)
|
||||||
|
|
||||||
elif command == 'd':
|
elif command == 'd':
|
||||||
env.metadatums['DESCRIPTION'] = args[1]
|
env.metadatums['DESCRIPTION'] = render_substitutions(env, args[1])
|
||||||
|
|
||||||
elif command == 'unset':
|
elif command == 'unset':
|
||||||
key = args[1]
|
key = args[1]
|
||||||
del env.metadatums[key]
|
if key == '*':
|
||||||
env.incr.discard(key)
|
all_keys = list(env.metadatums.keys())
|
||||||
|
for k in all_keys:
|
||||||
elif command == 'unset*':
|
del env.metadatums[k]
|
||||||
all_keys = list(env.metadatums.keys())
|
env.incr.discard(k)
|
||||||
for k in all_keys:
|
else:
|
||||||
del env.metadatums[k]
|
del env.metadatums[key]
|
||||||
env.incr.discard(k)
|
env.incr.discard(key)
|
||||||
|
|
||||||
elif command == 'set++':
|
elif command == 'set++':
|
||||||
key = args[1]
|
key = args[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user