[sword-cvs] sword/utilities Makefile.am,1.18,1.19 installmgr.cpp,1.1,1.2 osis2mod.cpp,1.2,1.3
sword@www.crosswire.org
sword@www.crosswire.org
Mon, 7 Jul 2003 07:16:28 -0700
Update of /usr/local/cvsroot/sword/utilities
In directory www:/tmp/cvs-serv15875/utilities
Modified Files:
Makefile.am installmgr.cpp osis2mod.cpp
Log Message:
Added InstallMgr basic feature for remote source installation
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/sword/utilities/Makefile.am,v
retrieving revision 1.18
retrieving revision 1.19
diff -C2 -d -r1.18 -r1.19
*** Makefile.am 30 May 2003 19:22:32 -0000 1.18
--- Makefile.am 7 Jul 2003 14:16:25 -0000 1.19
***************
*** 24,27 ****
--- 24,28 ----
lexdump_SOURCES = lexdump.c
lexdump_LDADD = -lstdc++
+ installmgr_LDADD = $(CURL_LIBS) $(LDADD)
mkfastmod_SOURCES = mkfastmod.cpp
mod2vpl_SOURCES = mod2vpl.cpp
Index: installmgr.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/utilities/installmgr.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** installmgr.cpp 30 May 2003 19:25:20 -0000 1.1
--- installmgr.cpp 7 Jul 2003 14:16:25 -0000 1.2
***************
*** 1,40 ****
#include <swmgr.h>
#include <installmgr.h>
#include <iostream>
using namespace sword;
using std::cout;
void usage(const char *progName) {
! fprintf(stderr, "usage: %s <option>\nOptions:\n\t-l\t\tlist installed modules\n\t-u <modName>\tuninstall module\n", progName);
! exit(-1);
}
int main(int argc, char **argv) {
if (argc < 2)
usage(*argv);
! SWMgr mgr;
! SWModule *module = 0;
! if (argv[1][1] == 'l') {
! for (ModMap::iterator it = mgr.Modules.begin(); it != mgr.Modules.end(); it++) {
! module = it->second;
! cout << "[" << module->Name() << "] \t- " << module->Description() << "\n";
}
! }
! else if (argv[1][1] == 'u') {
if (argc < 3)
usage(*argv);
! ModMap::iterator it = mgr.Modules.find(argv[2]);
! if (it == mgr.Modules.end()) {
! fprintf(stderr, "Couldn't find module [%s] to remove\n", argv[2]);
! exit(-2);
}
! module = it->second;
! removeModule(&mgr, module->Name());
! cout << "Removed module: [" << module->Name() << "]\n";
}
! else usage(*argv);
return 0;
--- 1,249 ----
#include <swmgr.h>
#include <installmgr.h>
+ #include <filemgr.h>
#include <iostream>
+ #include <string>
using namespace sword;
using std::cout;
+ using std::cin;
+ using std::string;
+
+
+ SWMgr *mgr;
+ InstallMgr *installMgr;
+
+
+ void finish(int status) {
+ delete installMgr;
+ delete mgr;
+ cout << "\n";
+ exit(status);
+ }
+
void usage(const char *progName) {
! fprintf(stderr, "usage: %s <option>\nOptions:\n"
! "\t-init\t\t\t\tcreate a basic user config file.\n"
! "\t\t\t\t\t\tWARNING: overwrites existing.\n"
! "\t-l\t\t\t\tlist installed modules\n"
! "\t-u <modName>\t\t\tuninstall module\n"
! "\t-s\t\t\t\tlist remote sources\n"
! "\t-r <remoteSrcName>\t\trefresh remote source\n"
! "\t-rl <remoteSrcName>\t\tlist available modules from remote source\n"
! "\t-ri <remoteSrcName> <modName>\tinstall module from remote source\n"
! "\t-ll <path>\t\t\tlist available modules at local path\n"
! "\t-li <path> <modName>\t\tinstall module from local path\n"
! , progName);
! finish(-1);
}
+
+ void initConfig() {
+ cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
+ cout << " -=+* WARNING *+=- -=+* WARNING *+=-\n\n\n";
+ cout << "Although Install Manager provides a convenient way for installing\n";
+ cout << "and upgrading SWORD components, it also uses a systematic method\n";
+ cout << "for accessing sites which gives packet sniffers a target to lock\n";
+ cout << "into for singling out users. \n\n\n";
+ cout << "IF YOU LIVE IN A PERSECUTED COUNTRY AND DO NOT WISH TO RISK DETECTION,\n";
+ cout << "YOU SHOULD *NOT* USE INSTALL MANAGER'S REMOTE SOURCE FEATURES.\n\n\n";
+ cout << "if you understand this and are willing to enable remote source features\n";
+ cout << "then type yes at the prompt\n\n";
+ cout << "enable? [no] ";
+ char *prompt = 0;
+ size_t size = 0;
+ getline(&prompt, &size, stdin);
+ bool enable = (!strcmp(prompt, "yes\n"));
+ free(prompt);
+ char *envhomedir = getenv ("HOME");
+ SWBuf confPath = (envhomedir) ? envhomedir : ".";
+ confPath += "/.sword/InstallMgr/InstallMgr.conf";
+ FileMgr::createParent(confPath.c_str());
+ remove(confPath.c_str());
+
+ InstallSource is("FTP");
+ is.caption = "crosswire";
+ is.source = "ftp.crosswire.org";
+ is.directory = "/pub/sword/raw";
+
+ SWConfig config(confPath.c_str());
+ config["General"]["PassiveFTF"] = "true";
+ if (enable) {
+ config["Sources"]["FTPSource"] = is.getConfEnt();
+ }
+ config.Save();
+ cout << "\n\nInitialized basic config file at [" << confPath << "]\n";
+ cout << "with remote source features " << ((enable) ? "ENABLED" : "DISABLED") << "\n";
+ }
+
+
+ void listModules(SWMgr *mgr) {
+ cout << "Installed Modules:\n\n";
+ SWModule *module;
+ for (ModMap::iterator it = mgr->Modules.begin(); it != mgr->Modules.end(); it++) {
+ module = it->second;
+ cout << "[" << module->Name() << "] \t- " << module->Description() << "\n";
+ }
+ }
+
+
+ void uninstallModule(const char *modName) {
+ SWModule *module;
+ ModMap::iterator it = mgr->Modules.find(modName);
+ if (it == mgr->Modules.end()) {
+ fprintf(stderr, "Couldn't find module [%s] to remove\n", modName);
+ finish(-2);
+ }
+ module = it->second;
+ installMgr->removeModule(mgr, module->Name());
+ cout << "Removed module: [" << module->Name() << "]\n";
+ }
+
+
+ void listRemoteSources() {
+ cout << "Remote Sources:\n\n";
+ for (InstallSourceMap::iterator it = installMgr->sources.begin(); it != installMgr->sources.end(); it++) {
+ cout << "[" << it->second->caption << "]\n";
+ cout << "\tType ; " << it->second->type << "\n";
+ cout << "\tSource ; " << it->second->source << "\n";
+ cout << "\tDirectory; " << it->second->directory << "\n";
+ }
+ }
+
+
+ void refreshRemoteSource(const char *sourceName) {
+ InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
+ if (source == installMgr->sources.end()) {
+ fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
+ finish(-3);
+ }
+ installMgr->refreshRemoteSource(source->second);
+ cout << "Remote Source Refreshed\n";
+ }
+
+
+ void remoteListModules(const char *sourceName) {
+ cout << "Available Modules:\n(be sure to refresh remote source (-r) first for most current list)\n\n";
+ InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
+ if (source == installMgr->sources.end()) {
+ fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
+ finish(-3);
+ }
+ listModules(source->second->getMgr());
+ }
+
+
+ void localDirListModules(const char *dir) {
+ cout << "Available Modules:\n\n";
+ SWMgr mgr(dir);
+ listModules(&mgr);
+ }
+
+
+ void remoteInstallModule(const char *sourceName, const char *modName) {
+ InstallSourceMap::iterator source = installMgr->sources.find(sourceName);
+ if (source == installMgr->sources.end()) {
+ fprintf(stderr, "Couldn't find remote source [%s]\n", sourceName);
+ finish(-3);
+ }
+ InstallSource *is = source->second;
+ SWMgr *rmgr = is->getMgr();
+ SWModule *module;
+ ModMap::iterator it = rmgr->Modules.find(modName);
+ if (it == rmgr->Modules.end()) {
+ fprintf(stderr, "Remote source [%s] does not make available module [%s]\n", sourceName, modName);
+ finish(-4);
+ }
+ module = it->second;
+ installMgr->installModule(mgr, 0, module->Name(), is);
+ cout << "Installed module: [" << module->Name() << "]\n";
+ }
+
+
+ void localDirInstallModule(const char *dir, const char *modName) {
+ SWMgr lmgr(dir);
+ SWModule *module;
+ ModMap::iterator it = lmgr.Modules.find(modName);
+ if (it == lmgr.Modules.end()) {
+ fprintf(stderr, "Module [%s] not available at path [%s]\n", modName, dir);
+ finish(-4);
+ }
+ module = it->second;
+ installMgr->installModule(mgr, dir, module->Name());
+ cout << "Installed module: [" << module->Name() << "]\n";
+ }
+
+
int main(int argc, char **argv) {
+
+ mgr = new SWMgr();
+ char *envhomedir = getenv ("HOME");
+ SWBuf baseDir = (envhomedir) ? envhomedir : ".";
+ baseDir += "/.sword/InstallMgr";
+ installMgr = new InstallMgr(baseDir);
+
+ cout << "\n";
+
if (argc < 2)
usage(*argv);
! switch (argv[1][1]) {
! case 'i':
! if (strcmp(argv[1], "-init"))
! usage(*argv);
! initConfig();
! break;
! case 'l':
! switch (argv[1][2]) {
! case 0: // -l list installed modules
! listModules(mgr);
! break;
! case 'l': // -ll list from local directory
! if (argc < 3)
! usage(*argv);
! localDirListModules(argv[2]);
! break;
! case 'i': // -li remote install
! if (argc < 4)
! usage(*argv);
! localDirInstallModule(argv[2], argv[3]);
! break;
! default: usage(*argv);
}
! break;
! case 'u':
if (argc < 3)
usage(*argv);
! uninstallModule(argv[2]);
! break;
! case 's':
! listRemoteSources();
! break;
! case 'r': // remote option
! switch (argv[1][2]) {
! case 0: // -r refresh
! if (argc < 3)
! usage(*argv);
! refreshRemoteSource(argv[2]);
! break;
! case 'l': // -rl remote list
! if (argc < 3)
! usage(*argv);
! remoteListModules(argv[2]);
! break;
! case 'i': // -ri remote install
! if (argc < 4)
! usage(*argv);
! remoteInstallModule(argv[2], argv[3]);
! break;
! default: usage(*argv);
}
! break;
! default: usage(*argv);
}
!
! finish(0);
return 0;
Index: osis2mod.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/utilities/osis2mod.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** osis2mod.cpp 28 May 2003 01:53:00 -0000 1.2
--- osis2mod.cpp 7 Jul 2003 14:16:25 -0000 1.3
***************
*** 92,97 ****
void writeEntry(VerseKey &key, SWBuf &text) {
! cout << "Verse: " << key << "\n";
! cout << "TEXT: " << text << "\n\n";
SWBuf currentText = module->getRawEntry();
if (currentText.length())
--- 92,97 ----
void writeEntry(VerseKey &key, SWBuf &text) {
! // cout << "Verse: " << key << "\n";
! // cout << "TEXT: " << text << "\n\n";
SWBuf currentText = module->getRawEntry();
if (currentText.length())
***************
*** 120,124 ****
if (!strcmp(token.getAttribute("type"), "book")) {
if (inHeader) { // this one should never happen, but just in case
! cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;
--- 120,124 ----
if (!strcmp(token.getAttribute("type"), "book")) {
if (inHeader) { // this one should never happen, but just in case
! // cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;
***************
*** 134,138 ****
if (!strcmp(token.getAttribute("type"), "chapter")) {
if (inHeader) {
! cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;
--- 134,138 ----
if (!strcmp(token.getAttribute("type"), "chapter")) {
if (inHeader) {
! // cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;
***************
*** 149,153 ****
if ((!strcmp(token.getName(), "verse")) && (!token.isEndTag())) {
if (inHeader) {
! cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;
--- 149,153 ----
if ((!strcmp(token.getName(), "verse")) && (!token.isEndTag())) {
if (inHeader) {
! // cout << "HEADING ";
writeEntry(currentVerse, text);
inHeader = false;