Add --config option to map (#2543).
authorCarl Hetherington <cth@carlh.net>
Tue, 30 May 2023 10:23:00 +0000 (12:23 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 30 May 2023 10:23:30 +0000 (12:23 +0200)
src/lib/map_cli.cc
test/data
test/map_cli_test.cc

index 1b99afa945fcf4f5157cdaf7ba4e46fe6944748b..c95d7f1a1aaa4c2f3bb2b5f2eda6ddf2b80c7bb0 100644 (file)
@@ -63,6 +63,7 @@ help(std::function<void (string)> out)
        out("  -s, --soft-link  using soft links instead of copying");
        out("  -d, --assets-dir look in this directory for assets (can be given more than once)");
        out("  -r, --rename     rename all files to <uuid>.<mxf|xml>");
        out("  -s, --soft-link  using soft links instead of copying");
        out("  -d, --assets-dir look in this directory for assets (can be given more than once)");
        out("  -r, --rename     rename all files to <uuid>.<mxf|xml>");
+       out("  --config <dir>   directory containing config.xml and cinemas.xml");
 }
 
 
 }
 
 
@@ -74,6 +75,7 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
        bool soft_link = false;
        bool rename = false;
        vector<boost::filesystem::path> assets_dir;
        bool soft_link = false;
        bool rename = false;
        vector<boost::filesystem::path> assets_dir;
+       optional<boost::filesystem::path> config_dir;
 
        /* This makes it possible to call getopt several times in the same executable, for tests */
        optind = 0;
 
        /* This makes it possible to call getopt several times in the same executable, for tests */
        optind = 0;
@@ -87,10 +89,11 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
                        { "soft-link", no_argument, 0, 's' },
                        { "assets-dir", required_argument, 0, 'd' },
                        { "rename", no_argument, 0, 'r' },
                        { "soft-link", no_argument, 0, 's' },
                        { "assets-dir", required_argument, 0, 'd' },
                        { "rename", no_argument, 0, 'r' },
+                       { "config", required_argument, 0, 'c' },
                        { 0, 0, 0, 0 }
                };
 
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long(argc, argv, "ho:lsd:r", long_options, &option_index);
+               int c = getopt_long(argc, argv, "ho:lsd:rc:", long_options, &option_index);
 
                if (c == -1) {
                        break;
 
                if (c == -1) {
                        break;
@@ -117,6 +120,9 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
                case 'r':
                        rename = true;
                        break;
                case 'r':
                        rename = true;
                        break;
+               case 'c':
+                       config_dir = optarg;
+                       break;
                }
        }
 
                }
        }
 
@@ -127,6 +133,10 @@ map_cli(int argc, char* argv[], std::function<void (string)> out)
                exit(EXIT_FAILURE);
        }
 
                exit(EXIT_FAILURE);
        }
 
+       if (config_dir) {
+               State::override_path = *config_dir;
+       }
+
        vector<boost::filesystem::path> cpl_filenames;
        for (int i = optind; i < argc; ++i) {
                cpl_filenames.push_back(argv[i]);
        vector<boost::filesystem::path> cpl_filenames;
        for (int i = optind; i < argc; ++i) {
                cpl_filenames.push_back(argv[i]);
index 31458f4b7a93bd95d23b4b58eb89503e8cec8759..ece8e470df37357b9a9c29360c15213b6e71ec30 160000 (submodule)
--- a/test/data
+++ b/test/data
@@ -1 +1 @@
-Subproject commit 31458f4b7a93bd95d23b4b58eb89503e8cec8759
+Subproject commit ece8e470df37357b9a9c29360c15213b6e71ec30
index 3e6abc059cd9b93f031cce5fabdfaaddecd19200..ffe281de570ff519c342925fc237b9c28dd538bf 100644 (file)
@@ -353,3 +353,32 @@ BOOST_AUTO_TEST_CASE(map_two_smpte_cpls_each_with_subs)
 {
        test_two_cpls_each_with_subs("map_two_smpte_cpls_each_with_subs", false);
 }
 {
        test_two_cpls_each_with_subs("map_two_smpte_cpls_each_with_subs", false);
 }
+
+
+BOOST_AUTO_TEST_CASE(map_with_given_config)
+{
+       string const name = "map_with_given_config";
+       string const out = String::compose("build/test/%1_out", name);
+
+       auto content = content_factory("test/data/flat_red.png");
+       auto film = new_test_film2(name + "_in", content);
+       make_and_verify_dcp(film);
+
+       vector<string> const args = {
+               "map_cli",
+               "-o", out,
+               "-d", film->dir(film->dcp_name()).string(),
+               "--config", "test/data/map_with_given_config",
+               find_cpl(film->dir(film->dcp_name())).string()
+       };
+
+       boost::filesystem::remove_all(out);
+
+       Config::instance()->drop();
+       vector<string> output_messages;
+       auto error = run(args, output_messages);
+       BOOST_CHECK(!error);
+
+       /* It should be signed by the key in test/data/map_with_given_config, not the one in test/data/signer_key */
+       BOOST_CHECK(dcp::file_to_string(find_file(out, "cpl_")).find("dnQualifier=\\+uOcNN2lPuxpxgd/5vNkkBER0GE=,CN=CS.dcpomatic.smpte-430-2.LEAF,OU=dcpomatic.com,O=dcpomatic.com") != std::string::npos);
+}