[rygel] core,doc: Add option to override user config file
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] core,doc: Add option to override user config file
- Date: Fri, 1 Jul 2011 18:17:59 +0000 (UTC)
commit 0b187c9d4fc8f519d37252f2e886c6fe539d1f00
Author: Jens Georg <mail jensge org>
Date: Sun May 29 21:50:45 2011 +0200
core,doc: Add option to override user config file
doc/man/rygel.conf.xml | 3 +--
doc/man/rygel.xml | 9 +++++++++
src/rygel/rygel-cmdline-config.vala | 12 ++++++++++++
src/rygel/rygel-meta-config.vala | 17 +++++++++++++----
src/rygel/rygel-user-config.vala | 14 +++++++-------
5 files changed, 42 insertions(+), 13 deletions(-)
---
diff --git a/doc/man/rygel.conf.xml b/doc/man/rygel.conf.xml
index ca07db0..c76b88b 100644
--- a/doc/man/rygel.conf.xml
+++ b/doc/man/rygel.conf.xml
@@ -93,8 +93,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<refsect1 id="description">
<title>DESCRIPTION</title>
<para><command>&dhpackage;</command> reads its configuration values from
- the file <filename>$XDG_CONFIG_DIR/rygel.conf</filename> or - if that
- file does not exist - from the file
+ the file <filename>$XDG_CONFIG_DIR/rygel.conf</filename> or a file given on command line with the <userinput>--config</userinput> option. If that file does not exist it uses the file
<filename>/etc/rygel.conf</filename>.</para>
<para>Most of the options may be overriden by commandline arguments or
envronment variables. See <citerefentry>
diff --git a/doc/man/rygel.xml b/doc/man/rygel.xml
index 74a8062..12afd40 100644
--- a/doc/man/rygel.xml
+++ b/doc/man/rygel.xml
@@ -311,6 +311,15 @@ handling.</para>
<para>Disable advertisement via UPnP and set <application>&dhpackage;</application> into streaming-only mode.</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <option>-c</option>
+ <option>--config=<replaceable>CONFIG_FILE</replaceable></option>
+ </term>
+ <listitem>
+ <para>Use <replaceable>CONFIG_FILE</replaceable> instead of <filename>${XDG_CONFIG_DIR}/rygel.conf</filename>.</para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
<refsect1 id="files">
diff --git a/src/rygel/rygel-cmdline-config.vala b/src/rygel/rygel-cmdline-config.vala
index 20ab6c1..64fab87 100644
--- a/src/rygel/rygel-cmdline-config.vala
+++ b/src/rygel/rygel-cmdline-config.vala
@@ -51,6 +51,8 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
private static bool version;
+ private static string config_file;
+
[CCode (array_length = false, array_null_terminated = true)]
[NoArrayLength]
private static string[] disabled_plugins;
@@ -105,6 +107,8 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
"Set plugin options", "PluginName:OPTION:VALUE1[,VALUE2,..]" },
{ "disable-upnp", 'P', 0, OptionArg.NONE, ref no_upnp,
"Disable UPnP (streaming-only)", null },
+ { "config", 'c', 0, OptionArg.FILENAME, ref config_file,
+ "Use configuration file instead of user configuration", null },
{ null }
};
@@ -272,6 +276,14 @@ internal class Rygel.CmdlineConfig : GLib.Object, Configuration {
}
}
+ public string get_config_file () throws GLib.Error {
+ if (config_file == null) {
+ throw new ConfigurationError.NO_VALUE_SET (_("No value available"));
+ }
+
+ return config_file;
+ }
+
// Dynamic options
// FIXME: How to handle them?
public string get_string (string section,
diff --git a/src/rygel/rygel-meta-config.vala b/src/rygel/rygel-meta-config.vala
index ead0400..ac6c828 100644
--- a/src/rygel/rygel-meta-config.vala
+++ b/src/rygel/rygel-meta-config.vala
@@ -48,13 +48,22 @@ public class Rygel.MetaConfig : GLib.Object, Configuration {
public MetaConfig () {
this.configs = new ArrayList<Configuration> ();
- this.configs.add (CmdlineConfig.get_default ());
+ var cmdline_config = CmdlineConfig.get_default ();
+
+ this.configs.add (cmdline_config);
this.configs.add (EnvironmentConfig.get_default ());
+
try {
- var user_config = UserConfig.get_default ();
+ var config_file = cmdline_config.get_config_file ();
+ var user_config = new UserConfig (config_file);
this.configs.add (user_config);
- } catch (Error err) {
- warning (_("Failed to load user configuration: %s"), err.message);
+ } catch (Error error) {
+ try {
+ var user_config = UserConfig.get_default ();
+ this.configs.add (user_config);
+ } catch (Error err) {
+ warning (_("Failed to load user configuration: %s"), err.message);
+ }
}
}
diff --git a/src/rygel/rygel-user-config.vala b/src/rygel/rygel-user-config.vala
index f28d19b..9e04850 100644
--- a/src/rygel/rygel-user-config.vala
+++ b/src/rygel/rygel-user-config.vala
@@ -100,13 +100,16 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
public static UserConfig get_default () throws Error {
if (config == null) {
- config = new UserConfig ();
+ var path = Path.build_filename
+ (Environment.get_user_config_dir (),
+ CONFIG_FILE);
+ config = new UserConfig (path);
}
return config;
}
- public UserConfig () throws Error {
+ public UserConfig (string file) throws Error {
this.key_file = new KeyFile ();
this.sys_key_file = new KeyFile ();
@@ -119,14 +122,11 @@ public class Rygel.UserConfig : GLib.Object, Configuration {
debug ("Loaded system configuration from file '%s'", path);
try {
- path = Path.build_filename (Environment.get_user_config_dir (),
- CONFIG_FILE);
-
- this.key_file.load_from_file (path,
+ this.key_file.load_from_file (file,
KeyFileFlags.KEEP_COMMENTS |
KeyFileFlags.KEEP_TRANSLATIONS);
- debug ("Loaded user configuration from file '%s'", path);
+ debug ("Loaded user configuration from file '%s'", file);
} catch (Error error) {
debug ("Failed to load user configuration from file '%s': %s",
path,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]