couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r662279 - in /incubator/couchdb/branches/runtimeconfig: etc/ etc/couchdb/ share/www/script/ src/couchdb/
Date Sun, 01 Jun 2008 20:17:42 GMT
Author: jan
Date: Sun Jun  1 13:17:42 2008
New Revision: 662279

URL: http://svn.apache.org/viewvc?rev=662279&view=rev
Log:
integrate config writer into the build.

Added:
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl
Removed:
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couchdb_config_writer.erl
Modified:
    incubator/couchdb/branches/runtimeconfig/etc/Makefile.am
    incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am
    incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
    incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
    incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl

Modified: incubator/couchdb/branches/runtimeconfig/etc/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/Makefile.am?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/Makefile.am Sun Jun  1 13:17:42 2008
@@ -40,7 +40,7 @@
 	        mkdir default; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%pkgconfdir%|@pkgconfdir@|g" \
 	       -e "s|%sysconfdir%|@sysconfdir@|" \
 	       -e "s|%localstatedir%|@localstatedir@|" \
@@ -55,7 +55,7 @@
 	        mkdir init; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%bindir%|@bindir@|" \
 	       -e "s|%sysconfdir%|@sysconfdir@|" \
 	       -e "s|%erlangbindir%|@erlangbindir@|" \
@@ -74,7 +74,7 @@
 	        mkdir launchd; \
 	    fi \
 	fi
-	sed -r -e "s|%configure_input%|$@. Generated from $< by configure.|" \
+	sed -E -e "s|%configure_input%|$@. Generated from $< by configure.|" \
 	       -e "s|%bindir%|@bindir@|" \
 	       -e "s|%couchdb_command_name%|$(couchdb_command_name)|" \
 	       -e "s|([^:])/+|\1/|g" \

Modified: incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/etc/couchdb/Makefile.am Sun Jun  1 13:17:42 2008
@@ -22,7 +22,7 @@
 couchprivlibdir = $(erlanglibdir)/couch-$(version)/priv/lib
 
 couch.ini: couch.ini.tpl
-	sed -r -e "s|%bindir%|@bindir@|g" \
+	sed -E -e "s|%bindir%|@bindir@|g" \
 	       -e "s|%pkgconfdir%|@pkgconfdir@|g" \
 	       -e "s|%pkgdatadir%|@pkgdatadir@|g" \
 	       -e "s|%pkgstatelibdir%|@pkgstatelibdir@|g" \

Modified: incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] (original)
+++ incubator/couchdb/branches/runtimeconfig/share/www/script/couch_tests.js [utf-8] Sun Jun
 1 13:17:42 2008
@@ -1038,35 +1038,35 @@
     if(debug) debugger;
     var xhr;
 
-    xhr = CouchDB.request("GET", "/_config/HTTPd/Port");
+    xhr = CouchDB.request("GET", "/_config/CouchDB/ConsoleStartupMsg");
     T(xhr.status == 200);
     T(JSON.parse(xhr.responseText).ok);
 
