couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [13/29] git commit: load plugin config from priv/default.d/*.ini
Date Fri, 17 Jan 2014 23:09:47 GMT
load plugin config from priv/default.d/*.ini


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/commit/c3dfc415
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/tree/c3dfc415
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/diff/c3dfc415

Branch: refs/heads/import
Commit: c3dfc415a9dd62e2138a33324bd0f24390a9207b
Parents: 9b8fca9
Author: Bob Ippolito <bob@redivi.com>
Authored: Thu Aug 1 01:47:50 2013 -0700
Committer: Jan Lehnardt <jan@apache.org>
Committed: Thu Oct 3 16:08:35 2013 +0200

----------------------------------------------------------------------
 Makefile.am           |  1 +
 README.md             |  8 +++----
 src/couch_plugins.erl | 53 +++++++++++++++++-----------------------------
 3 files changed, 24 insertions(+), 38 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/blob/c3dfc415/Makefile.am
----------------------------------------------------------------------
diff --git a/Makefile.am b/Makefile.am
index 300f19c..91adfae 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -10,6 +10,7 @@
 ## License for the specific language governing permissions and limitations under
 ## the License.
 
+couch_pluginslibdir = $(localerlanglibdir)/couch_plugins-0.1
 couch_pluginsebindir = $(couch_pluginslibdir)/ebin
 
 couch_pluginsebin_DATA = $(compiled_files)

http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/blob/c3dfc415/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 09a0a71..8851794 100644
--- a/README.md
+++ b/README.md
@@ -131,10 +131,10 @@ to the Erlang code path
 (`code:add_path("/tmp/couchdb_plugins/geocouch-couchdb1.2.x_v0.3.0-12-g4ea0bea-R15B03/ebin")`)
 and loads the included application (`application:load(geocouch)`).
 
-Then it looks into the `./config` directory that lives next to `ebin/`
-in the plugin directory for a file `config.erlt` (“erl-terms”). with a
-list of configuration parameters to load. We parse the file and set
-the config directives one by one.
+Then it looks into the `./priv/default.d` directory that lives next to
+`ebin/` in the plugin directory for configuration `.ini` files and loads them.
+On next startup these configuration files are loaded after global defaults,
+and before any local configuration.
 
 If that all goes to plan, we report success back to the HTTP caller.
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-plugins/blob/c3dfc415/src/couch_plugins.erl
----------------------------------------------------------------------
diff --git a/src/couch_plugins.erl b/src/couch_plugins.erl
index daac885..a7680c3 100644
--- a/src/couch_plugins.erl
+++ b/src/couch_plugins.erl
@@ -18,7 +18,7 @@
 
 -define(PLUGIN_DIR, "/tmp/couchdb_plugins").
 
-log(T) -> 
+log(T) ->
   ?LOG_DEBUG("[couch_plugins] ~p ~n", [T]).
 
 %% "geocouch", "http://localhost:8000/dist", "1.0.0"
@@ -45,44 +45,30 @@ install({Name, _BaseUrl, Version, Checksums}=Plugin) ->
   log("loaded plugin"),
   ok.
 
--spec load_config(string(), string()) -> ok | {error, string()}.
+-spec load_config(string(), string()) -> ok.
 load_config(Name, Version) ->
-  ConfigFile = ?PLUGIN_DIR ++ "/" ++ get_file_slug(Name, Version) ++ "/priv/config.erlt",
-  load_config_file(file_exists(ConfigFile), ConfigFile).
-
--spec load_config_file(boolean(), string()) -> ok | {error, string()}.
-load_config_file(false, _) -> ok;
-load_config_file(true, ConfigFile) ->
-  % read file
-  {ok, ConfigFileData} = file:read_file(ConfigFile),
-  % split by \n
-  Lines = binary:split(ConfigFileData, <<"\n">>, [global]),
-  % feed each line...
-  lists:foreach(
-    fun(<<>>) ->
-      ok; % skip empty lines
-    (<<";", _Rest/binary>>) ->
-      ok; % ignore comments
-    (Line) ->
-    % ...to couch_util:parse_term()...
-    case couch_util:parse_term(Line) of
-      {ok, {{Section, Key}, Value}} ->
-        % ...and set the configs
-        ?LOG_DEBUG("parsed Line correctly: ~p", [Line]),
-        couch_config:set(Section, Key, Value);
-      Else ->
-        ?LOG_ERROR("Error parsing plugin config from line ~s", [Line]),
-        Else
-      end
-  end, Lines),
-  ok.
+    lists:foreach(
+      fun load_config_file/1,
+      filelib:wildcard(
+        filename:join(
+          [?PLUGIN_DIR, get_file_slug(Name, Version),
+           "priv", "default.d", "*.ini"]))).
+
+-spec load_config_file(string()) -> ok.
+load_config_file(File) ->
+    {ok, Config} = couch_config:parse_ini_file(File),
+    lists:foreach(fun set_config/1, Config).
+
+-spec set_config({{string(), string()}, string()}) -> ok.
+set_config({{Section, Key}, Value}) ->
+    ok = couch_config:set(Section, Key, Value, false).
 
 -spec add_code_path(string(), string()) -> ok | {error, bad_directory}.
 add_code_path(Name, Version) ->
   PluginPath = ?PLUGIN_DIR ++ "/" ++ get_file_slug(Name, Version) ++ "/ebin",
   case code:add_path(PluginPath) of
     true -> ok;
-    Else -> 
+    Else ->
       ?LOG_ERROR("Failed to add PluginPath: '~s'", [PluginPath]),
       Else
   end.
@@ -103,7 +89,7 @@ untargz(Filename) ->
   ok = filelib:ensure_dir(?PLUGIN_DIR),
   % untar
   erl_tar:extract({binary, TarData}, [{cwd, ?PLUGIN_DIR}, keep_old_files]).
-  
+
 
 % downloads a pluygin .tar.gz into a local plugins directory
 -spec download(string()) -> ok | {error, string()}.
@@ -256,4 +242,3 @@ does_file_exist(_Else) -> true.
 %  - in couch 1.x.x context
 %  - in bigcouch context
 %  - what is a server-user owned data/ dir we can use for this, that isn’t db_dir or index_dir
or log or var/run or /tmp
-


Mime
View raw message