You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/01/30 13:26:31 UTC
incubator-ariatosca git commit: inroduced __mapiname__
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-44-Merge-parser-and-storage-models 7c232fdc1 -> 7195d84fa
inroduced __mapiname__
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/7195d84f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/7195d84f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/7195d84f
Branch: refs/heads/ARIA-44-Merge-parser-and-storage-models
Commit: 7195d84fa827fbcb2d6f4afacbc8b419338e48fb
Parents: 7c232fd
Author: mxmrlv <mx...@gmail.com>
Authored: Mon Jan 30 15:26:19 2017 +0200
Committer: mxmrlv <mx...@gmail.com>
Committed: Mon Jan 30 15:26:19 2017 +0200
----------------------------------------------------------------------
aria/storage/api.py | 6 ++----
aria/storage/core.py | 2 +-
aria/storage/instrumentation.py | 10 +++-------
aria/storage/modeling/elements.py | 4 ++--
aria/storage/modeling/orchestrator_elements.py | 2 +-
aria/storage/modeling/structure.py | 19 +++++++------------
aria/storage/modeling/utils.py | 8 ++++++++
7 files changed, 24 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/api.py
----------------------------------------------------------------------
diff --git a/aria/storage/api.py b/aria/storage/api.py
index d6fc3b8..9b5462b 100644
--- a/aria/storage/api.py
+++ b/aria/storage/api.py
@@ -44,7 +44,7 @@ class ModelAPI(StorageAPI):
"""
super(ModelAPI, self).__init__(**kwargs)
self._model_cls = model_cls
- self._name = name or generate_lower_name(model_cls)
+ self._name = model_cls.__modelname__
@property
def name(self):
@@ -177,6 +177,4 @@ def generate_lower_name(model_cls):
:return: lower name
:rtype: basestring
"""
- return ''.join(
- character if character.islower() else '_{0}'.format(character.lower())
- for character in model_cls.__name__)[1:]
+ return getattr(model_cls, '__mapiname__', model_cls.__tablename__)
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/core.py
----------------------------------------------------------------------
diff --git a/aria/storage/core.py b/aria/storage/core.py
index 94b4fe0..8d17f55 100644
--- a/aria/storage/core.py
+++ b/aria/storage/core.py
@@ -105,7 +105,7 @@ class ModelStorage(Storage):
:param model_cls: the model to register.
:return:
"""
- model_name = storage_api.generate_lower_name(model_cls)
+ model_name = model_cls.__modelname__
if model_name in self.registered:
self.logger.debug('{name} in already storage {self!r}'.format(name=model_name,
self=self))
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/instrumentation.py
----------------------------------------------------------------------
diff --git a/aria/storage/instrumentation.py b/aria/storage/instrumentation.py
index 7bcf35a..ea7fe78 100644
--- a/aria/storage/instrumentation.py
+++ b/aria/storage/instrumentation.py
@@ -75,7 +75,7 @@ class _Instrumentation(object):
def _register_set_attribute_listener(self, instrumented_attribute, attribute_type):
def listener(target, value, *_):
- mapi_name = self._mapi_name(target.__class__)
+ mapi_name = target.__modelname__
tracked_instances = self.tracked_changes.setdefault(mapi_name, {})
tracked_attributes = tracked_instances.setdefault(target.id, {})
if value is None:
@@ -90,7 +90,7 @@ class _Instrumentation(object):
def _register_instance_listeners(self, instrumented_class, instrumented_attributes):
def listener(target, *_):
- mapi_name = self._mapi_name(instrumented_class)
+ mapi_name = instrumented_class.__modelname__
tracked_instances = self.tracked_changes.setdefault(mapi_name, {})
tracked_attributes = tracked_instances.setdefault(target.id, {})
for attribute_name, attribute_type in instrumented_attributes.items():
@@ -110,7 +110,7 @@ class _Instrumentation(object):
def clear(self, target=None):
if target:
- mapi_name = self._mapi_name(target.__class__)
+ mapi_name = target.__modelname__
tracked_instances = self.tracked_changes.setdefault(mapi_name, {})
tracked_instances.pop(target.id, None)
else:
@@ -128,10 +128,6 @@ class _Instrumentation(object):
def __exit__(self, exc_type, exc_val, exc_tb):
self.restore()
- @staticmethod
- def _mapi_name(instrumented_class):
- return api.generate_lower_name(instrumented_class)
-
class _Value(object):
# You may wonder why is this a full blown class and not a named tuple. The reason is that
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/modeling/elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/elements.py b/aria/storage/modeling/elements.py
index 8c432f5..699a511 100644
--- a/aria/storage/modeling/elements.py
+++ b/aria/storage/modeling/elements.py
@@ -28,7 +28,7 @@ from . import type
# pylint: disable=no-self-argument, no-member, abstract-method
-class ParameterBase(structure.ModelElementBase, structure.ModelMixin):
+class ParameterBase(structure.ModelMixin):
"""
Represents a typed value.
@@ -74,7 +74,7 @@ class ParameterBase(structure.ModelElementBase, structure.ModelMixin):
self.value = utils.coerce_value(context, container, self.value, report_issues)
-class MetadataBase(structure.ModelElementBase, structure.ModelMixin):
+class MetadataBase(structure.ModelMixin):
"""
Custom values associated with the deployment template and its plans.
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/modeling/orchestrator_elements.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/orchestrator_elements.py b/aria/storage/modeling/orchestrator_elements.py
index ccd438d..f33b11c 100644
--- a/aria/storage/modeling/orchestrator_elements.py
+++ b/aria/storage/modeling/orchestrator_elements.py
@@ -328,7 +328,7 @@ class TaskBase(ModelMixin):
"""
A Model which represents an task
"""
- __tablename__ = 'tasks'
+ __tablename__ = 'task'
_private_fields = ['node_instance_fk', 'relationship_instance_fk', 'execution_fk']
@declared_attr
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/modeling/structure.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/structure.py b/aria/storage/modeling/structure.py
index ae562fb..3ea27f3 100644
--- a/aria/storage/modeling/structure.py
+++ b/aria/storage/modeling/structure.py
@@ -28,13 +28,13 @@ classes:
"""
from sqlalchemy.orm import relationship, backref
-from sqlalchemy.ext import associationproxy
+from sqlalchemy.ext import associationproxy, hybrid
from sqlalchemy import (
Column,
ForeignKey,
Integer,
Text,
- Table
+ Table,
)
from . import utils
@@ -93,8 +93,11 @@ class ModelElementBase(ElementBase):
raise NotImplementedError
-# TODO: models should inherit for model_element
-class ModelMixin(ElementBase):
+class ModelMixin(ModelElementBase):
+
+ @utils.classproperty
+ def __modelname__(cls):
+ return getattr(cls, '__mapiname__', cls.__tablename__)
@classmethod
def id_column_name(cls):
@@ -164,14 +167,6 @@ class ModelMixin(ElementBase):
**backref_kwargs or {}),
**relationship_kwargs)
-
-
- # @classmethod
- # def one_to_many_relationship(cls, child_table_name, backrefernce=None):
- # return relationship(lambda: cls._get_cls_by_tablename(child_table_name),
- # backref=backrefernce or '{0}s'.format(cls.__tablename__),
- # lazy='dynamic')
-
@classmethod
def relationship_to_self(cls, local_column):
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/7195d84f/aria/storage/modeling/utils.py
----------------------------------------------------------------------
diff --git a/aria/storage/modeling/utils.py b/aria/storage/modeling/utils.py
index b59959c..cee8289 100644
--- a/aria/storage/modeling/utils.py
+++ b/aria/storage/modeling/utils.py
@@ -129,3 +129,11 @@ def pluralize(noun):
return '{0}ies'.format(noun[:-1])
else:
return '{0}s'.format(noun)
+
+
+class classproperty(object):
+ def __init__(self, f):
+ self._f = f
+
+ def __get__(self, instance, owner):
+ return self._f(owner)