def print_key(table, key): if table == db_common.UNIQUE_KEY_TABLE: value = nb_api.driver.get_key(table, key) value_dict = {'id': key, table: int(value)} cli_utils.print_dict(value_dict) return model = _get_model_or_exit(table) try: value = nb_api.get(model(id=key)) except df_exceptions.DBKeyNotFound: print('Key not found: ' + table) return cli_utils.print_dict(value.to_struct())
def print_key(db_driver, table, key): try: value = db_driver.get_key(table, key) except df_exceptions.DBKeyNotFound: print('Key not found: ' + table) return value = jsonutils.loads(value) # It will be too difficult to print all type of data in table # therefore using print dict for dictionary type otherwise # using old approach for print. if isinstance(value, dict): cli_utils.print_dict(value) else: print(value)
def _print_dict(dct, format_): if format_ == FORMAT_PRETTY: cli_utils.print_dict(dct) elif format_ == FORMAT_JSON: jsonutils.dump(dct, sys.stdout)