From 16776f8af14a35f900f5ad1fb0272618aff6cfc0 Mon Sep 17 00:00:00 2001 From: Rhet Turnbull Date: Mon, 13 Nov 2023 08:47:33 -0800 Subject: [PATCH] Fix for #1274, allow library to be specified in config.toml --- osxphotos/cli/export.py | 13 ++++++++++++- tests/test_cli.py | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/osxphotos/cli/export.py b/osxphotos/cli/export.py index d52a128ad..132fc75f8 100644 --- a/osxphotos/cli/export.py +++ b/osxphotos/cli/export.py @@ -1057,6 +1057,7 @@ def export( # config expects --verbose to be named "verbose" not "verbose_flag" locals_["verbose"] = verbose_flag + locals_["library"] = None # synynom for --db del locals_["verbose_flag"] # NOTE: because of the way ConfigOptions works, Click options must not @@ -1086,6 +1087,14 @@ def export( ) sys.exit(1) + if cfg.library and cfg.db: + # library & db are synonyms but library takes precedence over db + # warn user if both options are used + rich_click_echo( + f"[warning]:warning-emoji: both --db and --library were specified; --library will be used ({cfg.library}) ", + err=True, + ) + # re-set the local vars to the corresponding config value # this isn't elegant but avoids having to rewrite this function to use cfg.varname for every parameter # the query options appear to be unaccessed but they are used below by query_options_from_kwargs @@ -1109,7 +1118,9 @@ def export( convert_to_jpeg = cfg.convert_to_jpeg crash_after = cfg.crash_after current_name = cfg.current_name - db = cfg.db + db = ( + cfg.library or cfg.db + ) # if both db and library are specified, library takes precedence deleted = cfg.deleted deleted_only = cfg.deleted_only description = cfg.description diff --git a/tests/test_cli.py b/tests/test_cli.py index 1b44798ef..a3924400a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7692,6 +7692,32 @@ def test_save_load_config(): assert "Writing XMP sidecar" not in result.output +def test_load_config_library(): + """Test --load-config with libary option, #1274""" + + runner = CliRunner() + cwd = os.getcwd() + # pylint: disable=not-context-manager + with runner.isolated_filesystem(): + with open("test.toml", "w") as fd: + fd.write("[export]\n") + fd.write(f'library = "{os.path.join(cwd, CLI_PHOTOS_DB)}"\n') + + # test load config file + result = runner.invoke( + export, + [ + ".", + "--verbose", + "--load-config", + "test.toml", + ], + ) + assert result.exit_code == 0 + assert "Loaded options from file" in result.output + assert "Processed" in result.output + + def test_config_only(): """test --save-config, --config-only"""