mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2026-01-17 02:17:44 -05:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a365c1e720 | ||
|
|
3e97352128 | ||
|
|
78d2530878 | ||
|
|
d09f481b47 | ||
|
|
e0f07086d5 | ||
|
|
bbff57e6aa | ||
|
|
3c24d0a026 | ||
|
|
6107bad17e | ||
|
|
5931ac45c4 | ||
|
|
4de8623a52 | ||
|
|
6eace310a2 | ||
|
|
c6499ad5c6 | ||
|
|
34ceaf37f2 | ||
|
|
f05096e2ce | ||
|
|
3864b2404c | ||
|
|
4cd74dca4b | ||
|
|
88cea54520 | ||
|
|
3061c8bba3 | ||
|
|
2774eb9529 | ||
|
|
77dc2ef2ed | ||
|
|
17d11f9772 | ||
|
|
68ac06c397 | ||
|
|
99f6941614 | ||
|
|
848d058610 |
@@ -1,6 +1,6 @@
|
||||
language: cpp
|
||||
dist: trusty
|
||||
sudo: required
|
||||
dist: xenial
|
||||
sudo: true
|
||||
cache: ccache
|
||||
install: travis/install_deps.sh
|
||||
script: travis/compile.sh
|
||||
|
||||
25
Changelog
25
Changelog
@@ -1,3 +1,28 @@
|
||||
kiwix-tools 2.0.0
|
||||
=================
|
||||
|
||||
kiwix-manage
|
||||
-----------
|
||||
|
||||
* Better usage()
|
||||
* Adding multiple files bug fix
|
||||
* Remove download command.
|
||||
|
||||
kiwix-serve
|
||||
-----------
|
||||
|
||||
* Better usage()
|
||||
* Display properly welcome page on 3 columns
|
||||
* New welcome page footer "Powered by Kiwix"
|
||||
|
||||
kiwix-tools 1.2.1
|
||||
=================
|
||||
|
||||
kiwix-serve
|
||||
-----------
|
||||
|
||||
* Always use POLL when avaible.
|
||||
|
||||
kiwix-tools 1.2.0
|
||||
=================
|
||||
|
||||
|
||||
15
README.md
15
README.md
@@ -26,14 +26,9 @@ The Kiwix tools rely on a few third party software libraries. They are
|
||||
prerequisites to the Kiwix tools compilation. Therefore, following
|
||||
libraries need to be available:
|
||||
|
||||
* Kiwix lib ....................... https://github.com/kiwix/kiwix-lib
|
||||
(no package so far)
|
||||
* Libmicrohttpd .......... https://www.gnu.org/software/libmicrohttpd/
|
||||
(package libmicrohttpd-dev on Ubuntu)
|
||||
* CTPP2 ..................................... http://ctpp.havoc.ru/en/
|
||||
(package libctpp2-dev on Ubuntu)
|
||||
* Zlib .......................................... http://www.zlib.net/
|
||||
(package zlib1g-dev on Ubuntu)
|
||||
* [Kiwix lib](https://github.com/kiwix/kiwix-lib) (no package so far)
|
||||
* [Libmicrohttpd](https://www.gnu.org/software/libmicrohttpd/) (package libmicrohttpd-dev on Ubuntu)
|
||||
* [Zlib](https://www.zlib.net/) (package zlib1g-dev on Ubuntu)
|
||||
|
||||
These dependencies may or may not be packaged by your operating
|
||||
system. They may also be packaged but only in an older version. They
|
||||
@@ -46,7 +41,7 @@ If you want to install these dependencies locally, then use the
|
||||
kiwix-tools directory as install prefix.
|
||||
|
||||
If you want to compile Kiwix tools statically, the dependencies should
|
||||
be compile statically (provide a lib...a library), for example by
|
||||
be compiled statically (provide a lib...a library), for example by
|
||||
using "--enable-static" with "./configure".
|
||||
|
||||
If you compile manually Libmicrohttpd, you might need to compile it
|
||||
@@ -57,7 +52,7 @@ Environment
|
||||
-------------
|
||||
|
||||
The Kiwix tools build using [Meson](http://mesonbuild.com/) version
|
||||
0.39 or higher. Meson relies itself on Ninja, pkg-config and few other
|
||||
0.43 or higher. Meson relies itself on Ninja, pkg-config and few other
|
||||
compilation tools. Install them first:
|
||||
* Meson
|
||||
* Ninja
|
||||
|
||||
@@ -4,7 +4,7 @@ LABEL maintainer Emmanuel Engelhart <kelson@kiwix.org>
|
||||
# Install kiwix-serve
|
||||
WORKDIR /
|
||||
RUN apk add --no-cache curl bzip2
|
||||
RUN curl -kL https://download.kiwix.org/release/kiwix-tools/kiwix-tools_linux-x86_64-1.1.0.tar.gz | tar -xz && \
|
||||
RUN curl -kL https://download.kiwix.org/release/kiwix-tools/kiwix-tools_linux-x86_64-1.2.1.tar.gz | tar -xz && \
|
||||
mv kiwix-tools*/kiwix-serve /usr/local/bin && \
|
||||
rm -r kiwix-tools*
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
project('kiwix-tools', 'cpp',
|
||||
version : '1.2.0',
|
||||
version : '2.0.0',
|
||||
license : 'GPL',
|
||||
default_options: ['c_std=c11', 'cpp_std=c++11', 'werror=true'])
|
||||
|
||||
@@ -11,7 +11,7 @@ if static_linkage
|
||||
endif
|
||||
|
||||
thread_dep = dependency('threads')
|
||||
kiwixlib_dep = dependency('kiwix', version:'>=4.1.0', static:static_linkage)
|
||||
kiwixlib_dep = dependency('kiwix', version:'>=5.1.0', static:static_linkage)
|
||||
microhttpd_dep = dependency('libmicrohttpd', static:static_linkage)
|
||||
z_dep = dependency('zlib', static:static_linkage)
|
||||
|
||||
|
||||
@@ -21,19 +21,14 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <getopt.h>
|
||||
#include <kiwix/tools/pathTools.h>
|
||||
#include <kiwix/tools/stringTools.h>
|
||||
#include <kiwix/manager.h>
|
||||
#include <kiwix/downloader.h>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
|
||||
using namespace std;
|
||||
|
||||
enum supportedAction { NONE, ADD, SHOW, REMOVE, DOWNLOAD };
|
||||
enum supportedAction { NONE, ADD, SHOW, REMOVE };
|
||||
|
||||
void show(kiwix::Library* library, const std::string& bookId)
|
||||
{
|
||||
@@ -57,19 +52,47 @@ void show(kiwix::Library* library, const std::string& bookId)
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
/* Print correct console usage options */
|
||||
void usage()
|
||||
{
|
||||
cerr << "Usage:" << endl;
|
||||
cerr << "\tkiwix-manage LIBRARY_PATH add ZIM_PATH "
|
||||
"[--zimPathToSave=../content/foobar.zim] [--current] "
|
||||
"[--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;
|
||||
}
|
||||
std::cout << "Usage:" << std::endl
|
||||
<< "\tkiwix-manage LIBRARY_PATH add ZIM_PATH [OPTIONS]" << std::endl
|
||||
<< "\tkiwix-manage LIBRARY_PATH remove ZIM_ID [ZIM_ID]..." << std::endl
|
||||
<< "\tkiwix-manage LIBRARY_PATH show [ZIM_ID]..." << std::endl
|
||||
<< std::endl
|
||||
|
||||
<< "Purpose:" << std::endl
|
||||
<< "\tManipulates the Kiwix library XML file"
|
||||
<< std::endl << std::endl
|
||||
|
||||
<< "Arguments:" << std::endl
|
||||
<< "\tLIBRARY_PATH\tis the XML library file path."
|
||||
<< std::endl << std::endl
|
||||
<< "\tACTION\t\tis the pre-defined string to specify the action to run on the XML library file."
|
||||
<< std::endl << std::endl
|
||||
<< "\t\t\tMust be one of the following values:" << std::endl
|
||||
<< "\t\t\t* add: add a ZIM file to the library" << std::endl
|
||||
<< "\t\t\t* remove: remove a ZIM file from the library" << std::endl
|
||||
<< "\t\t\t* show: show the content of the library"
|
||||
<< std::endl << std::endl
|
||||
<< "\tZIM_ID\t\tZIM file unique ID"
|
||||
<< std::endl << std::endl
|
||||
<< "\tOPTIONS\t\tCustom options for \"add\" action:" << std::endl
|
||||
<< "\t\t\t--zimPathToSave=CUSTOM_ZIM_PATH to replace the current ZIM file path" << std::endl
|
||||
<< "\t\t\t--url=HTTP_ZIM_URL to create an \"url\" attribute for the online version of the ZIM file" << std::endl
|
||||
<< std::endl
|
||||
|
||||
<< "Examples:" << std::endl
|
||||
<< "\tAdd ZIM files to library: kiwix-manage my_library.xml add first.zim second.zim" << std::endl
|
||||
<< "\tRemove ZIM files from library: kiwix-manage my_library.xml remove e5c2c003-b49e-2756-5176-5d9c86393dd9" << std::endl
|
||||
<< "\tShow all library ZIM files: kiwix-manage my_library.xml show" << std::endl
|
||||
<< std::endl
|
||||
|
||||
<< "Documentation:" << std::endl
|
||||
<< "\tSource code\thttps://github.com/kiwix/kiwix-tools" << std::endl
|
||||
<< "\tMore info\thttps://wiki.kiwix.org/wiki/Kiwix-manage" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
bool handle_show(kiwix::Library* library, const std::string& libraryPath,
|
||||
int argc, char* argv[])
|
||||
@@ -150,8 +173,8 @@ bool handle_add(kiwix::Library* library, const std::string& libraryPath,
|
||||
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);
|
||||
auto _zimPathToSave = zimPathToSave == "." ? zimPath : zimPathToSave;
|
||||
manager.addBookFromPathAndGetId(zimPath, _zimPathToSave, url, false);
|
||||
} else {
|
||||
std::cerr << "Invalid zim file path" << std::endl;
|
||||
resultCode = 1;
|
||||
@@ -191,62 +214,6 @@ bool handle_remove(kiwix::Library* library, const std::string& libraryPath,
|
||||
return(exitCode);
|
||||
}
|
||||
|
||||
bool handle_download(kiwix::Library* library, const std::string& libraryPath,
|
||||
int argc, char* argv[])
|
||||
{
|
||||
std::string bookId;
|
||||
bool exitCode = false;
|
||||
|
||||
if (argc > 3) {
|
||||
bookId = argv[3];
|
||||
}
|
||||
|
||||
auto& book = library->getBookById(bookId);
|
||||
auto did = book.getDownloadId();
|
||||
kiwix::Downloader downloader;
|
||||
kiwix::Download* download = nullptr;
|
||||
if (!did.empty()) {
|
||||
std::cout << "try resume " << did << std::endl;
|
||||
try {
|
||||
download = downloader.getDownload(did);
|
||||
} catch(...) {}
|
||||
}
|
||||
if (nullptr == download || download->getStatus() == kiwix::Download::K_UNKNOWN) {
|
||||
download = downloader.startDownload(book.getUrl());
|
||||
book.setDownloadId(download->getDid());
|
||||
}
|
||||
int step = 60*5;
|
||||
while (step--) {
|
||||
download->updateStatus();
|
||||
if (download->getStatus() == kiwix::Download::K_COMPLETE) {
|
||||
auto followingId = download->getFollowedBy();
|
||||
if (followingId.empty()) {
|
||||
book.setPath(download->getPath());
|
||||
book.setDownloadId("");
|
||||
std::cout << "File downloaded to " << book.getPath() << std::endl;
|
||||
break;
|
||||
} else {
|
||||
download = downloader.getDownload(followingId);
|
||||
}
|
||||
} else if (download->getStatus() == kiwix::Download::K_ACTIVE) {
|
||||
std::cout << download->getDid() << " : "
|
||||
<< kiwix::beautifyFileSize(download->getCompletedLength()) << "/"
|
||||
<< kiwix::beautifyFileSize(download->getTotalLength())
|
||||
<< " (" << kiwix::beautifyFileSize(download->getDownloadSpeed()) << "/s) "
|
||||
<< " [" << kiwix::beautifyFileSize(download->getVerifiedLength()) << "]"
|
||||
<< "[" << step << "] \n" << std::flush;
|
||||
} else if (download->getStatus() == kiwix::Download::K_ERROR) {
|
||||
std::cout << "File Error" << std::endl;
|
||||
exitCode = true;
|
||||
break;
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
|
||||
downloader.close();
|
||||
return exitCode;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
string libraryPath = "";
|
||||
@@ -264,8 +231,6 @@ int main(int argc, char** argv)
|
||||
action = SHOW;
|
||||
else if (actionString == "remove" || actionString == "delete")
|
||||
action = REMOVE;
|
||||
else if (actionString == "download")
|
||||
action = DOWNLOAD;
|
||||
}
|
||||
|
||||
/* Print usage)) if necessary */
|
||||
@@ -293,15 +258,12 @@ int main(int argc, char** argv)
|
||||
case REMOVE:
|
||||
exitCode = handle_remove(&library, libraryPath, argc, argv);
|
||||
break;
|
||||
case DOWNLOAD:
|
||||
exitCode = handle_download(&library, libraryPath, argc, argv);
|
||||
break;
|
||||
case NONE:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Rewrite the library file */
|
||||
if (action == REMOVE || action == ADD || action == DOWNLOAD) {
|
||||
if (action == REMOVE || action == ADD) {
|
||||
library.writeToFile(libraryPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,6 @@ extern "C" {
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "server-resources.h"
|
||||
@@ -106,6 +105,7 @@ static kiwix::Library library;
|
||||
static pthread_mutex_t searchLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t compressorLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static pthread_mutex_t regexLock = PTHREAD_MUTEX_INITIALIZER;
|
||||
static unsigned int nb_threads = 4;
|
||||
|
||||
std::pair<kiwix::Reader*, kiwix::Searcher*>
|
||||
get_from_humanReadableBookId(const std::string& humanReadableBookId) {
|
||||
@@ -937,6 +937,42 @@ bool hasHumanReadableIdCollision(const string &humanReadableId,
|
||||
return false;
|
||||
}
|
||||
|
||||
void usage()
|
||||
{
|
||||
std::cout << "Usage:" << std::endl
|
||||
<< "\tkiwix-serve [OPTIONS] ZIM_PATH+" << std::endl
|
||||
<< "\tkiwix-serve --library [OPTIONS] LIBRARY_PATH" << std::endl
|
||||
<< std::endl
|
||||
|
||||
<< "Purpose:" << std::endl
|
||||
<< "\tDeliver ZIM file articles via HTTP"
|
||||
<< std::endl << std::endl
|
||||
|
||||
<< "Mandatory arguments:" << std::endl
|
||||
<< "\tLIBRARY_PATH\t\tis the XML library file path listing ZIM file to serve. To be used only with the --library argument."
|
||||
<< std::endl
|
||||
<< "\tZIM_PATH\t\tis the path of a ZIM file."
|
||||
<< std::endl << std::endl
|
||||
|
||||
<< "Optional arguments:" << std::endl
|
||||
<< "\t-a, --attachToProcess\texit if given process id is not running anymore" << std::endl
|
||||
<< "\t-d, --daemon\t\tdetach the HTTP server daemon from the main process" << std::endl
|
||||
<< "\t-f, --interface\t\tlisten only on this interface, all available ones otherwise (POSIX only)" << std::endl
|
||||
<< "\t-m, --nolibrarybutton\tdo not print the builtin home button in the builtin top bar overlay" << std::endl
|
||||
<< "\t-n, --nosearchbar\tdo not print the builtin bar overlay on the top of each served page" << std::endl
|
||||
<< "\t-p, --port\t\tTCP port on which to listen to HTTP requests (default: 80)" << std::endl
|
||||
<< "\t-r, --urlRootLocation\tURL prefix on which the content should be made available (default: /)" << std::endl
|
||||
<< "\t-t, --threads\t\tnumber of threads to run in parallel (default: " << nb_threads << ")" << std::endl
|
||||
<< "\t-v, --verbose\t\tprint debug log to STDOUT" << std::endl
|
||||
<< "\t-z, --nodatealiases\tcreate URL aliases for each content by removing the date" << std::endl
|
||||
<< std::endl
|
||||
|
||||
<< "Documentation:" << std::endl
|
||||
<< "\tSource code\t\thttps://github.com/kiwix/kiwix-tools" << std::endl
|
||||
<< "\tMore info\t\thttps://wiki.kiwix.org/wiki/Kiwix-serve" << std::endl
|
||||
<< std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
struct MHD_Daemon* daemon;
|
||||
@@ -949,7 +985,6 @@ int main(int argc, char** argv)
|
||||
int libraryFlag = false;
|
||||
string PPIDString;
|
||||
unsigned int PPID = 0;
|
||||
unsigned int nb_threads = std::thread::hardware_concurrency();
|
||||
|
||||
static struct option long_options[]
|
||||
= {{"daemon", no_argument, 0, 'd'},
|
||||
@@ -1034,20 +1069,7 @@ int main(int argc, char** argv)
|
||||
|
||||
/* Print usage)) if necessary */
|
||||
if (zimPathes.empty() && libraryPath.empty()) {
|
||||
cerr << "Usage: kiwix-serve [--index=INDEX_PATH] [--port=PORT] [--verbose] "
|
||||
"[--nosearchbar] [--nolibrarybutton] [--nodatealiases] [--daemon] "
|
||||
"[--attachToProcess=PID] [--interface=IF_NAME] "
|
||||
"[--urlRootLocation=/URL_ROOT] "
|
||||
"[--threads=NB_THREAD(" << nb_threads << ")] ZIM_PATH+"
|
||||
<< endl;
|
||||
cerr << " kiwix-serve --library [--port=PORT] [--verbose] [--daemon] "
|
||||
"[--nosearchbar] [--nolibrarybutton] [--nodatealiases] [--attachToProcess=PID] "
|
||||
"[--interface=IF_NAME] [--urlRootLocation=/URL_ROOT] "
|
||||
"[--threads=NB_THREAD(" << nb_threads << ")] LIBRARY_PATH "
|
||||
<< endl;
|
||||
cerr << "\n If you set more than one ZIM_PATH, you cannot set a "
|
||||
"INDEX_PATH."
|
||||
<< endl;
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -1270,7 +1292,10 @@ int main(int argc, char** argv)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
daemon = MHD_start_daemon(MHD_USE_POLL_INTERNALLY,
|
||||
int flags = MHD_USE_POLL_INTERNALLY;
|
||||
if (isVerbose.load())
|
||||
flags |= MHD_USE_DEBUG;
|
||||
daemon = MHD_start_daemon(flags,
|
||||
serverPort,
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -1285,7 +1310,15 @@ int main(int argc, char** argv)
|
||||
#endif
|
||||
|
||||
} else {
|
||||
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY,
|
||||
#ifdef _WIN32
|
||||
int flags = MHD_USE_SELECT_INTERNALLY;
|
||||
#else
|
||||
int flags = MHD_USE_POLL_INTERNALLY;
|
||||
#endif
|
||||
if (isVerbose.load())
|
||||
flags |= MHD_USE_DEBUG;
|
||||
|
||||
daemon = MHD_start_daemon(flags,
|
||||
serverPort,
|
||||
NULL,
|
||||
NULL,
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
background-size:16px 16px;
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
max-width: 65.8em;
|
||||
max-width: 1100px;
|
||||
}
|
||||
.book__list { text-align: center; }
|
||||
.book {
|
||||
@@ -40,16 +40,16 @@
|
||||
}
|
||||
.book__info { line-height: 18px; color: #777; font-weight: bold; font-size: 13px; }
|
||||
</style>
|
||||
<script>
|
||||
$(function() {
|
||||
$( "#accordion" ).accordion();
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
<body class="kiwix">
|
||||
|
||||
<div class="kiwix">
|
||||
__BOOKS__
|
||||
</div>
|
||||
|
||||
<div id="kiwixfooter">
|
||||
Powered by <a href="https://kiwix.org">Kiwix</a>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
float: left;
|
||||
}
|
||||
|
||||
#kiwixfooter {
|
||||
text-align: center;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.height_separator {
|
||||
height: 3em;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
set -e
|
||||
|
||||
REPO_NAME=${TRAVIS_REPO_SLUG#*/}
|
||||
ARCHIVE_NAME=deps_${TRAVIS_OS_NAME}_${PLATFORM}_${REPO_NAME}.tar.xz
|
||||
ARCHIVE_NAME=deps_linux_xenial_${PLATFORM}_${REPO_NAME}.tar.xz
|
||||
|
||||
# Packages.
|
||||
case ${PLATFORM} in
|
||||
@@ -46,3 +46,4 @@ sudo cp ninja /bin
|
||||
cd ${HOME}
|
||||
wget http://tmp.kiwix.org/ci/${ARCHIVE_NAME}
|
||||
tar xf ${HOME}/${ARCHIVE_NAME}
|
||||
sudo ln -s travis ../ci_builder
|
||||
|
||||
Reference in New Issue
Block a user