| @@ -204,6 +204,9 @@ class MDBase(object): | |||||
| return self._obj[k] | return self._obj[k] | ||||
| def __to_dict__(self): | def __to_dict__(self): | ||||
| '''Returns an internal object. If modification is necessary, | |||||
| make sure to .copy() it first.''' | |||||
| return self._obj | return self._obj | ||||
| def __eq__(self, o): | def __eq__(self, o): | ||||
| @@ -736,6 +739,17 @@ def cmd_pubkey(options): | |||||
| def cmd_modify(options): | def cmd_modify(options): | ||||
| persona, objstr = get_objstore(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] | props = [[ x[0] ] + x[1:].split('=', 1) for x in options.modtagvalues] | ||||
| if any(x[0] not in ('+', '-') for x in props): | 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) | 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 | # Get MetaData | ||||
| try: | try: | ||||
| objs = objstr.by_file(i) | objs = objstr.by_file(i) | ||||
| #print('x:', repr(objs), file=_real_stderr) | |||||
| except KeyError: | 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) | objstr.loadobj(fobj) | ||||
| objs = [ persona.MetaData(hashes=fobj.hashes) ] | 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: | for j in objs: | ||||
| #print('c:', repr(j), file=_real_stderr) | |||||
| # make into key/values | # make into key/values | ||||
| obj = j.__to_dict__() | |||||
| # copy as we modify it later, which is bad | |||||
| obj = j.__to_dict__().copy() | |||||
| # delete tags | # delete tags | ||||
| for k in dels: | for k in dels: | ||||
| @@ -782,6 +806,7 @@ def cmd_modify(options): | |||||
| for k, v in adds: | for k, v in adds: | ||||
| obj.setdefault(k, []).append(v) | obj.setdefault(k, []).append(v) | ||||
| #print('a:', repr(obj), file=_real_stderr) | |||||
| del obj['modified'] | del obj['modified'] | ||||
| nobj = MDBase.create_obj(obj) | nobj = MDBase.create_obj(obj) | ||||