Write out list of libraries to stderr except in list command.

This commit is contained in:
mwort
2020-01-20 00:56:23 +01:00
parent e214746063
commit 6e364fc9d9

View File

@@ -202,8 +202,8 @@ def keywords(ctx, cli_obj, db, json_, photos_library):
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["keywords"].get_help(ctx)) click.echo(cli.commands["keywords"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -226,8 +226,8 @@ def albums(ctx, cli_obj, db, json_, photos_library):
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["albums"].get_help(ctx)) click.echo(cli.commands["albums"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -253,8 +253,8 @@ def persons(ctx, cli_obj, db, json_, photos_library):
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["persons"].get_help(ctx)) click.echo(cli.commands["persons"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -277,8 +277,8 @@ def info(ctx, cli_obj, db, json_, photos_library):
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["info"].get_help(ctx)) click.echo(cli.commands["info"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -350,8 +350,8 @@ def dump(ctx, cli_obj, db, json_, photos_library):
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["dump"].get_help(ctx)) click.echo(cli.commands["dump"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -366,10 +366,10 @@ def dump(ctx, cli_obj, db, json_, photos_library):
@click.pass_context @click.pass_context
def list_libraries(ctx, cli_obj, json_): def list_libraries(ctx, cli_obj, json_):
""" Print list of Photos libraries found on the system. """ """ Print list of Photos libraries found on the system. """
_list_libraries(json_=json_ or cli_obj.json) _list_libraries(json_=json_ or cli_obj.json, error=False)
def _list_libraries(json_=False): def _list_libraries(json_=False, error=True):
""" Print list of Photos libraries found on the system. """ Print list of Photos libraries found on the system.
If json_ == True, print output as JSON (default = False) """ If json_ == True, print output as JSON (default = False) """
@@ -389,20 +389,20 @@ def _list_libraries(json_=False):
for lib in photo_libs: for lib in photo_libs:
if lib == sys_lib: if lib == sys_lib:
click.echo(f"(*)\t{lib}") click.echo(f"(*)\t{lib}", err=error)
sys_lib_flag = True sys_lib_flag = True
elif lib == last_lib: elif lib == last_lib:
click.echo(f"(#)\t{lib}") click.echo(f"(#)\t{lib}", err=error)
last_lib_flag = True last_lib_flag = True
else: else:
click.echo(f"\t{lib}") click.echo(f"\t{lib}", err=error)
if sys_lib_flag or last_lib_flag: if sys_lib_flag or last_lib_flag:
click.echo("\n") click.echo("\n", err=error)
if sys_lib_flag: if sys_lib_flag:
click.echo("(*)\tSystem Photos Library") click.echo("(*)\tSystem Photos Library", err=error)
if last_lib_flag: if last_lib_flag:
click.echo("(#)\tLast opened Photos Library") click.echo("(#)\tLast opened Photos Library", err=error)
@cli.command() @cli.command()
@@ -566,8 +566,8 @@ def query(
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["query"].get_help(ctx)) click.echo(cli.commands["query"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return
@@ -758,8 +758,8 @@ def export(
db = get_photos_db(*photos_library, db, cli_obj.db) db = get_photos_db(*photos_library, db, cli_obj.db)
if db is None: if db is None:
click.echo(cli.commands["export"].get_help(ctx)) click.echo(cli.commands["export"].get_help(ctx), err=True)
click.echo("\n\nLocated the following Photos library databases: ") click.echo("\n\nLocated the following Photos library databases: ", err=True)
_list_libraries() _list_libraries()
return return