Browse Source

wrap lines

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

+ 34
- 17
ui/medashare/cli.py View File

@@ -32,7 +32,8 @@ _NAMESPACE_MEDASHARE_PATH = uuid.UUID('f6f36b62-3770-4a68-bc3d-dc3e31e429e6')


_defaulthash = 'sha512' _defaulthash = 'sha512'
_validhashes = set([ 'sha256', '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): def _keyordering(x):
k, v = x k, v = x
@@ -56,7 +57,8 @@ def _makeuuid(s):


return uuid.UUID(bytes=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 - add validation
# XXX - how to add singletons # XXX - how to add singletons
@@ -81,8 +83,10 @@ class MDBase(object):


_common_properties = [ 'type', 'created_by_ref' ] # XXX - add lang? _common_properties = [ 'type', 'created_by_ref' ] # XXX - add lang?
_common_optional = set(('parent_refs', 'sig')) _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): def __init__(self, obj={}, **kwargs):
obj = copy.deepcopy(obj) obj = copy.deepcopy(obj)
@@ -198,7 +202,8 @@ class Identity(MDBase):
'created_by_ref' ] 'created_by_ref' ]
_common_optional = set([ x for x in MDBase._common_optional if x != _common_optional = set([ x for x in MDBase._common_optional if x !=
'parent_refs' ] + [ 'name', 'pubkey' ]) '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): def _trytodict(o):
if isinstance(o, uuid.UUID): if isinstance(o, uuid.UUID):
@@ -206,7 +211,8 @@ def _trytodict(o):
try: try:
return 'dict', o.__to_dict__() return 'dict', o.__to_dict__()
except Exception: # pragma: no cover 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): class CanonicalCoder(pasn1.ASN1DictCoder):
def enc_dict(self, obj, **kwargs): def enc_dict(self, obj, **kwargs):
@@ -234,7 +240,8 @@ class Persona(object):


if 'pubkey' in self._identity: if 'pubkey' in self._identity:
pubkeybytes = self._identity.pubkey 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 self._created_by_ref = self._identity.uuid


@@ -311,7 +318,8 @@ class Persona(object):


kwargs = {} kwargs = {}
if 'key' in objs: 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) return cls(Identity(objs['identity']), **kwargs)


@@ -401,7 +409,8 @@ class ObjectStore(object):
value = hashstr value = hashstr


bvalue = value.encode('ascii') 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) raise ValueError('value has invalid hex digits (must be lower case)', value)


if hash in _validhashes: if hash in _validhashes:
@@ -486,7 +495,8 @@ class ObjectStore(object):
if j: if j:
return j return j
else: 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): def _readfp(fp):
while True: while True:
@@ -539,7 +549,8 @@ def enumeratedir(_dir, created_by_ref):


Returned is a list of FileObjects.''' 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): def get_objstore(options):
persona = get_persona(options) persona = get_persona(options)
@@ -562,7 +573,8 @@ def get_persona(options):
try: try:
persona = Persona.load(identfname) persona = Persona.load(identfname)
except FileNotFoundError: 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) sys.exit(1)


return persona return persona
@@ -587,7 +599,8 @@ def cmd_ident(options):
persona = Persona.load(identfname) persona = Persona.load(identfname)


if options.tagvalue: 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) persona.store(identfname)
else: else:
@@ -610,9 +623,11 @@ def cmd_modify(options):
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)
sys.exit(1) 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): 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) sys.exit(1)


adds = [ x[1:] for x in props if x[0] == '+' ] adds = [ x[1:] for x in props if x[0] == '+' ]
@@ -667,7 +682,8 @@ def cmd_list(options):
print('%s:\t%s' % (k, v)) print('%s:\t%s' % (k, v))
except (KeyError, FileNotFoundError): except (KeyError, FileNotFoundError):
# XXX - tell the difference? # 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) sys.exit(1)


def main(): def main():
@@ -675,7 +691,8 @@ def main():


parser = argparse.ArgumentParser() 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', subparsers = parser.add_subparsers(title='subcommands',
description='valid subcommands', help='additional help') description='valid subcommands', help='additional help')


Loading…
Cancel
Save