-    xhr = CouchDB.request("POST", "/_config/HTTPd/Port", {"body":"5985"});
+    xhr = CouchDB.request("POST", "/_config/CouchDB/ConsoleStartupMsg", {"body":"CouchDB
is awesome."});
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
-    T(res.value == "5985");
+    T(res.value == "CouchDB is awesome.");
 
-    xhr = CouchDB.request("GET", "/_config/HTTPd/Port");
+    xhr = CouchDB.request("GET", "/_config/CouchDB/ConsoleStartupMsg");
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
-    T(res.value == "5985");
+    T(res.value == "CouchDB is awesome.");
 
-    xhr = CouchDB.request("DELETE", "/_config/HTTPd/Port");
+    xhr = CouchDB.request("DELETE", "/_config/CouchDB/ConsoleStartupMsg");
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
-    T(res.old_value == "5985");
+    T(res.old_value == "CouchDB is awesome.");
 
-    xhr = CouchDB.request("PUT", "/_config/HTTPd/Port", {"body":"5984"});
+    xhr = CouchDB.request("PUT", "/_config/CouchDB/ConsoleStartupMsg", {"body":"Apache CouchDB
is starting."});
     T(xhr.status == 200);
     var res = JSON.parse(xhr.responseText);
     T(res.ok);
-    T(res.value == "5984");
-    }
-  };
+    T(res.value == "Apache CouchDB is starting.");
+  }
+};
 
 function makeDocs(start, end, templateDoc) {
   var templateDocSrc = templateDoc ? templateDoc.toSource() : "{}"

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/Makefile.am Sun Jun  1 13:17:42 2008
@@ -31,7 +31,8 @@
 couch_file_collection = \
     cjson.erl \
     couch_btree.erl \
-	couch_config.erl \
+    couch_config.erl \
+    couch_config_writer.erl \
     couch_db.erl \
     couch_db_update_notifier.erl \
     couch_doc.erl \
@@ -53,7 +54,8 @@
     cjson.beam \
     couch.app \
     couch_btree.beam \
-	couch_config.beam \
+    couch_config.beam \
+    couch_config_writer.beam \
     couch_db.beam \
     couch_db_update_notifier.beam \
     couch_doc.beam \

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config.erl Sun Jun  1 13:17:42
2008
@@ -34,18 +34,14 @@
 lookup_match(Key, Default) -> gen_server:call(?MODULE, {lookup_match, Key, Default}).
 dump() -> gen_server:call(?MODULE, {dump, []}).
 
-
 unset(Key) -> gen_server:call(?MODULE, {unset, Key}).
 
-
 init([]) ->     
     Tap = ets:new(?MODULE, []),
     {ok, Tap}.
 
-
 handle_call({store, Config}, _From, Tab) ->
-    [ets:insert(Tab, {Key, Value}) || {Key, Value} <- Config],
-    commit(Config),
+    [insert_and_commit(Tab, Config2) || Config2 <- Config],
     {reply, ok, Tab};
 
 handle_call({init_value, Key, Value}, _From, Tab) ->
@@ -72,8 +68,6 @@
     io:format("~p~n", [ets:match(Tab, '$1')]),
     {reply, ok, Tab}.
 
-
-
 lookup(Key, Fun, Default, Tab) ->
     Reply = case Fun(Tab, Key) of
         [{Key, Value}] ->
@@ -85,9 +79,17 @@
     end,
     {reply, Reply, Tab}.
 
-commit(Config) ->
-    couch_config_writer:save_config(Config, ?MODULE:lookup({"_CouchDB", "ConfigurationStorageFile"})),
-    ok.
+insert_and_commit(Tab, Config) ->
+    {reply, File, _Tab} = 
+        lookup({"_CouchDB", "ConfigurationStorageFile"}, 
+            fun(Tab_, Key_) -> ets:lookup(Tab_, Key_) end, 
+            null, Tab
+        ),
+    ets:insert(Tab, Config),
+    commit(Config, File).
+
+commit(Config, File) ->
+    couch_config_writer:save_config(Config, File).
 
 handle_cast(_Msg, State) -> {noreply, State}.
 handle_info(_Msg, State) -> {noreply, State}.
@@ -95,13 +97,12 @@
 code_change(_OldVersion, State, _Extra) -> {ok, State}.
 
 load_ini_files(IniFiles) ->
-    % load all ini files in the order they come in.
-    lists:foreach(fun(IniFile) -> load_ini_file(IniFile) end, IniFiles),
-    
     % store the name of the last ini file for storing changes made at runtime
     [LastIniFile|_] = lists:reverse(IniFiles),
-    couch_config:init_value({"_CouchDB", "ConfigurationStorageFile"}, LastIniFile).
+    couch_config:init_value({"_CouchDB", "ConfigurationStorageFile"}, LastIniFile),
 
+    % load all ini files in the order they come in.
+    lists:foreach(fun(IniFile) -> load_ini_file(IniFile) end, IniFiles).
 
 load_ini_file(IniFile) ->
     IniFilename = couch_util:abs_pathname(IniFile),

Added: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl?rev=662279&view=auto
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl (added)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_config_writer.erl Sun Jun 
1 13:17:42 2008
@@ -0,0 +1,105 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License.  You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couch_config_writer).
+-export([save_config/2]).
+
+save_config({{Module, Variable}, Value}, File) ->
+    % open file and create a list of lines
+    {ok, Stream} = file:read_file(File),
+    {ok, Lines} = regexp:split(binary_to_list(Stream), "\r\n|\n|\r|\032"),
+    
+    % prepare input variables
+    ModuleName = "[" ++ atom_to_list(Module) ++ "]",
+    VariableList = atom_to_list(Variable),
+    
+    % produce the contents for the config file
+    NewFileContents = save_loop({{ModuleName, VariableList}, Value}, Lines, "", "", []),
+    
+    % do the save, close the config file and get out
+    save_file(File, NewFileContents),
+    file:close(Stream),
+    ok.
+    
+save_loop({{Module, Variable}, Value}, [Line|Rest], OldCurrentModule, Contents, DoneVariables)
->
+
+    % if we find a new [ini section] (Module), save that for reference
+    NewCurrentModule = parse_module(Line, OldCurrentModule),
+
+    % if the current Module is the one we want to change, try to match
+    % each line with the Variable
+    NewContents = case Module of
+        NewCurrentModule ->
+            % see if the current line matches the variable we want to substitute
+            case parse_variable(Line, Variable, Value) of
+                % nope, return original line
+                nomatch ->
+                    DoneVariables2 = DoneVariables,
+                    Line;
+                % got em! return new line
+                NewLine ->
+                    DoneVariables2 = [Variable|DoneVariables],
+                    NewLine
+            end;
+        % if the variable we want to change couldn't be replaced, we append it
+        % in the proper module section
+        OldCurrentModule ->
+            case lists:member(Variable, DoneVariables) of
+                false ->
+                    DoneVariables2 = [Variable|DoneVariables],
+                    Variable ++ "=" ++ Value ++ "\n" ++ Line;
+                true ->
+                    DoneVariables2 = DoneVariables,
+                    Line
+            end;
+        % otherwise we just print out the original line
+        _ ->
+            DoneVariables2 = DoneVariables,
+            Line
+        end,
+    % clumsy way to only append a newline character
+    % if the line is not empty. We need this to not
+    % avoid haveing a newline inserted at the top
+    % of the target file each time we save it.
+    Contents2 = case Contents of "" -> ""; _ -> Contents ++ "\n" end,
+
+    % go to next line
+    save_loop({{Module, Variable}, Value}, Rest, NewCurrentModule, Contents2 ++ NewContents,
DoneVariables2);
+    
+save_loop(_Config, [], _OldModule, NewFileContents, _DoneVariable) ->
+    % we're out of new lines, just return the new file's contents
+    NewFileContents.
+        
+parse_module(Line, OldModule) ->
+    case regexp:match(Line, "^\\[([a-zA-Z0-9_-]*)\\]$") of
+        nomatch ->
+            OldModule;
+        {error, Error} ->
+            io:format("ini file regex error module: '~s'~n", [Error]),
+            OldModule;
+        {match, Start, Length} ->
+            string:substr(Line, Start, Length)
+    end.
+
+parse_variable(Line, Variable, Value) ->
+    case regexp:match(Line, "^" ++ Variable ++ "=") of
+        nomatch ->
+            nomatch;
+        {error, Error}->
+            io:format("ini file regex error variable: '~s'~n", [Error]),
+            nomatch;
+        {match, _Start, _Length} ->
+            Variable ++ "=" ++ Value
+    end.
+
+save_file(File, Contents) ->
+    file:write_file(File, list_to_binary(Contents)).
\ No newline at end of file

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_httpd.erl Sun Jun  1 13:17:42
2008
@@ -106,6 +106,8 @@
             {ok, Req:respond({301, [{"Location", "/_utils/"}], <<>>})};
         "/_utils/" ++ PathInfo ->
             {ok, Req:serve_file(PathInfo, DocumentRoot)};
+        "/_config/" ++ Config ->
+            handle_config_request(Req, Method, {config, Config});
         "/_" ++ _Path ->
             throw({not_found, unknown_private_path});
         "/favicon.ico" ->

Modified: incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl?rev=662279&r1=662278&r2=662279&view=diff
==============================================================================
--- incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl (original)
+++ incubator/couchdb/branches/runtimeconfig/src/couchdb/couch_server_sup.erl Sun Jun  1 13:17:42
2008
@@ -118,6 +118,8 @@
     StartResult = (catch supervisor:start_link(
         {local, couch_server_sup}, couch_server_sup, ChildProcesses)),
 
+    io:format("start result: '~p'", [StartResult]),
+
     case StartResult of
     {ok,_} ->
         % only output when startup was successful



Mime
View raw message