3
0
Fork 0

+ many improvments of kiwix-manage

small_fixes
kelson42 14 years ago
parent 2fc7b277d4
commit c287902b45

@ -17,8 +17,10 @@
* MA 02110-1301, USA. * MA 02110-1301, USA.
*/ */
#include <getopt.h>
#include <iostream> #include <iostream>
#include <cstdlib> #include <cstdlib>
#include <pathTools.h>
#include <kiwix/manager.h> #include <kiwix/manager.h>
using namespace std; using namespace std;
@ -44,13 +46,22 @@ void show(kiwix::Library library) {
} }
} }
void usage() {
cerr << "Usage:" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH [--relativePaths|-r] [--noZimPath|n] [--indexBackend|-b=xapian|clucene] [--indexPath|-i=FULLTEXT_IDX_PATH] [url|u=http://...metalink]" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH show show [CONTENTID1] [CONTENTID2] ... (show everything if no param.)" << endl;
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
string libraryPath = ""; string libraryPath = "";
supportedAction action = NONE; supportedAction action = NONE;
string zimPath = ""; string zimPath = "";
kiwix::Manager libraryManager; kiwix::Manager libraryManager;
int option_index = 0;
int c = 0;
/* Argument parsing */ /* Argument parsing */
if (argc > 2) { if (argc > 2) {
libraryPath = argv[1]; libraryPath = argv[1];
@ -66,7 +77,7 @@ int main(int argc, char **argv) {
/* Print usage)) if necessary */ /* Print usage)) if necessary */
if (libraryPath == "" || action == NONE) { if (libraryPath == "" || action == NONE) {
cerr << "Usage: kiwix-manage LIBRARY_PATH ACTION [OPTIONS]" << endl; usage();
exit(1); exit(1);
} }
@ -77,20 +88,79 @@ int main(int argc, char **argv) {
if (action == SHOW) { if (action == SHOW) {
show(libraryManager.cloneLibrary()); show(libraryManager.cloneLibrary());
} else if (action == ADD) { } else if (action == ADD) {
string zimPath = ""; string zimPath;
string url = ""; string zimPathToSave = ".";
string indexPath;
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
string url;
if (argc>3) { if (argc>3) {
zimPath = argv[3]; zimPath = argv[3];
} }
if (argc>4) { /* Options parsing */
url = argv[4]; optind = 2;
while (42) {
static struct option long_options[] = {
{"url", required_argument, 0, 'u'},
{"indexPath", required_argument, 0, 'i'},
{"indexBackend", required_argument, 0, 'b'},
{"zimPathToSave", required_argument, 0, 'z'},
{0, 0, 0, 0}
};
c = getopt_long(argc, argv, "z:u:i:b:", long_options, &option_index);
if (c != -1) {
switch (c) {
case 'u':
url = optarg;
break;
case 'i':
indexPath = optarg;
break;
case 'b':
if (!strcmp(optarg, "clucene")) {
indexBackend = kiwix::CLUCENE;
} else if (!strcmp(optarg, "xapian")) {
indexBackend = kiwix::XAPIAN;
} else {
usage();
}
break;
case 'z':
zimPathToSave = optarg;
break;
}
} else {
break;
}
} }
if (zimPath != "") { if (zimPath != "") {
libraryManager.addBookFromPath(zimPath, "", url, true); zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
libraryManager.removeBookPaths(); string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, true);
if (!bookId.empty()) {
libraryManager.setCurrentBookId(bookId);
/* In case of the library already had the same book and a
corresponding path, the merge politic could should to save
the "old" one if zimPathToSave is empty */
if (zimPathToSave.empty())
libraryManager.setBookPath(bookId, zimPathToSave);
if (!indexPath.empty())
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
} else {
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
}
} else { } else {
std::cerr << "Invalid zim file path" << std::endl; std::cerr << "Invalid zim file path" << std::endl;
} }

Loading…
Cancel
Save