diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index 60bd115..6f8c27e 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -32,7 +32,8 @@ _NAMESPACE_MEDASHARE_PATH = uuid.UUID('f6f36b62-3770-4a68-bc3d-dc3e31e429e6') _defaulthash = 'sha512' _validhashes = set([ 'sha256', 'sha512' ]) -_hashlengths = { len(getattr(hashlib, x)().hexdigest()): x for x in _validhashes } +_hashlengths = { len(getattr(hashlib, x)().hexdigest()): x for x in + _validhashes } def _keyordering(x): k, v = x @@ -56,7 +57,8 @@ def _makeuuid(s): return uuid.UUID(bytes=s) -# XXX - known issue, store is not atomic/safe, overwrites in place instead of renames +# XXX - known issue, store is not atomic/safe, overwrites in place instead of +# renames # XXX - add validation # XXX - how to add singletons @@ -81,8 +83,10 @@ class MDBase(object): _common_properties = [ 'type', 'created_by_ref' ] # XXX - add lang? _common_optional = set(('parent_refs', 'sig')) - _common_names = set(_common_properties + list(_generated_properties.keys())) - _common_names_list = _common_properties + list(_generated_properties.keys()) + _common_names = set(_common_properties + list( + _generated_properties.keys())) + _common_names_list = _common_properties + list( + _generated_properties.keys()) def __init__(self, obj={}, **kwargs): obj = copy.deepcopy(obj) @@ -198,7 +202,8 @@ class Identity(MDBase): 'created_by_ref' ] _common_optional = set([ x for x in MDBase._common_optional if x != 'parent_refs' ] + [ 'name', 'pubkey' ]) - _common_names = set(_common_properties + list(MDBase._generated_properties.keys())) + _common_names = set(_common_properties + list( + MDBase._generated_properties.keys())) def _trytodict(o): if isinstance(o, uuid.UUID): @@ -206,7 +211,8 @@ def _trytodict(o): try: return 'dict', o.__to_dict__() except Exception: # pragma: no cover - raise TypeError('unable to find __to_dict__ on %s: %s' % (type(o), repr(o))) + raise TypeError('unable to find __to_dict__ on %s: %s' % + (type(o), repr(o))) class CanonicalCoder(pasn1.ASN1DictCoder): def enc_dict(self, obj, **kwargs): @@ -234,7 +240,8 @@ class Persona(object): if 'pubkey' in self._identity: pubkeybytes = self._identity.pubkey - self._pubkey = Ed448PublicKey.from_public_bytes(pubkeybytes) + self._pubkey = Ed448PublicKey.from_public_bytes( + pubkeybytes) self._created_by_ref = self._identity.uuid @@ -311,7 +318,8 @@ class Persona(object): kwargs = {} if 'key' in objs: - kwargs['key'] = Ed448PrivateKey.from_private_bytes(objs['key']) + kwargs['key'] = Ed448PrivateKey.from_private_bytes( + objs['key']) return cls(Identity(objs['identity']), **kwargs) @@ -401,7 +409,8 @@ class ObjectStore(object): value = hashstr bvalue = value.encode('ascii') - if strict and len(bvalue.translate(None, string.hexdigits.lower().encode('ascii'))) != 0: + if strict and len(bvalue.translate(None, + string.hexdigits.lower().encode('ascii'))) != 0: raise ValueError('value has invalid hex digits (must be lower case)', value) if hash in _validhashes: @@ -486,7 +495,8 @@ class ObjectStore(object): if j: return j else: - raise KeyError('unable to find metadata for file: %s' % repr(fname)) + raise KeyError('unable to find metadata for file: %s' % + repr(fname)) def _readfp(fp): while True: @@ -539,7 +549,8 @@ def enumeratedir(_dir, created_by_ref): Returned is a list of FileObjects.''' - return [FileObject.from_file(os.path.join(_dir, x), created_by_ref) for x in os.listdir(_dir)] + return [FileObject.from_file(os.path.join(_dir, x), + created_by_ref) for x in os.listdir(_dir)] def get_objstore(options): persona = get_persona(options) @@ -562,7 +573,8 @@ def get_persona(options): try: persona = Persona.load(identfname) except FileNotFoundError: - print('ERROR: Identity not created, create w/ -g.', file=sys.stderr) + print('ERROR: Identity not created, create w/ -g.', + file=sys.stderr) sys.exit(1) return persona @@ -587,7 +599,8 @@ def cmd_ident(options): persona = Persona.load(identfname) if options.tagvalue: - persona.new_version(*(x.split('=', 1) for x in options.tagvalue)) + persona.new_version(*(x.split('=', 1) for x in + options.tagvalue)) persona.store(identfname) else: @@ -610,9 +623,11 @@ def cmd_modify(options): print('ERROR: tag needs to start with a "+" (add) or a "-" (remove).', file=sys.stderr) sys.exit(1) - badtags = list(x[1] for x in props if x[1] in (MDBase._common_names | MDBase._common_optional)) + badtags = list(x[1] for x in props if x[1] in (MDBase._common_names | + MDBase._common_optional)) if any(badtags): - print('ERROR: invalid tag%s: %s.' % ( 's' if len(badtags) > 1 else '', repr(badtags)), file=sys.stderr) + print('ERROR: invalid tag%s: %s.' % ( 's' if + len(badtags) > 1 else '', repr(badtags)), file=sys.stderr) sys.exit(1) adds = [ x[1:] for x in props if x[0] == '+' ] @@ -667,7 +682,8 @@ def cmd_list(options): print('%s:\t%s' % (k, v)) except (KeyError, FileNotFoundError): # XXX - tell the difference? - print('ERROR: file not found: %s' % repr(i), file=sys.stderr) + print('ERROR: file not found: %s' % repr(i), + file=sys.stderr) sys.exit(1) def main(): @@ -675,7 +691,8 @@ def main(): parser = argparse.ArgumentParser() - parser.add_argument('--db', '-d', type=str, help='base name for storage') + parser.add_argument('--db', '-d', type=str, + help='base name for storage') subparsers = parser.add_subparsers(title='subcommands', description='valid subcommands', help='additional help')