Merge pull request #272 from kiwix/multiple_add

[manage] Allow user to add several zim files to library in the same time.
This commit is contained in:
Matthieu Gautier 2019-04-02 15:33:39 +02:00 committed by GitHub
commit 26b4dd5f57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 50 additions and 33 deletions

View File

@ -1,4 +1,4 @@
kiwix-tools 1.1.1 kiwix-tools 1.2.0
================= =================
kiwix-serve kiwix-serve
@ -10,6 +10,7 @@ kiwix-manage
------------ ------------
* Do not show all books if book ids has been provided. * Do not show all books if book ids has been provided.
* Be able to add several zim files in the same time in a library.
kiwix-tools 1.1.0 kiwix-tools 1.1.0
================= =================

View File

@ -99,47 +99,63 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
int c = 0; int c = 0;
bool resultCode = 0; bool resultCode = 0;
if (argc > 3) { if (argc <= 3) {
zimPath = argv[3]; std::cerr << "Path to zim file to add is missing in the command line" << std::endl;
return (-1);
} }
/* Options parsing */ /* Options parsing */
optind = 2; optind = 3;
while (42) { static struct option long_options[] = {
static struct option long_options[] {"url", required_argument, 0, 'u'},
= {{"url", required_argument, 0, 'u'}, {"origId", required_argument, 0, 'o'},
{"origId", required_argument, 0, 'o'}, {"zimPathToSave", required_argument, 0, 'z'},
{"zimPathToSave", required_argument, 0, 'z'}, {0, 0, 0, 0}
{0, 0, 0, 0}}; };
bool has_option = false;
while (true) {
c = getopt_long(argc, argv, "cz:u:", long_options, &option_index); c = getopt_long(argc, argv, "cz:u:", long_options, &option_index);
if (c == -1)
if (c != -1) {
switch (c) {
case 'u':
url = optarg;
break;
case 'o':
origID = optarg;
break;
case 'z':
zimPathToSave = optarg;
break;
}
} else {
break; break;
has_option = true;
switch (c) {
case 'u':
url = optarg;
break;
case 'o':
origID = optarg;
break;
case 'z':
zimPathToSave = optarg;
break;
} }
} }
if (!zimPath.empty()) { if (optind >= argc) {
kiwix::Manager manager(library); std::cerr << "Path to zim file to add is missing in the command line" << std::endl;
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave; return (-1);
manager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false); }
} else {
std::cerr << "Invalid zim file path" << std::endl; if (has_option && argc-optind > 1) {
resultCode = 1; std::cerr << "You cannot give option and several zim files to add" << std::endl;
return (-1);
}
kiwix::Manager manager(library);
for(auto i=optind; i<argc; i++) {
std::string zimPath = argv[i];
if (!zimPath.empty()) {
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
manager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
} else {
std::cerr << "Invalid zim file path" << std::endl;
resultCode = 1;
}
} }
return(resultCode); return(resultCode);