You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by cm...@apache.org on 2008/08/31 00:01:02 UTC

svn commit: r690595 - in /incubator/couchdb/trunk/src/couchdb: couch_config_writer.erl couch_httpd.erl

Author: cmlenz
Date: Sat Aug 30 15:01:01 2008
New Revision: 690595

URL: http://svn.apache.org/viewvc?rev=690595&view=rev
Log:
Rename 'module' to 'section', and 'variable' to 'option' in the config code.

Modified:
    incubator/couchdb/trunk/src/couchdb/couch_config_writer.erl
    incubator/couchdb/trunk/src/couchdb/couch_httpd.erl

Modified: incubator/couchdb/trunk/src/couchdb/couch_config_writer.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_config_writer.erl?rev=690595&r1=690594&r2=690595&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_config_writer.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_config_writer.erl Sat Aug 30 15:01:01 2008
@@ -10,11 +10,11 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
-%% @doc Saves a Key/Value pair to a ini file. The Key consists of a Module
-%%      and Variable combination. If that combination is found in the ini file
-%%      the new value replaces the old value. If only the Module is found the
-%%      Variable and value combination is appended to the Module. If the Module
-%%      does not yet exist in the ini file, it is added and the Variable/Value
+%% @doc Saves a Key/Value pair to a ini file. The Key consists of a Section
+%%      and Option combination. If that combination is found in the ini file
+%%      the new value replaces the old value. If only the Section is found the
+%%      Option and value combination is appended to the Section. If the Section
+%%      does not yet exist in the ini file, it is added and the Option/Value
 %%      pair is appended.
 %% @see couch_config
 
@@ -24,12 +24,12 @@
 -export([save_to_file/2]).
 
 %% @spec save_to_file(
-%%           Config::{{Module::string(), Variable::string()}, Value::string()},
+%%           Config::{{Section::string(), Option::string()}, Value::string()},
 %%           File::filename()) -> ok
-%% @doc Saves a Module/Key/Value triple to the ini file File::filename()
-save_to_file({{Module, Variable}, Value}, File) ->
+%% @doc Saves a Section/Key/Value triple to the ini file File::filename()
+save_to_file({{Section, Option}, Value}, File) ->
 
-    ?LOG_DEBUG("saving to file '~s', Config: '~p'", [File, {{Module, Variable}, Value}]),
+    ?LOG_DEBUG("saving to file '~s', Config: '~p'", [File, {{Section, Option}, Value}]),
 
     % open file and create a list of lines
     {ok, Stream} = file:read_file(File),
@@ -37,16 +37,16 @@
     {ok, Lines} = regexp:split(OldFileContents, "\r\n|\n|\r|\032"),
 
     % prepare input variables
-    ModuleName = "[" ++ Module ++ "]",
-    VariableList = Variable,
+    SectionName = "[" ++ Section ++ "]",
+    OptionList = Option,
 
     % produce the contents for the config file
     NewFileContents =
-    case NewFileContents2 = save_loop({{ModuleName, VariableList}, Value}, Lines, "", "", []) of
+    case NewFileContents2 = save_loop({{SectionName, OptionList}, Value}, Lines, "", "", []) of
         % we didn't change anything, that means we couldn't find a matching
         % [ini section] in which case we just append a new one.
         OldFileContents ->
-            append_new_ini_section({{ModuleName, VariableList}, Value}, OldFileContents);
+            append_new_ini_section({{SectionName, OptionList}, Value}, OldFileContents);
         _ ->
             NewFileContents2
     end,
@@ -58,40 +58,40 @@
 
 %% @doc Iterates over the lines of an ini file and replaces or adds a new
 %%      configuration directive.
-save_loop({{Module, Variable}, Value}, [Line|Rest], OldCurrentModule, Contents, DoneVariables) ->
+save_loop({{Section, Option}, Value}, [Line|Rest], OldCurrentSection, Contents, DoneOptions) ->
 
