[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9817 - trunk/gnue-common/src/apps
From: |
johannes |
Subject: |
[gnue] r9817 - trunk/gnue-common/src/apps |
Date: |
Wed, 21 Nov 2007 03:02:59 -0600 (CST) |
Author: johannes
Date: 2007-11-21 03:02:58 -0600 (Wed, 21 Nov 2007)
New Revision: 9817
Modified:
trunk/gnue-common/src/apps/GConfig.py
Log:
More work on PEP8 and pylint
Modified: trunk/gnue-common/src/apps/GConfig.py
===================================================================
--- trunk/gnue-common/src/apps/GConfig.py 2007-11-16 10:29:24 UTC (rev
9816)
+++ trunk/gnue-common/src/apps/GConfig.py 2007-11-21 09:02:58 UTC (rev
9817)
@@ -62,23 +62,28 @@
self._default_section = section
self._loadedConfigs = {}
- self.loadApplicationConfig(configFilename, homeConfigDir, section,
+ self.load_application_config(configFilename, homeConfigDir, section,
defaults)
# Add global gConfig function to application namespace
import __builtin__
+ # Deprecated versions
__builtin__.__dict__['gConfig'] = self.gConfig
- __builtin__.__dict__['gConfigDict'] = self.gConfigDict
+ __builtin__.__dict__['gConfigDict'] = self.gConfigDict
+ # New versions
+ __builtin__.__dict__['gconfig'] = self.gconfig
+ __builtin__.__dict__['gconfig_dict'] = self.gconfig_dict
# -------------------------------------------------------------------------
# Register an alias
# -------------------------------------------------------------------------
- def registerAlias(self, name, section):
+ def register_alias(self, name, section):
"""
Register an alias for retrieving options of a given section in the
configration file.
+
@param name: function name to use as a 'builtin' for retrieving options
of the given section
@type name: string
@@ -86,18 +91,29 @@
@type section: string
"""
- alias = GConfigAlias(self.gConfig, section)
+ alias = GConfigAlias(self.gconfig, section)
import __builtin__
- __builtin__.__dict__[name] = alias.gConfig
+ __builtin__.__dict__[name] = alias.gconfig
# -------------------------------------------------------------------------
+ # Register an alias
+ # -------------------------------------------------------------------------
+
+ def registerAlias(self, name, section):
+ """
+ This method is deprecated. Please use register_alias() instead
+ """
+ return self.register_alias(name, section)
+
+
+ # -------------------------------------------------------------------------
# Load the specified file
# -------------------------------------------------------------------------
- def loadApplicationConfig(self, configFilename="gnue.conf",
- homeConfigDir=".gnue", section="DEFAULT", defaults=None):
+ def load_application_config(self, config_filename="gnue.conf",
+ home_config_dir=".gnue", section="DEFAULT", defaults=None):
"""
Load the specified file only once. Subsequent calls setup the defaults
for any missing values.
@@ -107,16 +123,16 @@
"""
assert gDebug(2, 'Reading configuration info from %s section %s' %
- (configFilename, section))
+ (config_filename, section))
# Create parser and populate it if it doesn't exist
- if not self._loadedConfigs.has_key(configFilename):
+ if not self._loadedConfigs.has_key(config_filename):
if defaults is None:
parser = GConfigParser(GCConfig.ConfigOptions)
else:
parser = GConfigParser(defaults + GCConfig.ConfigOptions)
- self._loadedConfigs[configFilename] = parser
+ self._loadedConfigs[config_filename] = parser
# Build valid file list
@@ -125,19 +141,19 @@
# system config file
if etc_base:
- file_locations.append(os.path.join(etc_base, configFilename))
+ file_locations.append(os.path.join(etc_base, config_filename))
# user config file
try:
file_locations.append(os.path.join(os.environ['HOME'],
- homeConfigDir, configFilename))
+ home_config_dir, config_filename))
except KeyError:
pass
# system fixed config file
if etc_base:
file_locations.append(os.path.join(etc_base,
- configFilename + '.fixed'))
+ config_filename + '.fixed'))
# Load the values from the files specified
try:
@@ -160,21 +176,35 @@
sys.exc_value
# Common only needs checked once, load any [common] defaults
- self.__integrate_default_dict(configFilename, 'common',
- self.__build_defaults(GCConfig.ConfigOptions))
+ self.__integrate_default_dict(config_filename, 'common',
+ _build_defaults(GCConfig.ConfigOptions))
# Load anything set in the DEFAULT section
- self.__integrate_default_dict(configFilename, section,
- self._loadedConfigs[configFilename].defaults())
+ self.__integrate_default_dict(config_filename, section,
+ self._loadedConfigs[config_filename].defaults())
# If any values are still blank after loading from file's specific
# section and then the default section then load the defaults specified
# by the application itself.
- self.__integrate_default_dict(configFilename, section,
- self.__build_defaults(defaults))
+ self.__integrate_default_dict(config_filename, section,
+ _build_defaults(defaults))
# -------------------------------------------------------------------------
+ # Load the specified file
+ # -------------------------------------------------------------------------
+
+ def loadApplicationConfig(self, configFilename="gnue.conf",
+ homeConfigDir=".gnue", section="DEFAULT", defaults=None):
+ """
+ This method is deprecated. Please use load_application_config()
+ instead.
+ """
+ return self.load_application_config(configFilename, homeConfigDir,
+ section, defaults)
+
+
+ # -------------------------------------------------------------------------
# Integrate default values from a dictionary into a configuration section
# -------------------------------------------------------------------------
@@ -197,33 +227,19 @@
# -------------------------------------------------------------------------
- # Create a dictionary of default values from a definition dictionary
- # -------------------------------------------------------------------------
-
- def __build_defaults(self, definitions):
-
- defaults = {}
- if definitions:
- for item in definitions:
- defaults[item['Name'].lower()] = str(item['Default'])
-
- return defaults
-
-
- # -------------------------------------------------------------------------
# Retrieve an option value from a configuration files' section
# -------------------------------------------------------------------------
- def gConfig(self, var_name, configFilename=None, section=None):
+ def gconfig(self, var_name, config_filename=None, section=None):
"""
Retrieve an option from a section in a configuration file
@param var_name: name of the option to retrieve
@type var_name: string
- @param configFilename: name of the configuration file to retrieve the
+ @param config_filename: name of the configuration file to retrieve the
option from. If None, the default configuration file will be used.
- @type configFilename: string
+ @type config_filename: string
@param section: name of the section to retrieve the option from. If
None, the default section will be used.
@@ -231,12 +247,12 @@
@returns: the retrieve option value
"""
- if not configFilename:
- configFilename = self._default_config_filename
+ if not config_filename:
+ config_filename = self._default_config_filename
if not section:
section = self._default_section
- cfg_parser = self._loadedConfigs[configFilename]
+ cfg_parser = self._loadedConfigs[config_filename]
try:
return cfg_parser.get(section, var_name)
@@ -256,18 +272,29 @@
# -------------------------------------------------------------------------
+ # Retrieve an option value from a configuration files' section
+ # -------------------------------------------------------------------------
+
+ def gConfig(self, var_name, configFilename=None, section=None):
+ """
+ This method is deprecated. Please use gconfig() instead.
+ """
+ return self.gconfig(var_name, configFilename, section)
+
+
+ # -------------------------------------------------------------------------
# Get a dictionary with all configuration options in a section
# -------------------------------------------------------------------------
- def gConfigDict(self, configFilename=None, section=None):
+ def gconfig_dict(self, config_filename=None, section=None):
"""
Build a dictionary containing all configuration options of a given
section within a given configuration file.
- @param configFilename: name of the configuration file to retrieve the
+ @param config_filename: name of the configuration file to retrieve the
options from. If None, the default configuration file will be
used.
- @type configFilename: string
+ @type config_filename: string
@param section: name of the section to retrieve the options from. If
None, the default section will be used.
@@ -275,12 +302,12 @@
@rtype: dict
"""
- if not configFilename:
- configFilename = self._default_config_filename
+ if not config_filename:
+ config_filename = self._default_config_filename
if not section:
section = self._default_section
- cfg_parser = self._loadedConfigs[configFilename]
+ cfg_parser = self._loadedConfigs[config_filename]
result = {}
if cfg_parser.has_section(section):
@@ -290,7 +317,18 @@
return result
+ # -------------------------------------------------------------------------
+ # Get a dictionary with all configuration options in a section
+ # -------------------------------------------------------------------------
+ def gConfigDict(self, configFilename=None, section=None):
+ """
+ This method is deprecated. Please use gconfig_dict() instead.
+ """
+
+ return self.gconfig_dict(configFilename, section)
+
+
# =============================================================================
# GNUe Config Parser class supporting the GTypecast system
# =============================================================================
@@ -374,24 +412,24 @@
@type name: string
"""
- self._gConfig = gconfig
- self._section = name
+ self.__gconfig = gconfig
+ self.__section = name
# -------------------------------------------------------------------------
# Retrieve an option value
# -------------------------------------------------------------------------
- def gConfig(self, var_name, configFilename=None, section=None):
+ def gconfig(self, var_name, config_filename=None, section=None):
"""
Retrieve an option from a section in a configuration file
@param var_name: name of the option to retrieve
@type var_name: string
- @param configFilename: name of the configuration file to retrieve the
+ @param config_filename: name of the configuration file to retrieve the
option from. If None, the default configuration file will be used.
- @type configFilename: string
+ @type config_filename: string
@param section: name of the section to retrieve the option from. If
None, the default section will be used.
@@ -400,17 +438,27 @@
"""
if not section:
- section = self._section
+ section = self.__section
- return self._gConfig(var_name, configFilename=configFilename,
- section=section)
+ return self.__gconfig(var_name, config_filename, section)
+ # -------------------------------------------------------------------------
+ # Retrieve an option value
+ # -------------------------------------------------------------------------
+
+ def gConfig(self, var_name, configFilename=None, section=None):
+ """
+ This method is deprecated. Please use gconfig() instead.
+ """
+ return self.gconfig(var_name, configFilename, section)
+
+
# -----------------------------------------------------------------------------
# get the install location of a given group
# -----------------------------------------------------------------------------
-def getInstalledBase(*parameters):
+def get_installed_base(*parameters):
"""
Returns the first matching item of the arguments in the _site_config
dictionary.
@@ -423,6 +471,17 @@
# -----------------------------------------------------------------------------
+# get the install location of a given group
+# -----------------------------------------------------------------------------
+
+def getInstalledBase(*parameters):
+ """
+ This method is deprecated. Please use get_installed_base() instead.
+ """
+ return get_installed_base(*parameters)
+
+
+# -----------------------------------------------------------------------------
# Create a printable description of configuration options
# -----------------------------------------------------------------------------
@@ -463,6 +522,27 @@
return output
+# -------------------------------------------------------------------------
+# Create a dictionary of default values from a definition dictionary
+# -------------------------------------------------------------------------
+
+def _build_defaults(definitions):
+ """
+ Create a dictionary of default values for all configuration option listed
+ in the given definitions dictionary.
+
+ @param definitions: dictionary of configuration options
+ @returns: dictionary with default values where the option name is the key
+ and it's default the value
+ """
+ defaults = {}
+ if definitions:
+ for item in definitions:
+ defaults[item['Name'].lower()] = str(item['Default'])
+
+ return defaults
+
+
# =============================================================================
# Site configuration
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9817 - trunk/gnue-common/src/apps,
johannes <=