Browse Source

support specifying multiple files at once

main
John-Mark Gurney 2 years ago
parent
commit
de98507cd3
1 changed files with 27 additions and 2 deletions
  1. +27
    -2
      ui/medashare/cli.py

+ 27
- 2
ui/medashare/cli.py View File

@@ -204,6 +204,9 @@ class MDBase(object):
return self._obj[k]

def __to_dict__(self):
'''Returns an internal object. If modification is necessary,
make sure to .copy() it first.'''

return self._obj

def __eq__(self, o):
@@ -736,6 +739,17 @@ def cmd_pubkey(options):
def cmd_modify(options):
persona, objstr = get_objstore(options)

# because of how argparse works, only one file will be collected
# multiple files will end up in modtagvalues, so we need to
# find and move them.

for idx, i in enumerate(options.modtagvalues):
if i[0] not in { '+', '-' }:
# move remaining files
options.files[0:0] = options.modtagvalues[idx:]
del options.modtagvalues[idx:]
break

props = [[ x[0] ] + x[1:].split('=', 1) for x in options.modtagvalues]
if any(x[0] not in ('+', '-') for x in props):
print('ERROR: tag needs to start with a "+" (add) or a "-" (remove).', file=sys.stderr)
@@ -760,14 +774,24 @@ def cmd_modify(options):
# Get MetaData
try:
objs = objstr.by_file(i)
#print('x:', repr(objs), file=_real_stderr)
except KeyError:
fobj = persona.by_file(i)
try:
fobj = persona.by_file(i)
except FileNotFoundError:
print('ERROR: file not found: %s, or invalid tag specification.' % repr(i), file=sys.stderr)
sys.exit(1)

objstr.loadobj(fobj)
objs = [ persona.MetaData(hashes=fobj.hashes) ]
#print('y:', repr(objs), file=_real_stderr)

#print('b:', repr(i), repr(objs), file=_real_stderr)
for j in objs:
#print('c:', repr(j), file=_real_stderr)
# make into key/values
obj = j.__to_dict__()
# copy as we modify it later, which is bad
obj = j.__to_dict__().copy()

# delete tags
for k in dels:
@@ -782,6 +806,7 @@ def cmd_modify(options):
for k, v in adds:
obj.setdefault(k, []).append(v)

#print('a:', repr(obj), file=_real_stderr)
del obj['modified']
nobj = MDBase.create_obj(obj)



Loading…
Cancel
Save