diff options
| author | Carl Hetherington <cth@carlh.net> | 2017-03-03 19:55:41 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2017-03-03 19:55:41 +0000 |
| commit | e4d7f575fab50b6d255821d6d6a8171c8e1f13f6 (patch) | |
| tree | 49f603a388e8a8ca3107e6106e13dcdb3fbdbc93 /src/lib/cinema_kdms.cc | |
| parent | ccc8409dceedcf71872b2846b9b4a4dea9042bda (diff) | |
Add options to write KDMs to separate directories / ZIP files.
Diffstat (limited to 'src/lib/cinema_kdms.cc')
| -rw-r--r-- | src/lib/cinema_kdms.cc | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/src/lib/cinema_kdms.cc b/src/lib/cinema_kdms.cc index e82a987e8..8cac65f41 100644 --- a/src/lib/cinema_kdms.cc +++ b/src/lib/cinema_kdms.cc @@ -37,6 +37,7 @@ using std::cout; using std::string; using std::runtime_error; using boost::shared_ptr; +using boost::function; void CinemaKDMs::make_zip_file (boost::filesystem::path zip_file, dcp::NameFormat name_format, dcp::NameFormat::Map name_values) const @@ -113,24 +114,67 @@ CinemaKDMs::collect (list<ScreenKDM> screen_kdms) return cinema_kdms; } +/** Write one directory per cinema into another directory */ +int +CinemaKDMs::write_directories ( + list<CinemaKDMs> cinema_kdms, + boost::filesystem::path directory, + dcp::NameFormat container_name_format, + dcp::NameFormat filename_format, + dcp::NameFormat::Map name_values, + function<bool (boost::filesystem::path)> confirm_overwrite + ) +{ + /* No specific screen */ + name_values['s'] = ""; + + int written = 0; + + BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { + boost::filesystem::path path = directory; + name_values['c'] = i.cinema->name; + path /= container_name_format.get(name_values, ""); + if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { + boost::filesystem::create_directories (path); + ScreenKDM::write_files (i.screen_kdms, path, filename_format, name_values, confirm_overwrite); + } + written += i.screen_kdms.size(); + } + + return written; +} + /** Write one ZIP file per cinema into a directory */ -void +int CinemaKDMs::write_zip_files ( list<CinemaKDMs> cinema_kdms, boost::filesystem::path directory, - dcp::NameFormat name_format, - dcp::NameFormat::Map name_values + dcp::NameFormat container_name_format, + dcp::NameFormat filename_format, + dcp::NameFormat::Map name_values, + function<bool (boost::filesystem::path)> confirm_overwrite ) { /* No specific screen */ name_values['s'] = ""; + int written = 0; + BOOST_FOREACH (CinemaKDMs const & i, cinema_kdms) { boost::filesystem::path path = directory; name_values['c'] = i.cinema->name; - path /= name_format.get(name_values, ".zip"); - i.make_zip_file (path, name_format, name_values); + path /= container_name_format.get(name_values, ".zip"); + if (!boost::filesystem::exists (path) || confirm_overwrite (path)) { + if (boost::filesystem::exists (path)) { + /* Creating a new zip file over an existing one is an error */ + boost::filesystem::remove (path); + } + i.make_zip_file (path, filename_format, name_values); + written += i.screen_kdms.size(); + } } + + return written; } /** Email one ZIP file per cinema to the cinema. |
