Allow command-line configuration of config location (#1284).
authorCarl Hetherington <cth@carlh.net>
Sat, 28 Apr 2018 23:37:13 +0000 (00:37 +0100)
committerCarl Hetherington <cth@carlh.net>
Sat, 28 Apr 2018 23:37:13 +0000 (00:37 +0100)
ChangeLog
src/lib/config.cc
src/lib/config.h
src/tools/dcpomatic_cli.cc
src/tools/dcpomatic_create.cc
test/config_test.cc

index 304c9d3d8b314b2e59ea97347dbf1655e3a6ec00..fa080842d86fd4f5e51d5e5b6c2ee324a20c161d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2018-04-29  Carl Hetherington  <cth@carlh.net>
+
+       * Add command-line option to specify directory containing config (#1284).
+
 2018-04-27  Carl Hetherington  <cth@carlh.net>
 
        * Fix incorrect container size when loading a OV/VF combination into the player.
index 2ae7939a9e7bcf7ad725c2ec6176d6f29ffce4cc..e2f2bbeb97a81fff2ccbf19ae50798916394cd89 100644 (file)
@@ -68,7 +68,7 @@ int const Config::_current_version = 3;
 boost::signals2::signal<void ()> Config::FailedToLoad;
 boost::signals2::signal<void (string)> Config::Warning;
 boost::signals2::signal<bool (void)> Config::BadSignerChain;
-boost::optional<boost::filesystem::path> Config::test_path;
+boost::optional<boost::filesystem::path> Config::override_path;
 
 /** Construct default configuration */
 Config::Config ()
@@ -456,8 +456,8 @@ boost::filesystem::path
 Config::path (string file, bool create_directories)
 {
        boost::filesystem::path p;
-       if (test_path) {
-               p = test_path.get();
+       if (override_path) {
+               p = *override_path;
        } else {
 #ifdef DCPOMATIC_OSX
                p /= g_get_home_dir ();
index 2fca9699c786006d5819064ecb0acb4b1e5a49c5..c625e92424247314004232d92d48264d1314520b 100644 (file)
@@ -721,8 +721,9 @@ public:
        static bool have_existing (std::string);
        static boost::filesystem::path config_file ();
 
-       static boost::optional<boost::filesystem::path> test_path;
-
+       /** If set, this overrides the standard path (in home, Library, AppData or wherever) for config.xml and cinemas.xml */
+       static boost::optional<boost::filesystem::path> override_path;
+       
 private:
        Config ();
        static boost::filesystem::path path (std::string file, bool create_directories = true);
index 788594f0ca6273b509ee3641e13f0d25dbb70808..7fc5ed55dd9603d702eb4496adf6b37649b73629 100644 (file)
@@ -65,6 +65,7 @@ help (string n)
             << "  -s, --servers <file> specify servers to use in a text file\n"
             << "  -l, --list-servers   just display a list of encoding servers that DCP-o-matic is configured to use; don't encode\n"
             << "  -d, --dcp-path       echo DCP's path to stdout on successful completion (implies -n)\n"
+            << "  -c, --config <dir>   directory containing config.xml and cinemas.xml\n"
             << "      --dump           just dump a summary of the film's settings; don't encode\n"
             << "\n"
             << "<FILM> is the film directory.\n";
@@ -195,6 +196,7 @@ main (int argc, char* argv[])
        optional<boost::filesystem::path> servers;
        bool list_servers_ = false;
        bool dcp_path = false;
+       optional<boost::filesystem::path> config;
 
        int option_index = 0;
        while (true) {
@@ -210,12 +212,13 @@ main (int argc, char* argv[])
                        { "servers", required_argument, 0, 's' },
                        { "list-servers", no_argument, 0, 'l' },
                        { "dcp-path", no_argument, 0, 'd' },
+                       { "config", required_argument, 0, 'c' },
                        /* Just using A, B, C ... from here on */
                        { "dump", no_argument, 0, 'A' },
                        { 0, 0, 0, 0 }
                };
 
-               int c = getopt_long (argc, argv, "vhfnrt:j:kAs:ld", long_options, &option_index);
+               int c = getopt_long (argc, argv, "vhfnrt:j:kAs:ldc:", long_options, &option_index);
 
                if (c == -1) {
                        break;
@@ -259,9 +262,16 @@ main (int argc, char* argv[])
                        dcp_path = true;
                        progress = false;
                        break;
+               case 'c':
+                       config = optarg;
+                       break;
                }
        }
 
+       if (config) {
+               Config::override_path = *config;
+       }
+
        if (servers) {
                FILE* f = fopen_boost (*servers, "r");
                if (!f) {
index a9d1165f14c02a563d93ca268974c2544a0050c0..5c6fc3567f2f512953b24e8afa1ff8b893417279 100644 (file)
@@ -30,6 +30,7 @@
 #include "lib/image_content.h"
 #include "lib/video_content.h"
 #include "lib/cross.h"
+#include "lib/config.h"
 #include "lib/dcp_content.h"
 #include <dcp/exceptions.h>
 #include <libxml++/libxml++.h>
@@ -66,6 +67,7 @@ syntax (string n)
             << "      --standard <standard>     SMPTE or interop (default SMPTE)\n"
             << "      --no-use-isdcf-name       do not use an ISDCF name; use the specified name unmodified\n"
             << "      --no-sign                 do not sign the DCP\n"
+            << "      --config <dir>            directory containing config.xml and cinemas.xml\n"
             << "  -o, --output <dir>            output directory\n";
 }
 
@@ -105,6 +107,7 @@ main (int argc, char* argv[])
        optional<boost::filesystem::path> output;
        bool sign = true;
        bool use_isdcf_name = true;
+       optional<boost::filesystem::path> config;
 
        int option_index = 0;
        while (true) {
@@ -122,10 +125,11 @@ main (int argc, char* argv[])
                        { "no-use-isdcf-name", no_argument, 0, 'D'},
                        { "no-sign", no_argument, 0, 'E'},
                        { "output", required_argument, 0, 'o'},
+                       { "config", required_argument, 0, 'F'},
                        { 0, 0, 0, 0}
                };
 
-               int c = getopt_long (argc, argv, "vhn:f:c:f:A:B:C:s:o:DE", long_options, &option_index);
+               int c = getopt_long (argc, argv, "vhn:f:c:f:A:B:C:s:o:DEF:", long_options, &option_index);
                if (c == -1) {
                        break;
                }
@@ -185,6 +189,9 @@ main (int argc, char* argv[])
                case 'E':
                        sign = false;
                        break;
+               case 'F':
+                       config = optarg;
+                       break;
                case 's':
                        still_length = atoi (optarg);
                        break;
@@ -202,6 +209,10 @@ main (int argc, char* argv[])
                exit (EXIT_FAILURE);
        }
 
+       if (config) {
+               Config::override_path = *config;
+       }
+
        if (!content_ratio) {
                cerr << argv[0] << ": missing required option --content-ratio.\n";
                exit (EXIT_FAILURE);
index dad545a48e89db4a83c992f14dd63168c4ceaa43..14cceb6a0df30100849a9565e733fbec032902fd 100644 (file)
@@ -31,7 +31,7 @@ rewrite_bad_config ()
        boost::system::error_code ec;
        boost::filesystem::remove ("build/test/config.xml", ec);
 
-       Config::test_path = "build/test";
+       Config::override_path = "build/test";
        ofstream f ("build/test/config.xml");
        f << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
          << "<Config>\n"