-    % if we find a new [ini section] (Module), save that for reference
-    NewCurrentModule = parse_module(Line, OldCurrentModule),
+    % if we find a new [ini section] (Section), save that for reference
+    NewCurrentSection = parse_module(Line, OldCurrentSection),
 
-    % if the current Module is the one we want to change, try to match
-    % each line with the Variable
-    NewContents = case Module of
-        NewCurrentModule ->
+    % if the current Section is the one we want to change, try to match
+    % each line with the Option
+    NewContents = case Section of
+        NewCurrentSection ->
             % see if the current line matches the variable we want to substitute
-            case parse_variable(Line, Variable, Value) of
+            case parse_variable(Line, Option, Value) of
                 % nope, return original line
                 nomatch ->
-                    DoneVariables2 = DoneVariables,
+                    DoneOptions2 = DoneOptions,
                     Line;
                 % got em! return new line
                 NewLine ->
-                    DoneVariables2 = [Variable|DoneVariables],
+                    DoneOptions2 = [Option|DoneOptions],
                     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
+        OldCurrentSection ->
+            case lists:member(Option, DoneOptions) of
                 false ->
-                    DoneVariables2 = [Variable|DoneVariables],
-                    Variable ++ " = " ++ Value ++ "\n" ++ Line;
+                    DoneOptions2 = [Option|DoneOptions],
+                    Option ++ " = " ++ Value ++ "\n" ++ Line;
                 true ->
-                    DoneVariables2 = DoneVariables,
+                    DoneOptions2 = DoneOptions,
                     Line
             end;
         % otherwise we just print out the original line
         _ ->
-            DoneVariables2 = DoneVariables,
+            DoneOptions2 = DoneOptions,
             Line
         end,
     % clumsy way to only append a newline character
@@ -101,43 +101,43 @@
     Contents2 = case Contents of "" -> ""; _ -> Contents ++ "\n" end,
 
     % go to next line
-    save_loop({{Module, Variable}, Value}, Rest, NewCurrentModule, Contents2 ++ NewContents, DoneVariables2);
+    save_loop({{Section, Option}, Value}, Rest, NewCurrentSection, Contents2 ++ NewContents, DoneOptions2);
 
-save_loop(_Config, [], _OldModule, NewFileContents, _DoneVariable) ->
+save_loop(_Config, [], _OldSection, NewFileContents, _DoneOption) ->
     % we're out of new lines, just return the new file's contents
     NewFileContents.
 
-append_new_ini_section({{ModuleName, Variable}, Value}, OldFileContents) ->
-    OldFileContents ++ "\n\n" ++ ModuleName ++ "\n" ++  Variable ++ " = " ++ Value ++ "\n".
+append_new_ini_section({{SectionName, Option}, Value}, OldFileContents) ->
+    OldFileContents ++ "\n\n" ++ SectionName ++ "\n" ++  Option ++ " = " ++ Value ++ "\n".
 
-%% @spec parse_module(Lins::string(), OldModule::string()) -> string()
+%% @spec parse_module(Lins::string(), OldSection::string()) -> string()
 %% @doc Tries to match a line against a pattern specifying a ini module or
-%%      section ("[Module]"). Returns OldModule if no match is found.
-parse_module(Line, OldModule) ->
+%%      section ("[Section]"). Returns OldSection if no match is found.
+parse_module(Line, OldSection) ->
     case regexp:match(Line, "^\\[([a-zA-Z0-9_-]*)\\]$") of
         nomatch ->
-            OldModule;
+            OldSection;
         {error, Error} ->
             io:format("ini file regex error module: '~s'~n", [Error]),
-            OldModule;
+            OldSection;
         {match, Start, Length} ->
             string:substr(Line, Start, Length)
     end.
 
-%% @spec parse_variable(Line::string(), Variable::string(), Value::string()) ->
+%% @spec parse_variable(Line::string(), Option::string(), Value::string()) ->
 %%         string() | nomatch
 %% @doc Tries to match a variable assignment in Line. Returns nomatch if the
