Browse Source

standardize path name fetching...

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

+ 16
- 9
ui/medashare/cli.py View File

@@ -773,13 +773,18 @@ class TagCache:
with open(fname, 'wb') as fp: with open(fname, 'wb') as fp:
fp.write(_asn1coder.dumps(cache)) fp.write(_asn1coder.dumps(cache))


def _get_paths(options):
identfname = os.path.expanduser('~/.medashare_identity.pasn1')
storefname = os.path.expanduser('~/.medashare_store.sqlite3')
cachefname = os.path.expanduser('~/.medashare_cache.pasn1')

return identfname, storefname, cachefname

def init_datastructs(f): def init_datastructs(f):
@functools.wraps(f) @functools.wraps(f)
def wrapper(options): def wrapper(options):


identfname = os.path.expanduser('~/.medashare_identity.pasn1')
storefname = os.path.expanduser('~/.medashare_store.sqlite3')
cachefname = os.path.expanduser('~/.medashare_cache.pasn1')
identfname, storefname, cachefname = _get_paths(options)


# create the persona # create the persona
try: try:
@@ -806,7 +811,7 @@ def init_datastructs(f):
return wrapper return wrapper


def cmd_genident(options): def cmd_genident(options):
identfname = os.path.expanduser('~/.medashare_identity.pasn1')
identfname, _, _ = _get_paths(options)


if os.path.exists(identfname): if os.path.exists(identfname):
print('Error: Identity already created.', file=sys.stderr) print('Error: Identity already created.', file=sys.stderr)
@@ -820,7 +825,7 @@ def cmd_genident(options):
persona.store(identfname) persona.store(identfname)


def cmd_ident(options): def cmd_ident(options):
identfname = os.path.expanduser('~/.medashare_identity.pasn1')
identfname, _, _ = _get_paths(options)


persona = Persona.load(identfname) persona = Persona.load(identfname)


@@ -835,7 +840,7 @@ def cmd_ident(options):
print('%s:\t%s' % (k, v)) print('%s:\t%s' % (k, v))


def cmd_pubkey(options): def cmd_pubkey(options):
identfname = os.path.expanduser('~/.medashare_identity.pasn1')
identfname, _, _ = _get_paths(options)


persona = Persona.load(identfname) persona = Persona.load(identfname)


@@ -2110,7 +2115,9 @@ class _TestCases(unittest.TestCase):
self.assertEqual(stdout.getvalue(), '') self.assertEqual(stdout.getvalue(), '')


# looks up the correct file # looks up the correct file
eu.assert_called_with('~/.medashare_identity.pasn1')
eu.assert_any_call('~/.medashare_identity.pasn1')
eu.assert_any_call('~/.medashare_store.sqlite3')
eu.assert_any_call('~/.medashare_cache.pasn1')


# and that the identity # and that the identity
persona = Persona.load(identfname) persona = Persona.load(identfname)
@@ -2133,7 +2140,7 @@ class _TestCases(unittest.TestCase):
'Error: Identity already created.\n') 'Error: Identity already created.\n')


# and looked up the correct file # and looked up the correct file
eu.assert_called_with('~/.medashare_identity.pasn1')
eu.assert_any_call('~/.medashare_identity.pasn1')


# that when updating the identity # that when updating the identity
with mock.patch('sys.stdout', io.StringIO()) as stdout, mock.patch('sys.argv', [ 'progname', 'ident', 'name=Changed Name' ]) as argv: with mock.patch('sys.stdout', io.StringIO()) as stdout, mock.patch('sys.argv', [ 'progname', 'ident', 'name=Changed Name' ]) as argv:
@@ -2143,7 +2150,7 @@ class _TestCases(unittest.TestCase):
self.assertEqual(stdout.getvalue(), '') self.assertEqual(stdout.getvalue(), '')


# and looked up the correct file # and looked up the correct file
eu.assert_called_with('~/.medashare_identity.pasn1')
eu.assert_any_call('~/.medashare_identity.pasn1')


npersona = Persona.load(identfname) npersona = Persona.load(identfname)
nident = npersona.get_identity() nident = npersona.get_identity()


Loading…
Cancel
Save