X-Git-Url: https://main.carlh.net/gitweb/?p=dcpomatic.git;a=blobdiff_plain;f=src%2Ftools%2Fdcpomatic_cli.cc;h=52a113cbb4c72d6693faf84677a430cc3fc81e3e;hp=bd1a4e4aa60b8aceed165f708e631984d0de699c;hb=ed0b3ee0c5a0ba11d3a1a1dfee8e71238bcab4bd;hpb=4cb64738c9dae07651403341de17c5b280682495 diff --git a/src/tools/dcpomatic_cli.cc b/src/tools/dcpomatic_cli.cc index bd1a4e4aa..52a113cbb 100644 --- a/src/tools/dcpomatic_cli.cc +++ b/src/tools/dcpomatic_cli.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2015 Carl Hetherington + Copyright (C) 2012-2017 Carl Hetherington This file is part of DCP-o-matic. @@ -54,17 +54,18 @@ static void help (string n) { cerr << "Syntax: " << n << " [OPTION] []\n" - << " -v, --version show DCP-o-matic version\n" - << " -h, --help show this help\n" - << " -f, --flags show flags passed to C++ compiler on build\n" - << " -n, --no-progress do not print progress to stdout\n" - << " -r, --no-remote do not use any remote servers\n" - << " -t, --threads specify number of local encoding threads (overriding configuration)\n" - << " -j, --json run a JSON server on the specified port\n" - << " -k, --keep-going keep running even when the job is complete\n" - << " -s, --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" - << " --dump just dump a summary of the film's settings; don't encode\n" + << " -v, --version show DCP-o-matic version\n" + << " -h, --help show this help\n" + << " -f, --flags show flags passed to C++ compiler on build\n" + << " -n, --no-progress do not print progress to stdout\n" + << " -r, --no-remote do not use any remote servers\n" + << " -t, --threads specify number of local encoding threads (overriding configuration)\n" + << " -j, --json run a JSON server on the specified port\n" + << " -k, --keep-going keep running even when the job is complete\n" + << " -s, --servers 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" + << " --dump just dump a summary of the film's settings; don't encode\n" << "\n" << " is the film directory.\n"; } @@ -73,7 +74,7 @@ static void print_dump (shared_ptr film) { cout << film->dcp_name (true) << "\n" - << film->container()->nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n" + << film->container()->container_nickname() << " at " << ((film->resolution() == RESOLUTION_2K) ? "2K" : "4K") << "\n" << (film->j2k_bandwidth() / 1000000) << "Mbit/s" << "\n" << "Output " << film->video_frame_rate() << "fps " << (film->three_d() ? "3D" : "2D") << " " << (film->audio_frame_rate() / 1000) << "kHz\n" << (film->interop() ? "Inter-Op" : "SMPTE") << " " << (film->encrypted() ? "encrypted" : "unencrypted") << "\n"; @@ -116,50 +117,62 @@ print_dump (shared_ptr film) } static void -show_servers () +list_servers () { while (true) { int N = 0; - list servers = EncodeServerFinder::instance()->servers (); + list servers = EncodeServerFinder::instance()->good_servers (); - if (Config::instance()->use_any_servers ()) { - if (servers.empty ()) { - cout << "No encoding servers found.\n"; - ++N; - } else { - cout << std::left << setw(24) << "Host" << " Threads\n"; - ++N; - BOOST_FOREACH (EncodeServerDescription const & i, servers) { - cout << std::left << setw(24) << i.host_name() << " " << i.threads() << "\n"; - ++N; - } - } + /* This is a bit fiddly because we want to list configured servers that are down as well + as all those (configured and found by broadcast) that are up. + */ + + if (servers.empty() && Config::instance()->servers().empty()) { + cout << "No encoding servers found or configured.\n"; + ++N; } else { - vector configured_servers = Config::instance()->servers(); - if (configured_servers.empty()) { - cout << "No configured servers, and DCP-o-matic is not set to search for any server.\n"; - ++N; - } else { - cout << std::left << setw(24) << "Host" << " Status Threads\n"; - ++N; - BOOST_FOREACH (string const & i, Config::instance()->servers()) { - cout << std::left << setw(24) << i << " "; - optional threads; - BOOST_FOREACH (EncodeServerDescription const & j, servers) { - if (i == j.host_name()) { - threads = j.threads(); - } - } - if (static_cast(threads)) { - cout << "UP " << threads.get() << "\n"; + cout << std::left << setw(24) << "Host" << " Status Threads\n"; + ++N; + + /* Report the state of configured servers */ + BOOST_FOREACH (string i, Config::instance()->servers()) { + cout << std::left << setw(24) << i << " "; + + /* See if this server is on the active list; if so, remove it and note + the number of threads it is offering. + */ + optional threads; + list::iterator j = servers.begin (); + while (j != servers.end ()) { + if (i == j->host_name()) { + threads = j->threads(); + list::iterator tmp = j; + ++tmp; + servers.erase (j); + j = tmp; } else { - cout << "DOWN\n"; + ++j; } - ++N; } + if (static_cast(threads)) { + cout << "UP " << threads.get() << "\n"; + } else { + cout << "DOWN\n"; + } + ++N; } - } + /* Now report any left that have been found by broadcast */ + BOOST_FOREACH (EncodeServerDescription const & i, servers) { + cout << std::left << setw(24) << i.host_name() << " UP " << i.threads() << "\n"; + ++N; + } + + /* And those that have a bad version */ + BOOST_FOREACH (EncodeServerDescription i, EncodeServerFinder::instance()->good_servers()) { + cout << std::left << setw(24) << i.host_name() << " bad version\n"; + } + } dcpomatic_sleep (1); @@ -173,14 +186,15 @@ show_servers () int main (int argc, char* argv[]) { - string film_dir; + boost::filesystem::path film_dir; bool progress = true; bool no_remote = false; optional threads; optional json_port; bool keep_going = false; bool dump = false; - bool servers = false; + optional servers; + bool list_servers_ = false; bool dcp_path = false; int option_index = 0; @@ -194,14 +208,15 @@ main (int argc, char* argv[]) { "threads", required_argument, 0, 't'}, { "json", required_argument, 0, 'j'}, { "keep-going", no_argument, 0, 'k' }, - { "servers", no_argument, 0, 's' }, + { "servers", required_argument, 0, 's' }, + { "list-servers", no_argument, 0, 'l' }, { "dcp-path", no_argument, 0, 'd' }, /* 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:kAsd", long_options, &option_index); + int c = getopt_long (argc, argv, "vhfnrt:j:kAs:ld", long_options, &option_index); if (c == -1) { break; @@ -236,7 +251,10 @@ main (int argc, char* argv[]) dump = true; break; case 's': - servers = true; + servers = optarg; + break; + case 'l': + list_servers_ = true; break; case 'd': dcp_path = true; @@ -246,7 +264,24 @@ main (int argc, char* argv[]) } if (servers) { - show_servers (); + FILE* f = fopen_boost (*servers, "r"); + if (!f) { + cerr << "Could not open servers list file " << *servers << "\n"; + exit (EXIT_FAILURE); + } + vector servers; + while (!feof (f)) { + char buffer[128]; + if (fscanf (f, "%s.127", buffer) == 1) { + servers.push_back (buffer); + } + } + fclose (f); + Config::instance()->set_servers (servers); + } + + if (list_servers_) { + list_servers (); exit (EXIT_SUCCESS); } @@ -270,7 +305,7 @@ main (int argc, char* argv[]) } if (threads) { - Config::instance()->set_num_local_encoding_threads (threads.get ()); + Config::instance()->set_master_encoding_threads (threads.get ()); } shared_ptr film; @@ -278,7 +313,7 @@ main (int argc, char* argv[]) film.reset (new Film (film_dir)); film->read_metadata (); } catch (std::exception& e) { - cerr << argv[0] << ": error reading film `" << film_dir << "' (" << e.what() << ")\n"; + cerr << argv[0] << ": error reading film `" << film_dir.string() << "' (" << e.what() << ")\n"; exit (EXIT_FAILURE); }