-%%      Variable is not found. Returns a new line composed of the Variable and
+%%      Option is not found. Returns a new line composed of the Option and
 %%      Value otherwise.
-parse_variable(Line, Variable, Value) ->
-    case regexp:match(Line, "^" ++ Variable ++ "\s?=") of
+parse_variable(Line, Option, Value) ->
+    case regexp:match(Line, "^" ++ Option ++ "\s?=") of
         nomatch ->
             nomatch;
         {error, Error}->
             io:format("ini file regex error variable: '~s'~n", [Error]),
             nomatch;
         {match, _Start, _Length} ->
-            Variable ++ " = " ++ Value
+            Option ++ " = " ++ Value
     end.
 
 %% @spec save_file(File::filename(), Contents::string()) ->

Modified: incubator/couchdb/trunk/src/couchdb/couch_httpd.erl
URL: http://svn.apache.org/viewvc/incubator/couchdb/trunk/src/couchdb/couch_httpd.erl?rev=690595&r1=690594&r2=690595&view=diff
==============================================================================
--- incubator/couchdb/trunk/src/couchdb/couch_httpd.erl (original)
+++ incubator/couchdb/trunk/src/couchdb/couch_httpd.erl Sat Aug 30 15:01:01 2008
@@ -812,51 +812,51 @@
 % Config request handlers
 
 handle_config_request(_Req, Method, {config, Config}) ->
-    [Module, Key] = string:tokens(Config, "/"),
-    handle_config_request(_Req, Method, {[Module, Key]});
+    [Section, Option] = string:tokens(Config, "/"),
+    handle_config_request(_Req, Method, {[Section, Option]});
 
-% PUT /_config/Module/Key
+% PUT /_config/Section/Option
 % "value"
-handle_config_request(_Req, 'PUT', {[Module, Key]}) ->
-     handle_config_request(_Req, 'POST', {[Module, Key]});
+handle_config_request(_Req, 'PUT', {[Section, Option]}) ->
+     handle_config_request(_Req, 'POST', {[Section, Option]});
 
-% POST,PUT /_config/Module/Key
+% POST,PUT /_config/Section/Option
 % "value"
-handle_config_request(Req, 'POST', {[Module, Key]}) ->
+handle_config_request(Req, 'POST', {[Section, Option]}) ->
     Value = binary_to_list(Req:recv_body()),
-    ok = couch_config:store({Module, Key}, Value),
+    ok = couch_config:store({Section, Option}, Value),
     send_json(Req, 200, {obj, [
         {ok, true},
-        {module, Module},
-        {key, Key},
+        {section, Section},
+        {name, Option},
         {value, Value}
     ]});
 
-% GET /_config/Module/Key
-handle_config_request(Req, 'GET', {[Module, Key]}) ->
-    case couch_config:get({Module, Key},null) of
+% GET /_config/Section/Option
+handle_config_request(Req, 'GET', {[Section, Option]}) ->
+    case couch_config:get({Section, Option},null) of
     null ->
         throw({not_found, unknown_config_value});
     Value ->
         send_json(Req, 200, {obj, [
             {ok, true},
-            {module, Module},
-            {key, Key},
+            {section, Section},
+            {name, Option},
             {value, Value}
          ]})
     end;
 
-% DELETE /_config/Module/Key
-handle_config_request(Req, 'DELETE', {[Module, Key]}) ->
-    case couch_config:get({Module, Key}, null) of
+% DELETE /_config/Section/Option
+handle_config_request(Req, 'DELETE', {[Section, Option]}) ->
+    case couch_config:get({Section, Option}, null) of
     null ->
         throw({not_found, unknown_config_value});
     OldValue ->
-        couch_config:unset({Module, Key}),
+        couch_config:unset({Section, Option}),
         send_json(Req, 200, {obj, [
             {ok, true},
-            {module, Module},
-            {key, Key},
+            {section, Section},
+            {name, Option},
             {old_value, OldValue}
          ]})
     end.