Alon Bar-Lev has uploaded a new change for review. Change subject: core: remove getDefault(), getKey() functions ......................................................................
core: remove getDefault(), getKey() functions Change-Id: I213dc604b756f11dacfa006118ac44382a5458b9 Signed-off-by: Alon Bar-Lev <[email protected]> --- M src/otopi/__main__.py M src/otopi/context.py M src/otopi/main.py M src/otopi/util.py M src/plugins/otopi/core/config.py M src/plugins/otopi/core/log.py 6 files changed, 27 insertions(+), 71 deletions(-) git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/93/10693/1 diff --git a/src/otopi/__main__.py b/src/otopi/__main__.py index e8a94e5..cef86d2 100644 --- a/src/otopi/__main__.py +++ b/src/otopi/__main__.py @@ -32,7 +32,6 @@ from otopi import constants from otopi import main from otopi import common -from otopi import util class Installer(object): @@ -64,10 +63,9 @@ def __init__(self): self._debug = int( - util.getKey( - dictionary=os.environ, - key=constants.SystemEnvironment.DEBUG, - default=0 + os.environ.get( + constants.SystemEnvironment.DEBUG, + 0 ) ) diff --git a/src/otopi/context.py b/src/otopi/context.py index b72c376..6552666 100644 --- a/src/otopi/context.py +++ b/src/otopi/context.py @@ -187,8 +187,7 @@ constants.BaseEnv.PLUGIN_PATH: config.otopiplugindir, constants.BaseEnv.PLUGIN_GROUPS: 'otopi', constants.BaseEnv.DEBUG: int( - util.getKey( - os.environ, + os.environ.get( constants.SystemEnvironment.DEBUG, '0' ) @@ -337,7 +336,7 @@ for key in sorted(self.environment.keys()): if ( old is None or - self.environment[key] != util.getKey(old, key, None) + self.environment[key] != old.get(key) ): self.logger.debug( "ENV %s=%s:'%s'", diff --git a/src/otopi/main.py b/src/otopi/main.py index 249dd0c..032907c 100644 --- a/src/otopi/main.py +++ b/src/otopi/main.py @@ -131,21 +131,18 @@ pass self._debug = int( - util.getKey( - dictionary=os.environ, - key=constants.SystemEnvironment.DEBUG, - default=0 + os.environ.get( + constants.SystemEnvironment.DEBUG, + 0 ) ) - self._bundledir = util.getKey( - dictionary=os.environ, - key='OTOPI_BUNDLED', - default='' + self._bundledir = os.environ.get( + 'OTOPI_BUNDLED', + '' ) - self._insource = '0' != util.getKey( - dictionary=os.environ, - key='OTOPI_INSOURCETREE', - default='0' + self._insource = '0' != os.environ.get( + 'OTOPI_INSOURCETREE', + '0' ) self._setupLogger() self._setupGettext() diff --git a/src/otopi/util.py b/src/otopi/util.py index d081aac..87881ea 100644 --- a/src/otopi/util.py +++ b/src/otopi/util.py @@ -84,39 +84,6 @@ @export -def getKey(dictionary, key, default): - """Get key out of dictionary with default value. - - Keyword arguments: - dictionary -- dictionary to process. - key -- key to query. - default -- value to return if key is missing. - - Why Python does not have this? - - """ - if key in dictionary: - return dictionary[key] - else: - return default - - -@export -def getDefault(value, default): - """Get default out of variable. - - Keyword arguments: - value -- value to evaluate. - default -- value to return if value is None. - - """ - if value is None: - return default - else: - return value - - -@export def raiseExceptionInformation(info): """Python-2/Python-3 raise exception based on exception information.""" if hasattr(info[1], 'with_traceback'): diff --git a/src/plugins/otopi/core/config.py b/src/plugins/otopi/core/config.py index e8cc834..1102eed 100644 --- a/src/plugins/otopi/core/config.py +++ b/src/plugins/otopi/core/config.py @@ -88,10 +88,9 @@ def _init(self): self.environment.setdefault( constants.CoreEnv.CONFIG_FILE_NAME, - util.getKey( - dictionary=os.environ, - key=constants.SystemEnvironment.CONFIG, - default=constants.Defaults.CONFIG_FILE, + os.environ.get( + constants.SystemEnvironment.CONFIG, + constants.Defaults.CONFIG_FILE, ) ) diff --git a/src/plugins/otopi/core/log.py b/src/plugins/otopi/core/log.py index 45a8081..f94ff23 100644 --- a/src/plugins/otopi/core/log.py +++ b/src/plugins/otopi/core/log.py @@ -102,24 +102,20 @@ # Allow system environment to override both # the log dir and the log file # - self.environment[constants.CoreEnv.LOG_DIR] = util.getKey( - dictionary=os.environ, - key=constants.SystemEnvironment.LOG_DIR, - default=util.getKey( - dictionary=self.environment, - key=constants.CoreEnv.LOG_DIR, - default=tempfile.gettempdir(), + self.environment[constants.CoreEnv.LOG_DIR] = os.environ.get( + constants.SystemEnvironment.LOG_DIR, + self.environment.get( + constants.CoreEnv.LOG_DIR, + tempfile.gettempdir(), ), ) logFileName = self.environment[ constants.CoreEnv.LOG_FILE_NAME - ] = util.getKey( - dictionary=os.environ, - key=constants.SystemEnvironment.LOG_FILE, - default=util.getKey( - dictionary=self.environment, - key=constants.CoreEnv.LOG_FILE_NAME, - default=os.path.join( + ] = os.environ.get( + constants.SystemEnvironment.LOG_FILE, + self.environment.get( + constants.CoreEnv.LOG_FILE_NAME, + os.path.join( self.environment[constants.CoreEnv.LOG_DIR], "%s-%s.log" % ( self.environment[ -- To view, visit http://gerrit.ovirt.org/10693 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I213dc604b756f11dacfa006118ac44382a5458b9 Gerrit-PatchSet: 1 Gerrit-Project: otopi Gerrit-Branch: master Gerrit-Owner: Alon Bar-Lev <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
