diff options
author | Gordon Chung <chungg@ca.ibm.com> | 2013-12-07 16:46:32 -0500 |
---|---|---|
committer | Gordon Chung <chungg@ca.ibm.com> | 2013-12-16 09:56:46 -0500 |
commit | e4fa4b5248a594f8cc0839b06b77c4828bea2cd1 (patch) | |
tree | 0e1544cb85febcd18c5630f95c228f212ec2ac49 /pycadf | |
parent | 52b891fc87c48027d10ac4a760ede98ecbe75441 (diff) | |
download | pycadf-e4fa4b5248a594f8cc0839b06b77c4828bea2cd1.tar.gz |
sync requirements and oslo
- update common code
- update requirements
Change-Id: I1912dad4e61da7c14c5e3d9a38076829b09afe87
Diffstat (limited to 'pycadf')
-rw-r--r-- | pycadf/openstack/common/config/generator.py | 26 | ||||
-rw-r--r-- | pycadf/openstack/common/gettextutils.py | 6 | ||||
-rw-r--r-- | pycadf/openstack/common/importutils.py | 2 | ||||
-rw-r--r-- | pycadf/openstack/common/jsonutils.py | 14 | ||||
-rw-r--r-- | pycadf/openstack/common/timeutils.py | 15 |
5 files changed, 34 insertions, 29 deletions
diff --git a/pycadf/openstack/common/config/generator.py b/pycadf/openstack/common/config/generator.py index 83fc666..4834cc3 100644 --- a/pycadf/openstack/common/config/generator.py +++ b/pycadf/openstack/common/config/generator.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 SINA Corporation # All Rights Reserved. # @@ -28,6 +26,7 @@ import sys import textwrap from oslo.config import cfg +import six from pycadf.openstack.common import gettextutils from pycadf.openstack.common import importutils @@ -78,12 +77,15 @@ def generate(srcfiles): # The options list is a list of (module, options) tuples opts_by_group = {'DEFAULT': []} - for module_name in os.getenv( - "OSLO_CONFIG_GENERATOR_EXTRA_MODULES", "").split(','): - module = _import_module(module_name) - if module: - for group, opts in _list_opts(module): - opts_by_group.setdefault(group, []).append((module_name, opts)) + extra_modules = os.getenv("PYCADF_CONFIG_GENERATOR_EXTRA_MODULES", "") + if extra_modules: + for module_name in extra_modules.split(','): + module_name = module_name.strip() + module = _import_module(module_name) + if module: + for group, opts in _list_opts(module): + opts_by_group.setdefault(group, []).append((module_name, + opts)) for pkg_name in pkg_names: mods = mods_by_pkg.get(pkg_name) @@ -111,10 +113,8 @@ def _import_module(mod_str): return sys.modules[mod_str[4:]] else: return importutils.import_module(mod_str) - except ImportError as ie: - sys.stderr.write("%s\n" % str(ie)) - return None - except Exception: + except Exception as e: + sys.stderr.write("Error importing module %s: %s\n" % (mod_str, str(e))) return None @@ -233,7 +233,7 @@ def _print_opt(opt): if opt_default is None: print('#%s=<None>' % opt_name) elif opt_type == STROPT: - assert(isinstance(opt_default, basestring)) + assert(isinstance(opt_default, six.string_types)) print('#%s=%s' % (opt_name, _sanitize_default(opt_name, opt_default))) elif opt_type == BOOLOPT: diff --git a/pycadf/openstack/common/gettextutils.py b/pycadf/openstack/common/gettextutils.py index f964fc0..7f3cd21 100644 --- a/pycadf/openstack/common/gettextutils.py +++ b/pycadf/openstack/common/gettextutils.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2012 Red Hat, Inc. # Copyright 2013 IBM Corp. # All Rights Reserved. @@ -21,7 +19,7 @@ gettext for openstack-common modules. Usual usage in an openstack.common module: - from pycadf.openstack.common.gettextutils import _ + from pycadf.openstack.common.gettextutils import _ # noqa """ import copy @@ -317,7 +315,7 @@ def get_available_languages(domain): # NOTE(luisg): Babel <1.0 used a function called list(), which was # renamed to locale_identifiers() in >=1.0, the requirements master list # requires >=0.9.6, uncapped, so defensively work with both. We can remove - # this check when the master list updates to >=1.0, and all projects udpate + # this check when the master list updates to >=1.0, and update all projects list_identifiers = (getattr(localedata, 'list', None) or getattr(localedata, 'locale_identifiers')) locale_identifiers = list_identifiers() diff --git a/pycadf/openstack/common/importutils.py b/pycadf/openstack/common/importutils.py index 7a303f9..4fd9ae2 100644 --- a/pycadf/openstack/common/importutils.py +++ b/pycadf/openstack/common/importutils.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2011 OpenStack Foundation. # All Rights Reserved. # diff --git a/pycadf/openstack/common/jsonutils.py b/pycadf/openstack/common/jsonutils.py index 8ac4efe..72b928e 100644 --- a/pycadf/openstack/common/jsonutils.py +++ b/pycadf/openstack/common/jsonutils.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2010 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # Copyright 2011 Justin Santa Barbara @@ -41,8 +39,12 @@ import json try: import xmlrpclib except ImportError: - # NOTE(jd): xmlrpclib is not shipped with Python 3 - xmlrpclib = None + # NOTE(jaypipes): xmlrpclib was renamed to xmlrpc.client in Python3 + # however the function and object call signatures + # remained the same. This whole try/except block should + # be removed and replaced with a call to six.moves once + # six 1.4.2 is released. See http://bit.ly/1bqrVzu + import xmlrpc.client as xmlrpclib import six @@ -124,14 +126,14 @@ def to_primitive(value, convert_instances=False, convert_datetime=True, level=level, max_depth=max_depth) if isinstance(value, dict): - return dict((k, recursive(v)) for k, v in value.iteritems()) + return dict((k, recursive(v)) for k, v in six.iteritems(value)) elif isinstance(value, (list, tuple)): return [recursive(lv) for lv in value] # It's not clear why xmlrpclib created their own DateTime type, but # for our purposes, make it a datetime type which is explicitly # handled - if xmlrpclib and isinstance(value, xmlrpclib.DateTime): + if isinstance(value, xmlrpclib.DateTime): value = datetime.datetime(*tuple(value.timetuple())[:6]) if convert_datetime and isinstance(value, datetime.datetime): diff --git a/pycadf/openstack/common/timeutils.py b/pycadf/openstack/common/timeutils.py index 98d877d..c8b0b15 100644 --- a/pycadf/openstack/common/timeutils.py +++ b/pycadf/openstack/common/timeutils.py @@ -1,5 +1,3 @@ -# vim: tabstop=4 shiftwidth=4 softtabstop=4 - # Copyright 2011 OpenStack Foundation. # All Rights Reserved. # @@ -50,9 +48,9 @@ def parse_isotime(timestr): try: return iso8601.parse_date(timestr) except iso8601.ParseError as e: - raise ValueError(unicode(e)) + raise ValueError(six.text_type(e)) except TypeError as e: - raise ValueError(unicode(e)) + raise ValueError(six.text_type(e)) def strtime(at=None, fmt=PERFECT_TIME_FORMAT): @@ -178,6 +176,15 @@ def delta_seconds(before, after): datetime objects (as a float, to microsecond resolution). """ delta = after - before + return total_seconds(delta) + + +def total_seconds(delta): + """Return the total seconds of datetime.timedelta object. + + Compute total seconds of datetime.timedelta, datetime.timedelta + doesn't have method total_seconds in Python2.6, calculate it manually. + """ try: return delta.total_seconds() except AttributeError: |