mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-24 04:20:56 -04:00
+ improve kiwix-install
This commit is contained in:
parent
ce4839aa7a
commit
370c79a28e
@ -19,33 +19,36 @@
|
|||||||
|
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <pathTools.h>
|
||||||
#include <kiwix/xapianIndexer.h>
|
#include <kiwix/xapianIndexer.h>
|
||||||
#include <kiwix/cluceneIndexer.h>
|
#include <kiwix/cluceneIndexer.h>
|
||||||
|
|
||||||
enum supportedBackend { XAPIAN, CLUCENE };
|
enum supportedBackend { XAPIAN, CLUCENE };
|
||||||
|
enum supportedAction { NONE, ADDCONTENT };
|
||||||
|
|
||||||
void usage() {
|
void usage() {
|
||||||
cout << "Usage: kiwix-index [--verbose|-v] [--backend|-b=xapian|clucene] ADDCONTENT ZIM_PATH KIWIX_PATH" << endl;
|
cout << "Usage: kiwix-install [--verbose|-v] [--backend|-b=xapian|clucene] [--buildIndex|-i] ADDCONTENT ZIM_PATH KIWIX_PATH" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
/* Init the variables */
|
/* Init the variables */
|
||||||
const char *indexPath = NULL;
|
const char *contentPath = NULL;
|
||||||
const char *search = NULL;
|
const char *kiwixPath = NULL;
|
||||||
|
supportedAction action = NONE;
|
||||||
bool verboseFlag = false;
|
bool verboseFlag = false;
|
||||||
|
bool buildIndexFlag = false;
|
||||||
int option_index = 0;
|
int option_index = 0;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
supportedBackend backend = XAPIAN;
|
supportedBackend backend = XAPIAN;
|
||||||
|
|
||||||
kiwix::Indexer *indexer = NULL;
|
|
||||||
|
|
||||||
/* Argument parsing */
|
/* Argument parsing */
|
||||||
while (42) {
|
while (42) {
|
||||||
|
|
||||||
static struct option long_options[] = {
|
static struct option long_options[] = {
|
||||||
{"verbose", no_argument, 0, 'v'},
|
{"verbose", no_argument, 0, 'v'},
|
||||||
|
{"buildIndex", no_argument, 0, 'i'},
|
||||||
{"backend", required_argument, 0, 'b'},
|
{"backend", required_argument, 0, 'b'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
@ -57,6 +60,9 @@ int main(int argc, char **argv) {
|
|||||||
case 'v':
|
case 'v':
|
||||||
verboseFlag = true;
|
verboseFlag = true;
|
||||||
break;
|
break;
|
||||||
|
case 'i':
|
||||||
|
buildIndexFlag = true;
|
||||||
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
if (!strcmp(optarg, "clucene")) {
|
if (!strcmp(optarg, "clucene")) {
|
||||||
backend = CLUCENE;
|
backend = CLUCENE;
|
||||||
@ -69,12 +75,16 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (optind < argc) {
|
if (optind < argc) {
|
||||||
if (indexPath == NULL) {
|
if (action == NONE) {
|
||||||
indexPath = argv[optind++];
|
string actionString = argv[optind++];
|
||||||
} else if (search == NULL) {
|
if (actionString == "ADDCONTENT") {
|
||||||
search = argv[optind++];
|
action = ADDCONTENT;
|
||||||
|
}
|
||||||
|
} else if (contentPath == NULL) {
|
||||||
|
contentPath = argv[optind++];
|
||||||
|
} else if (kiwixPath == NULL) {
|
||||||
|
kiwixPath = argv[optind++];
|
||||||
} else {
|
} else {
|
||||||
cout << indexPath << endl;
|
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -84,20 +94,16 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we have enough arguments */
|
/* Check if we have enough arguments */
|
||||||
if (indexPath == NULL || search == NULL) {
|
if (contentPath == NULL || kiwixPath == NULL) {
|
||||||
usage();
|
usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to prepare the indexing */
|
/* Make the action */
|
||||||
try {
|
if (action == ADDCONTENT) {
|
||||||
if (backend == CLUCENE) {
|
if (!fileExists(contentPath)) {
|
||||||
indexer = new kiwix::CluceneIndexer("test.zim", indexPath);
|
cerr << "The content path '" << contentPath << "' does not exist or is not readable." << endl;
|
||||||
} else {
|
exit(1);
|
||||||
indexer = new kiwix::XapianIndexer("test.zim", indexPath);
|
|
||||||
}
|
}
|
||||||
} catch (...) {
|
|
||||||
cerr << "Unable to search through index '" << indexPath << "'." << endl;
|
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user