From 1ef596733da4742fb6eb94768da89a57a29d79ae Mon Sep 17 00:00:00 2001 From: Frank Celler Date: Fri, 20 Dec 2013 23:49:16 +0100 Subject: [PATCH] arangosh now uses config file name corresponding to binary name --- CHANGELOG | 3 ++ Makefile.in | 10 ++-- README | 14 ++++-- arangosh/V8Client/arangosh.cpp | 80 ++++++++++++++++++------------- etc/Makefile.files | 3 +- etc/arangodb/foxx-manager.conf.in | 11 +++++ etc/relative/foxx-manager.conf | 10 ++++ lib/BasicsC/files.c | 24 ++++++++++ lib/BasicsC/files.h | 6 +++ 9 files changed, 120 insertions(+), 41 deletions(-) create mode 100644 etc/arangodb/foxx-manager.conf.in create mode 100644 etc/relative/foxx-manager.conf diff --git a/CHANGELOG b/CHANGELOG index 77b8e93cafbd..3dcf9c859657 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,9 @@ v1.4.x (XXXX-XX-XX) ------------------- +* arangosh now uses the config-file which maps the binary name, i. e. if you + rename arangosh to foxx-manager it will use the config file foxx-manager.conf + * fixed issue #711, #687: foxx-manager throws internal errors * added `--server.ssl-protocol` option for client tools diff --git a/Makefile.in b/Makefile.in index 96a8994e5fb7..5fed94822a70 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1141,11 +1141,11 @@ BUILT_SOURCES = build.h etc/arangodb/arangod-uid.conf \ etc/arangodb/arangod.conf etc/arangodb/arangodump.conf \ etc/arangodb/arangoimp.conf etc/arangodb/arangoirb.conf \ etc/arangodb/arangorestore.conf etc/arangodb/arangosh.conf \ - $(am__append_12) Doxygen/.setup-directories \ - $(JAVASCRIPT_BROWSER) @builddir@/.setup-js-directories \ - $(am__append_13) $(am__append_15) $(am__append_16) @ZLIB_LIBS@ \ - $(am__append_17) $(am__append_19) $(am__append_21) \ - $(am__append_23) + etc/arangodb/foxx-manager.conf $(am__append_12) \ + Doxygen/.setup-directories $(JAVASCRIPT_BROWSER) \ + @builddir@/.setup-js-directories $(am__append_13) \ + $(am__append_15) $(am__append_16) @ZLIB_LIBS@ $(am__append_17) \ + $(am__append_19) $(am__append_21) $(am__append_23) ################################################################################ ### @brief man pages to install diff --git a/README b/README index 0c8980751a6e..9527cd9c53bb 100644 --- a/README +++ b/README @@ -1,8 +1,8 @@ ArangoDB ArangoDB is a multi-purpose open-source database with flexible data models for -documents, graphs, and key-values. Build high performance application using a -convenient sql-like query language or JavaScript/Ruby extensions. +documents, graphs, and key-values. Build high performance applications using a +convenient SQL-like query language or JavaScript/Ruby extensions. Key features include: * Schema-free schemata let you combine the space efficiency of MySQL with the @@ -21,7 +21,7 @@ Key features include: * No-nonsense storage: ArangoDB uses all of the power of modern storage hardware, like SSD and large caches * Powerful query language (AQL) to retrieve data -* Transactions: run queries on multiple documents or collections with optional +* Transactions: run queries on multiple documents or collections with optional transactional consistency and isolation * Replication: set up the database in a master-slave configuration * It is open source (Apache Licence 2.0) @@ -87,3 +87,11 @@ You can use the Google group for improvements, feature requests, comments http://www.arangodb.org/connect + +Citing ArangoDB + +Please kindly cite ArangoDB in your publications if it helps your research: +bibtex @misc{ArangoDB2013, Author = {ArangoDB}, Title = { {ArangoDB}: An Open +Source multi-purpose database supporting flexible data models for documents, +graphs, and key-values.}, Year = {2013}, Howpublished = {\url{http:// +arangodb.org/} } diff --git a/arangosh/V8Client/arangosh.cpp b/arangosh/V8Client/arangosh.cpp index 7f7daf774d75..b1e4c37bd1ed 100644 --- a/arangosh/V8Client/arangosh.cpp +++ b/arangosh/V8Client/arangosh.cpp @@ -73,24 +73,30 @@ using namespace triagens::arango; // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief base class for clients +/// @brief Windows console codepage //////////////////////////////////////////////////////////////////////////////// -ArangoClient BaseClient; +#ifdef _WIN32 +static int CodePage = 65001; +#endif //////////////////////////////////////////////////////////////////////////////// -/// @brief the initial default connection +/// @brief command prompt //////////////////////////////////////////////////////////////////////////////// -V8ClientConnection* ClientConnection = 0; +static string Prompt = "arangosh [%d]> "; //////////////////////////////////////////////////////////////////////////////// -/// @brief Windows console codepage +/// @brief base class for clients //////////////////////////////////////////////////////////////////////////////// -#ifdef _WIN32 -static int CodePage = 65001; -#endif +ArangoClient BaseClient; + +//////////////////////////////////////////////////////////////////////////////// +/// @brief the initial default connection +//////////////////////////////////////////////////////////////////////////////// + +V8ClientConnection* ClientConnection = 0; //////////////////////////////////////////////////////////////////////////////// /// @brief object template for the initial connection @@ -158,12 +164,6 @@ static vector UnitTests; static vector JsLint; -//////////////////////////////////////////////////////////////////////////////// -/// @brief command prompt -//////////////////////////////////////////////////////////////////////////////// - -static string Prompt = "arangosh [%d]> "; - // ----------------------------------------------------------------------------- // --SECTION-- JavaScript functions // ----------------------------------------------------------------------------- @@ -358,7 +358,7 @@ static v8::Handle JS_ImportJsonFile (v8::Arguments const& argv) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief normalize UTF 16 strings +/// @brief normalizes UTF 16 strings //////////////////////////////////////////////////////////////////////////////// static v8::Handle JS_normalize_string (v8::Arguments const& argv) { @@ -391,24 +391,18 @@ static v8::Handle JS_compare_string (v8::Arguments const& argv) { } // ----------------------------------------------------------------------------- -// --SECTION-- private functions +// --SECTION-- private enums // ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// -/// @brief return a new client connection instance +/// @brief ClientConnection class //////////////////////////////////////////////////////////////////////////////// -static V8ClientConnection* CreateConnection () { - return new V8ClientConnection(BaseClient.endpointServer(), - BaseClient.databaseName(), - BaseClient.username(), - BaseClient.password(), - BaseClient.requestTimeout(), - BaseClient.connectTimeout(), - ArangoClient::DEFAULT_RETRIES, - BaseClient.sslProtocol(), - false); -} +enum WRAP_CLASS_TYPES {WRAP_TYPE_CONNECTION = 1}; + +// ----------------------------------------------------------------------------- +// --SECTION-- private functions +// ----------------------------------------------------------------------------- //////////////////////////////////////////////////////////////////////////////// /// @brief parses the program options @@ -462,7 +456,13 @@ static vector ParseProgramOptions (int argc, char* argv[]) { // and parse the command line and config file ProgramOptions options; - BaseClient.parse(options, description, argc, argv, "arangosh.conf"); + + char* p = TRI_BinaryName(argv[0]); + string conf = p; + TRI_FreeString(TRI_CORE_MEM_ZONE, p); + conf += ".conf"; + + BaseClient.parse(options, description, argc, argv, conf); // set V8 options v8::V8::SetFlagsFromCommandLine(&argc, argv, true); @@ -487,13 +487,15 @@ static vector ParseProgramOptions (int argc, char* argv[]) { } //////////////////////////////////////////////////////////////////////////////// -/// @brief copy v8::Object to std::map +/// @brief copies v8::Object to std::map //////////////////////////////////////////////////////////////////////////////// static void objectToMap (map& myMap, v8::Handle val) { v8::Handle v8Headers = val.As (); + if (v8Headers->IsObject()) { v8::Handle props = v8Headers->GetPropertyNames(); + for (uint32_t i = 0; i < props->Length(); i++) { v8::Handle key = props->Get(v8::Integer::New(i)); myMap[TRI_ObjectToString(key)] = TRI_ObjectToString(v8Headers->Get(key)); @@ -502,10 +504,20 @@ static void objectToMap (map& myMap, v8::Handle val) } //////////////////////////////////////////////////////////////////////////////// -/// @brief ClientConnection class +/// @brief returns a new client connection instance //////////////////////////////////////////////////////////////////////////////// -enum WRAP_CLASS_TYPES {WRAP_TYPE_CONNECTION = 1}; +static V8ClientConnection* CreateConnection () { + return new V8ClientConnection(BaseClient.endpointServer(), + BaseClient.databaseName(), + BaseClient.username(), + BaseClient.password(), + BaseClient.requestTimeout(), + BaseClient.connectTimeout(), + ArangoClient::DEFAULT_RETRIES, + BaseClient.sslProtocol(), + false); +} //////////////////////////////////////////////////////////////////////////////// /// @brief weak reference callback for queries (call the destructor here) @@ -1569,6 +1581,8 @@ static void arangoshExitFunction (int, void*); // ............................................................................. // Call this function to do various initialistions for windows only +// +// TODO can we move this to a general function for all binaries? // ............................................................................. void arangoshEntryFunction() { @@ -1798,6 +1812,8 @@ int main (int argc, char* argv[]) { if (CodePage > 0) { SetConsoleOutputCP((UINT) CodePage); } + + // TODO we should have a special "printf" which can handle the color escape sequences! SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), greenColour); printf(" "); SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), redColour); diff --git a/etc/Makefile.files b/etc/Makefile.files index 04c165c6b5a9..7fc616d37821 100644 --- a/etc/Makefile.files +++ b/etc/Makefile.files @@ -11,7 +11,8 @@ BUILT_SOURCES += \ etc/arangodb/arangoimp.conf \ etc/arangodb/arangoirb.conf \ etc/arangodb/arangorestore.conf \ - etc/arangodb/arangosh.conf + etc/arangodb/arangosh.conf \ + etc/arangodb/foxx-manager.conf ################################################################################ ### @brief config diff --git a/etc/arangodb/foxx-manager.conf.in b/etc/arangodb/foxx-manager.conf.in new file mode 100644 index 000000000000..32727ed89107 --- /dev/null +++ b/etc/arangodb/foxx-manager.conf.in @@ -0,0 +1,11 @@ +pretty-print = true + +[server] +endpoint = tcp://localhost:8529 +disable-authentication = true + +[javascript] +startup-directory = @PKGDATADIR@/js +modules-path = @PKGDATADIR@/js/client/modules;@PKGDATADIR@/js/common/modules;@PKGDATADIR@/js/node +package-path = @PKGDATADIR@/js/npm +execute-string = require("org/arangodb/foxx/manager").run(ARGUMENTS); diff --git a/etc/relative/foxx-manager.conf b/etc/relative/foxx-manager.conf new file mode 100644 index 000000000000..77bb7528df73 --- /dev/null +++ b/etc/relative/foxx-manager.conf @@ -0,0 +1,10 @@ +pretty-print = true + +[server] +disable-authentication = true + +[javascript] +startup-directory = ./js +modules-path = ./js/client/modules;./js/common/modules;./js/node +package-path = ./js/npm +execute-string = require("org/arangodb/foxx/manager").run(ARGUMENTS); diff --git a/lib/BasicsC/files.c b/lib/BasicsC/files.c index 3e6ce361dfa6..7fa32719670c 100644 --- a/lib/BasicsC/files.c +++ b/lib/BasicsC/files.c @@ -1578,6 +1578,30 @@ char* TRI_GetAbsolutePath (char const* file, char const* cwd) { #endif +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the binary name without any path or suffix +//////////////////////////////////////////////////////////////////////////////// + +char* TRI_BinaryName (const char* argv0) { + char* name; + char* p; + char* e; + + name = TRI_Basename(argv0); + + p = name; + e = name + strlen(name); + + for (; p < e; ++p) { + if (*p == '.') { + *p = '\0'; + break; + } + } + + return name; +} + //////////////////////////////////////////////////////////////////////////////// /// @brief locates the directory containing the program //////////////////////////////////////////////////////////////////////////////// diff --git a/lib/BasicsC/files.h b/lib/BasicsC/files.h index 9f6a6646b9a8..dab959128faf 100644 --- a/lib/BasicsC/files.h +++ b/lib/BasicsC/files.h @@ -246,6 +246,12 @@ char* TRI_GetFilename (char const*); char* TRI_GetAbsolutePath (char const*, char const*); +//////////////////////////////////////////////////////////////////////////////// +/// @brief returns the binary name without any path or suffix +//////////////////////////////////////////////////////////////////////////////// + +char* TRI_BinaryName (const char* argv0); + //////////////////////////////////////////////////////////////////////////////// /// @brief locates the directory containing the program ////////////////////////////////////////////////////////////////////////////////