Minor changes
Mostly minor changes to make code more compliant with
proper coding style, also some repetitions are removed.
diff --git a/reclass/__init__.py b/reclass/__init__.py
index 2167a30..d5f3410 100644
--- a/reclass/__init__.py
+++ b/reclass/__init__.py
@@ -19,7 +19,7 @@
storage_class = StorageBackendLoader(storage_type).load()
return MemcacheProxy(storage_class(nodes_uri, classes_uri, compose_node_name, **kwargs))
-def get_path_mangler(storage_type,**kwargs):
+def get_path_mangler(storage_type, **kwargs):
return StorageBackendLoader(storage_type).path_mangler()
def output(data, fmt, pretty_print=False, no_refs=False):
diff --git a/reclass/core.py b/reclass/core.py
index d07b232..e3142af 100644
--- a/reclass/core.py
+++ b/reclass/core.py
@@ -23,7 +23,6 @@
from six import iteritems
from reclass.settings import Settings
-from reclass.output.yaml_outputter import ExplicitDumper
from reclass.datatypes import Entity, Classes, Parameters, Exports
from reclass.errors import MappingFormatError, ClassNameResolveError, ClassNotFound, InvQueryClassNameResolveError, InvQueryClassNotFound, InvQueryError, InterpolationError, ResolveError
from reclass.values.parser import Parser
@@ -153,8 +152,16 @@
def _get_automatic_parameters(self, nodename, environment):
if self._settings.automatic_parameters:
- return Parameters({ '_reclass_': { 'name': { 'full': nodename, 'short': nodename.split('.')[0] },
- 'environment': environment } }, self._settings, '__auto__')
+ pars = {
+ '_reclass_': {
+ 'name': {
+ 'full': nodename,
+ 'short': nodename.split('.')[0]
+ },
+ 'environment': environment
+ }
+ }
+ return Parameters(pars, self._settings, '__auto__')
else:
return Parameters({}, self._settings, '')
@@ -163,13 +170,12 @@
for nodename in self._storage.enumerate_nodes():
try:
node_base = self._storage.get_node(nodename, self._settings)
- if node_base.environment == None:
+ if node_base.environment is None:
node_base.environment = self._settings.default_environment
except yaml.scanner.ScannerError as e:
if self._settings.inventory_ignore_failed_node:
continue
- else:
- raise
+ raise
if all_envs or node_base.environment == environment:
try:
@@ -221,7 +227,8 @@
raise
def _nodeinfo_as_dict(self, nodename, entity):
- ret = {'__reclass__' : {'node': entity.name, 'name': nodename,
+ ret = {'__reclass__' : {'node': entity.name,
+ 'name': nodename,
'uri': entity.uri,
'environment': entity.environment,
'timestamp': Core._get_timestamp()
diff --git a/reclass/datatypes/applications.py b/reclass/datatypes/applications.py
index 90ae54c..4f6ee10 100644
--- a/reclass/datatypes/applications.py
+++ b/reclass/datatypes/applications.py
@@ -28,18 +28,14 @@
def __init__(self, iterable=None,
negation_prefix=DEFAULT_NEGATION_PREFIX):
- self._negation_prefix = negation_prefix
+ self.negation_prefix = negation_prefix
self._offset = len(negation_prefix)
self._negations = []
super(Applications, self).__init__(iterable)
- @property
- def negation_prefix(self):
- return self._negation_prefix
-
def append_if_new(self, item):
self._assert_is_string(item)
- if item.startswith(self._negation_prefix):
+ if item.startswith(self.negation_prefix):
item = item[self._offset:]
self._negations.append(item)
try:
@@ -64,6 +60,6 @@
def __repr__(self):
contents = self._items + \
- ['%s%s' % (self._negation_prefix, i) for i in self._negations]
+ ['%s%s' % (self.negation_prefix, i) for i in self._negations]
return "%s(%r, %r)" % (self.__class__.__name__, contents,
- str(self._negation_prefix))
+ str(self.negation_prefix))
diff --git a/reclass/datatypes/classes.py b/reclass/datatypes/classes.py
index 5270e28..fa9cbcf 100644
--- a/reclass/datatypes/classes.py
+++ b/reclass/datatypes/classes.py
@@ -57,7 +57,7 @@
def _assert_is_string(self, item):
if not isinstance(item, six.string_types):
- raise TypeError('%s instances can only contain strings, '\
+ raise TypeError('%s instances can only contain strings, '
'not %s' % (self.__class__.__name__, type(item)))
def _assert_valid_characters(self, item):
diff --git a/reclass/datatypes/entity.py b/reclass/datatypes/entity.py
index 8133de5..2e0e1e4 100644
--- a/reclass/datatypes/entity.py
+++ b/reclass/datatypes/entity.py
@@ -35,7 +35,6 @@
self._environment = environment
name = property(lambda s: s._name)
- short_name = property(lambda s: s._short_name)
uri = property(lambda s: s._uri)
classes = property(lambda s: s._classes)
applications = property(lambda s: s._applications)
@@ -61,10 +60,10 @@
return received_value
def merge(self, other):
- self._classes.merge_unique(other._classes)
- self._applications.merge_unique(other._applications)
- self._parameters.merge(other._parameters)
- self._exports.merge(other._exports)
+ self._classes.merge_unique(other.classes)
+ self._applications.merge_unique(other.applications)
+ self._parameters.merge(other.parameters)
+ self._exports.merge(other.exports)
self._name = other.name
self._uri = other.uri
self._parameters._uri = other.uri
@@ -91,12 +90,12 @@
def __eq__(self, other):
return isinstance(other, type(self)) \
- and self._applications == other._applications \
- and self._classes == other._classes \
- and self._parameters == other._parameters \
- and self._exports == other._exports \
- and self._name == other._name \
- and self._uri == other._uri
+ and self._applications == other.applications \
+ and self._classes == other.classes \
+ and self._parameters == other.parameters \
+ and self._exports == other.exports \
+ and self._name == other.name \
+ and self._uri == other.uri
def __ne__(self, other):
return not self.__eq__(other)
diff --git a/reclass/datatypes/exports.py b/reclass/datatypes/exports.py
index 04ab200..984a15a 100644
--- a/reclass/datatypes/exports.py
+++ b/reclass/datatypes/exports.py
@@ -23,9 +23,6 @@
def __init__(self, mapping, settings, uri):
super(Exports, self).__init__(mapping, settings, uri)
- def __repr__(self):
- return '%s(%r)' % (self.__class__.__name__, self._base)
-
def delete_key(self, key):
self._base.pop(key, None)
self._unrendered.pop(key, None)
diff --git a/reclass/storage/loader.py b/reclass/storage/loader.py
index aab554a..0a66a66 100644
--- a/reclass/storage/loader.py
+++ b/reclass/storage/loader.py
@@ -32,5 +32,6 @@
def path_mangler(self, name='path_mangler'):
function = getattr(self._module, name, None)
if function is None:
- raise AttributeError('Storage backend class {0} does not export "{1}"'.format(self._name, name))
+ raise AttributeError('Storage backend class {0} does not export '
+ '"{1}"'.format(self._name, name))
return function
diff --git a/reclass/values/value.py b/reclass/values/value.py
index 736e01a..451617e 100644
--- a/reclass/values/value.py
+++ b/reclass/values/value.py
@@ -24,7 +24,7 @@
self._settings = settings
self.uri = uri
self.overwrite = False
- self._constant = False
+ self.constant = False
if isinstance(value, string_types):
if parse_string:
try:
@@ -41,14 +41,6 @@
else:
self._item = ScaItem(value, self._settings)
- @property
- def constant(self):
- return self._constant
-
- @constant.setter
- def constant(self, constant):
- self._constant = constant
-
def item_type(self):
return self._item.type
@@ -74,8 +66,7 @@
def needs_all_envs(self):
if self._item.has_inv_query:
return self._item.needs_all_envs
- else:
- return False
+ return False
def ignore_failed_render(self):
return self._item.ignore_failed_render