|
|
|
@ -21,47 +21,54 @@
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <kiwix/common/pathTools.h>
|
|
|
|
|
#include <kiwix/manager.h>
|
|
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
enum supportedAction { NONE, ADD, SHOW, REMOVE };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void show(kiwix::Library library) {
|
|
|
|
|
std::vector<kiwix::Book>::iterator itr;
|
|
|
|
|
unsigned int inc = 1;
|
|
|
|
|
for ( itr = library.books.begin(); itr != library.books.end(); ++itr ) {
|
|
|
|
|
std::cout << "#" << inc++
|
|
|
|
|
<< std::endl << "id:\t\t" << itr->id
|
|
|
|
|
<< std::endl << "path:\t\t" << itr->path
|
|
|
|
|
<< std::endl << "indexpath:\t" << itr->indexPath
|
|
|
|
|
<< std::endl << "url:\t\t" << itr->url
|
|
|
|
|
<< std::endl << "title:\t\t" << itr->title
|
|
|
|
|
<< std::endl << "name:\t\t" << itr->name
|
|
|
|
|
<< std::endl << "tags:\t\t" << itr->tags
|
|
|
|
|
<< std::endl << "description:\t" << itr->description
|
|
|
|
|
<< std::endl << "creator:\t" << itr->creator
|
|
|
|
|
<< std::endl << "date:\t\t" << itr->date
|
|
|
|
|
<< std::endl << "articleCount:\t" << itr->articleCount
|
|
|
|
|
<< std::endl << "mediaCount:\t" << itr->mediaCount
|
|
|
|
|
<< std::endl << "size:\t\t" << itr->size << " KB"
|
|
|
|
|
<< std::endl << std::endl;
|
|
|
|
|
}
|
|
|
|
|
void show(kiwix::Library library)
|
|
|
|
|
{
|
|
|
|
|
std::vector<kiwix::Book>::iterator itr;
|
|
|
|
|
unsigned int inc = 1;
|
|
|
|
|
for (itr = library.books.begin(); itr != library.books.end(); ++itr) {
|
|
|
|
|
std::cout << "#" << inc++ << std::endl
|
|
|
|
|
<< "id:\t\t" << itr->id << std::endl
|
|
|
|
|
<< "path:\t\t" << itr->path << std::endl
|
|
|
|
|
<< "indexpath:\t" << itr->indexPath << std::endl
|
|
|
|
|
<< "url:\t\t" << itr->url << std::endl
|
|
|
|
|
<< "title:\t\t" << itr->title << std::endl
|
|
|
|
|
<< "name:\t\t" << itr->name << std::endl
|
|
|
|
|
<< "tags:\t\t" << itr->tags << std::endl
|
|
|
|
|
<< "description:\t" << itr->description << std::endl
|
|
|
|
|
<< "creator:\t" << itr->creator << std::endl
|
|
|
|
|
<< "date:\t\t" << itr->date << std::endl
|
|
|
|
|
<< "articleCount:\t" << itr->articleCount << std::endl
|
|
|
|
|
<< "mediaCount:\t" << itr->mediaCount << std::endl
|
|
|
|
|
<< "size:\t\t" << itr->size << " KB" << std::endl
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void usage() {
|
|
|
|
|
cerr << "Usage:" << endl;
|
|
|
|
|
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH [--zimPathToSave=../content/foobar.zim] [--current] [--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] [--url=http://...metalink]" << endl;
|
|
|
|
|
cerr << "\tkiwix-manage LIBRARY_PATH show [CONTENTID1] [CONTENTID2] ... (show everything if no param.)" << endl;
|
|
|
|
|
cerr << "\tkiwix-manage LIBRARY_PATH remove CONTENTID1 [CONTENTID2]" << endl;
|
|
|
|
|
void usage()
|
|
|
|
|
{
|
|
|
|
|
cerr << "Usage:" << endl;
|
|
|
|
|
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH "
|
|
|
|
|
"[--zimPathToSave=../content/foobar.zim] [--current] "
|
|
|
|
|
"[--indexBackend=xapian] [--indexPath=FULLTEXT_IDX_PATH] "
|
|
|
|
|
"[--url=http://...metalink]"
|
|
|
|
|
<< endl;
|
|
|
|
|
cerr << "\tkiwix-manage LIBRARY_PATH 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 = "";
|
|
|
|
|
supportedAction action = NONE;
|
|
|
|
|
string zimPath = "";
|
|
|
|
@ -89,9 +96,9 @@ int main(int argc, char **argv) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to read the file */
|
|
|
|
|
libraryPath = isRelativePath(libraryPath) ?
|
|
|
|
|
computeAbsolutePath(getCurrentDirectory(), libraryPath) :
|
|
|
|
|
libraryPath;
|
|
|
|
|
libraryPath = isRelativePath(libraryPath)
|
|
|
|
|
? computeAbsolutePath(getCurrentDirectory(), libraryPath)
|
|
|
|
|
: libraryPath;
|
|
|
|
|
libraryManager.readFile(libraryPath, false);
|
|
|
|
|
|
|
|
|
|
/* SHOW */
|
|
|
|
@ -103,81 +110,78 @@ int main(int argc, char **argv) {
|
|
|
|
|
string indexPath;
|
|
|
|
|
kiwix::supportedIndexType indexBackend = kiwix::XAPIAN;
|
|
|
|
|
string url;
|
|
|
|
|
string origID="";
|
|
|
|
|
string origID = "";
|
|
|
|
|
bool setCurrent = false;
|
|
|
|
|
|
|
|
|
|
if (argc>3) {
|
|
|
|
|
if (argc > 3) {
|
|
|
|
|
zimPath = argv[3];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Options parsing */
|
|
|
|
|
optind = 2;
|
|
|
|
|
while (42) {
|
|
|
|
|
static struct option long_options[]
|
|
|
|
|
= {{"url", required_argument, 0, 'u'},
|
|
|
|
|
{"origId", required_argument, 0, 'o'},
|
|
|
|
|
{"indexPath", required_argument, 0, 'i'},
|
|
|
|
|
{"indexBackend", required_argument, 0, 'b'},
|
|
|
|
|
{"zimPathToSave", required_argument, 0, 'z'},
|
|
|
|
|
{"current", no_argument, 0, 'c'},
|
|
|
|
|
{0, 0, 0, 0}};
|
|
|
|
|
|
|
|
|
|
static struct option long_options[] = {
|
|
|
|
|
{"url", required_argument, 0, 'u'},
|
|
|
|
|
{"origId", required_argument, 0, 'o'},
|
|
|
|
|
{"indexPath", required_argument, 0, 'i'},
|
|
|
|
|
{"indexBackend", required_argument, 0, 'b'},
|
|
|
|
|
{"zimPathToSave", required_argument, 0, 'z'},
|
|
|
|
|
{"current", no_argument, 0, 'c'},
|
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, "cz:u:i:b:", long_options, &option_index);
|
|
|
|
|
|
|
|
|
|
if (c != -1) {
|
|
|
|
|
|
|
|
|
|
switch (c) {
|
|
|
|
|
case 'u':
|
|
|
|
|
url = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
|
origID = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
|
setCurrent = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
|
indexPath = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
|
if (!strcmp(optarg, "xapian")) {
|
|
|
|
|
indexBackend = kiwix::XAPIAN;
|
|
|
|
|
} else {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
|
zimPathToSave = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
if (c != -1) {
|
|
|
|
|
switch (c) {
|
|
|
|
|
case 'u':
|
|
|
|
|
url = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
|
origID = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'c':
|
|
|
|
|
setCurrent = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'i':
|
|
|
|
|
indexPath = optarg;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
|
if (!strcmp(optarg, "xapian")) {
|
|
|
|
|
indexBackend = kiwix::XAPIAN;
|
|
|
|
|
} else {
|
|
|
|
|
usage();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'z':
|
|
|
|
|
zimPathToSave = optarg;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
break;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!zimPath.empty()) {
|
|
|
|
|
zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
|
|
|
|
|
string bookId = libraryManager.addBookFromPathAndGetId(zimPath, zimPathToSave, url, false);
|
|
|
|
|
string bookId = libraryManager.addBookFromPathAndGetId(
|
|
|
|
|
zimPath, zimPathToSave, url, false);
|
|
|
|
|
|
|
|
|
|
if (!bookId.empty()) {
|
|
|
|
|
if (setCurrent)
|
|
|
|
|
libraryManager.setCurrentBookId(bookId);
|
|
|
|
|
|
|
|
|
|
if (setCurrent)
|
|
|
|
|
libraryManager.setCurrentBookId(bookId);
|
|
|
|
|
|
|
|
|
|
/* Save the index infos if necessary */
|
|
|
|
|
if (!indexPath.empty())
|
|
|
|
|
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
|
|
|
|
|
/* Save the index infos if necessary */
|
|
|
|
|
if (!indexPath.empty())
|
|
|
|
|
libraryManager.setBookIndex(bookId, indexPath, indexBackend);
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
cerr << "Unable to build or save library file '" << libraryPath << "'" << endl;
|
|
|
|
|
cerr << "Unable to build or save library file '" << libraryPath << "'"
|
|
|
|
|
<< endl;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
std::cerr << "Invalid zim file path" << std::endl;
|
|
|
|
@ -187,7 +191,7 @@ int main(int argc, char **argv) {
|
|
|
|
|
unsigned int bookIndex = 0;
|
|
|
|
|
const unsigned int totalBookCount = libraryManager.getBookCount(true, true);
|
|
|
|
|
|
|
|
|
|
if (argc>3) {
|
|
|
|
|
if (argc > 3) {
|
|
|
|
|
bookIndex = atoi(argv[3]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -195,9 +199,13 @@ int main(int argc, char **argv) {
|
|
|
|
|
libraryManager.removeBookByIndex(bookIndex - 1);
|
|
|
|
|
} else {
|
|
|
|
|
if (totalBookCount > 0) {
|
|
|
|
|
std::cerr << "Invalid book index number. Please give a number between 1 and " << totalBookCount << std::endl;
|
|
|
|
|
std::cerr
|
|
|
|
|
<< "Invalid book index number. Please give a number between 1 and "
|
|
|
|
|
<< totalBookCount << std::endl;
|
|
|
|
|
} else {
|
|
|
|
|
std::cerr << "Invalid book index number. Library is empty, no book to delete." << std::endl;
|
|
|
|
|
std::cerr
|
|
|
|
|
<< "Invalid book index number. Library is empty, no book to delete."
|
|
|
|
|
<< std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|