From 5d82d5930a7f99ae0e47765b6e77b8f1e02dde56 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 11 Apr 2023 13:57:31 -0700 Subject: [PATCH] make mapping alone print out existing mappings.. --- ui/fixtures/cmd.mapping.json | 5 ++++ ui/medashare/cli.py | 44 +++++++++++++++++++++--------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/ui/fixtures/cmd.mapping.json b/ui/fixtures/cmd.mapping.json index 50066a5..2f603c3 100644 --- a/ui/fixtures/cmd.mapping.json +++ b/ui/fixtures/cmd.mapping.json @@ -98,5 +98,10 @@ "special": "verify store object cnt", "comment": "but didn't create an additional FileObject", "count": 5 +}, +{ + "title": "just mapping lists them", + "cmd": [ "mapping" ], + "stdout_re": "^efdb5d9c-d123-4b30-aaa8-45a9ea8f6053:/.*subdir/mapa <-> ceaa4862-dd00-41ba-9787-7480ec1b2679:/.*subdir/mapb\n$" } ] diff --git a/ui/medashare/cli.py b/ui/medashare/cli.py index d8bd3f3..4e3f1a4 100644 --- a/ui/medashare/cli.py +++ b/ui/medashare/cli.py @@ -53,7 +53,7 @@ import shutil import socket import sqlalchemy from sqlalchemy import create_engine, select, insert, func, delete -from sqlalchemy.orm import sessionmaker +from sqlalchemy.orm import sessionmaker, aliased import string import subprocess import sys @@ -945,28 +945,36 @@ def printhost(host): @init_datastructs def cmd_mapping(options, persona, objstr, cache): - if options.mapping is not None: - parts = [ x.split(':', 1) for x in options.mapping ] + if options.mapping is None: + maps = objstr.get_by_type('mapping') - if len(parts[0]) == 1: - parts[0] = [ hostuuid(), parts[0][0] ] + maps = (' <-> '.join(i['mapping']) for i in maps) - if parts[0][0] == hostuuid(): - parts[0][1] = str(pathlib.Path(parts[0][1]).resolve()) + for i in maps: + print(i) + return - if parts[1][1][0] != '/': - print('ERROR: host path must be absolute, is %s.' % - repr(parts[1][1][0]), file=sys.stderr) - sys.exit(1) + parts = [ x.split(':', 1) for x in options.mapping ] - try: - [ objstr.get_host(x[0]) for x in parts ] - except KeyError as e: - print('ERROR: Unable to find host %s' % - str(e.args[0]), file=sys.stderr) - sys.exit(1) + if len(parts[0]) == 1: + parts[0] = [ hostuuid(), parts[0][0] ] + + if parts[0][0] == hostuuid(): + parts[0][1] = str(pathlib.Path(parts[0][1]).resolve()) + + if parts[1][1][0] != '/': + print('ERROR: host path must be absolute, is %s.' % + repr(parts[1][1][0]), file=sys.stderr) + sys.exit(1) + + try: + [ objstr.get_host(x[0]) for x in parts ] + except KeyError as e: + print('ERROR: Unable to find host %s' % + str(e.args[0]), file=sys.stderr) + sys.exit(1) - m = persona.Mapping(mapping=[ ':'.join(x) for x in parts ]) + m = persona.Mapping(mapping=[ ':'.join(x) for x in parts ]) objstr.loadobj(m)