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
@ -10,6 +10,7 @@ kiwix-manage
------------
* 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
=================

View File

@ -99,22 +99,27 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
int c = 0;
bool resultCode = 0;
if (argc > 3) {
zimPath = argv[3];
if (argc <= 3) {
std::cerr << "Path to zim file to add is missing in the command line" << std::endl;
return (-1);
}
/* Options parsing */
optind = 2;
while (42) {
static struct option long_options[]
= {{"url", required_argument, 0, 'u'},
optind = 3;
static struct option long_options[] = {
{"url", required_argument, 0, 'u'},
{"origId", required_argument, 0, 'o'},
{"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);
if (c == -1)
break;
if (c != -1) {
has_option = true;
switch (c) {
case 'u':
url = optarg;
@ -128,19 +133,30 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
zimPathToSave = optarg;
break;
}
} else {
break;
}
}
if (!zimPath.empty()) {
if (optind >= argc) {
std::cerr << "Path to zim file to add is missing in the command line" << std::endl;
return (-1);
}
if (has_option && argc-optind > 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);
}