pylint-aria-storage

Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/03b2a22b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/03b2a22b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/03b2a22b

Branch: refs/heads/pylint-aria-storage
Commit: 03b2a22b5289a02574c9dfc093e162f558392c0c
Parents: 177a3f6
Author: mxmrlv <[email protected]>
Authored: Wed Oct 19 17:07:45 2016 +0300
Committer: mxmrlv <[email protected]>
Committed: Wed Oct 19 18:11:09 2016 +0300

----------------------------------------------------------------------
 .pylintrc                  |  1 -
 aria/storage/__init__.py   | 25 ++++++++++++++--
 aria/storage/drivers.py    | 11 +++++--
 aria/storage/models.py     | 64 +++++++++++++++++++++++++++++++++++++----
 aria/storage/structures.py | 20 +++++++++++++
 5 files changed, 109 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03b2a22b/.pylintrc
----------------------------------------------------------------------
diff --git a/.pylintrc b/.pylintrc
index 7f4f203..4e24f8e 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -404,5 +404,4 @@ overgeneral-exceptions=Exception
 
 
 [pre-commit-hook]
-params=--reports=no
 limit=9.5

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03b2a22b/aria/storage/__init__.py
----------------------------------------------------------------------
diff --git a/aria/storage/__init__.py b/aria/storage/__init__.py
index 3f9aefa..028bcdc 100644
--- a/aria/storage/__init__.py
+++ b/aria/storage/__init__.py
@@ -72,6 +72,9 @@ __all__ = (
 
 
 class ModelStorage(Storage):
+    """
+    Managing the models storage.
+    """
     def __init__(self, driver, models=(), **kwargs):
         """
         Simple storage client api for Aria applications.
@@ -99,12 +102,16 @@ class ModelStorage(Storage):
         return super(ModelStorage, self).__getattr__(table)
 
     def register(self, model_cls):
-        # todo: add documentation
+        """
+        Registers the model type in the resource storage manager.
+        :param model_cls: the model to register.
+        :return:
+        """
         model_name = generate_lower_name(model_cls)
         model_api = _ModelApi(model_name, self.driver, model_cls)
         self.registered[model_name] = model_api
 
-        for pointer, pointer_schema_register in 
model_api.pointer_mapping.items():
+        for pointer_schema_register in model_api.pointer_mapping.values():
             model_cls = pointer_schema_register.model_cls
             self.register(model_cls)
 
@@ -256,6 +263,12 @@ class _ModelApi(object):
 
 
 class ResourceApi(object):
+    """
+    Managing the resource in the storage, using the driver.
+
+    :param basestring name: the name of the resource.
+    :param ResourceDriver driver: the driver which supports this resource in 
the storage.
+    """
     def __init__(self, driver, resource_name):
         """
         Managing the resources in the storage, using the driver.
@@ -341,6 +354,9 @@ def generate_lower_name(model_cls):
 
 
 class ResourceStorage(Storage):
+    """
+    Managing the resource storage.
+    """
     def __init__(self, driver, resources=(), **kwargs):
         """
         Simple storage client api for Aria applications.
@@ -353,6 +369,11 @@ class ResourceStorage(Storage):
         super(ResourceStorage, self).__init__(driver, resources, **kwargs)
 
     def register(self, resource):
+        """
+        Registers the resource type in the resource storage manager.
+        :param resource: the resource to register.
+        :return:
+        """
         self.registered[resource] = ResourceApi(self.driver, 
resource_name=resource)
 
     def __getattr__(self, resource):

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03b2a22b/aria/storage/drivers.py
----------------------------------------------------------------------
diff --git a/aria/storage/drivers.py b/aria/storage/drivers.py
index 17a99a1..1a198d3 100644
--- a/aria/storage/drivers.py
+++ b/aria/storage/drivers.py
@@ -29,7 +29,8 @@ classes:
 
 import os
 import shutil
-import distutils.dir_util
+# pylint has an issue with distuls and virtualenvs: 
https://github.com/PyCQA/pylint/issues/73
+import distutils.dir_util                                                      
                     # pylint: disable=no-name-in-module, import-error
 from functools import partial
 from multiprocessing import RLock
 
@@ -216,6 +217,9 @@ class ResourceDriver(Driver):
 
 
 class BaseFileSystemDriver(Driver):
+    """
+    Base class which handles storage on the file system.
+    """
     def __init__(self, *args, **kwargs):
         super(BaseFileSystemDriver, self).__init__(*args, **kwargs)
         self._lock = RLock()
@@ -324,6 +328,7 @@ class FileSystemModelDriver(ModelDriver, 
BaseFileSystemDriver):
         entry_dict.update(**kwargs)
         self.store(name, entry_id, entry_dict)
 
+
 class FileSystemResourceDriver(ResourceDriver, BaseFileSystemDriver):
     """
     FileSystemResourceDriver context manager.
@@ -386,7 +391,7 @@ class FileSystemResourceDriver(ResourceDriver, 
BaseFileSystemDriver):
         if os.path.isfile(resource):
             shutil.copy2(resource, destination)
         else:
-            distutils.dir_util.copy_tree(resource, destination)
+            distutils.dir_util.copy_tree(resource, destination)                
                     # pylint: disable=no-member
 
     def upload(self, entry_type, entry_id, source, path=None):
         """
@@ -404,4 +409,4 @@ class FileSystemResourceDriver(ResourceDriver, 
BaseFileSystemDriver):
         if os.path.isfile(source):
             shutil.copy2(source, destination)
         else:
-            distutils.dir_util.copy_tree(source, destination)
+            distutils.dir_util.copy_tree(source, destination)                  
                     # pylint: disable=no-member

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03b2a22b/aria/storage/models.py
----------------------------------------------------------------------
diff --git a/aria/storage/models.py b/aria/storage/models.py
index d96c74a..1601324 100644
--- a/aria/storage/models.py
+++ b/aria/storage/models.py
@@ -65,6 +65,9 @@ ENTITY_TYPES = ()
 
 
 class Blueprint(Model):
+    """
+    A Model which represents a blueprint
+    """
     plan = Field(type=dict)
     id = Field(type=basestring, default=uuid_generator)
     description = Field(type=(basestring, NoneType))
@@ -74,6 +77,9 @@ class Blueprint(Model):
 
 
 class Snapshot(Model):
+    """
+    A Model which represents a snapshot
+    """
     CREATED = 'created'
     FAILED = 'failed'
     CREATING = 'creating'
@@ -87,13 +93,15 @@ class Snapshot(Model):
 
 
 class Deployment(Model):
+    """
+    A Model which represents a deployment
+    """
     id = Field(type=basestring, default=uuid_generator)
     description = Field(type=(basestring, NoneType))
     created_at = Field(type=datetime)
     updated_at = Field(type=datetime)
     blueprint_id = Field(type=basestring)
     workflows = Field(type=dict)
-    permalink = Field(default=None)  # TODO: check if needed... (old todo: 
implement)
     inputs = Field(type=dict, default=lambda: {})
     policy_types = Field(type=dict, default=lambda: {})
     policy_triggers = Field(type=dict, default=lambda: {})
@@ -103,6 +111,9 @@ class Deployment(Model):
 
 
 class DeploymentUpdateStep(Model):
+    """
+    A Model which represents a deployment update step
+    """
     id = Field(type=basestring, default=uuid_generator)
     action = Field(type=basestring, choices=ACTION_TYPES)
     entity_type = Field(type=basestring, choices=ENTITY_TYPES)
@@ -123,11 +134,12 @@ class DeploymentUpdateStep(Model):
 
         if self.action != other.action:
             if self.action == 'remove':
-                return True
+                return_value = True
             elif self.action == 'add':
-                return False
+                return_value = False
             else:
-                return other.action == 'add'
+                return_value = other.action == 'add'
+            return return_value
 
         if self.action == 'add':
             return self.entity_type == 'node' and other.entity_type == 
'relationship'
@@ -137,6 +149,9 @@ class DeploymentUpdateStep(Model):
 
 
 class DeploymentUpdate(Model):
+    """
+    A Model which represents a deployment update
+    """
     INITIALIZING = 'initializing'
     SUCCESSFUL = 'successful'
     UPDATING = 'updating'
@@ -158,8 +173,8 @@ class DeploymentUpdate(Model):
     deployment_id = Field(type=basestring)
     state = Field(type=basestring, choices=STATES, default=INITIALIZING)
     deployment_plan = Field()
-    deployment_update_nodes = Field(default=None)
-    deployment_update_node_instances = Field(default=None)
+    depup_nodes = Field(default=None)
+    depup_node_instances = Field(default=None)
     deployment_update_deployment = Field(default=None)
     modified_entity_ids = Field(default=None)
     execution_id = Field(type=basestring)
@@ -167,6 +182,9 @@ class DeploymentUpdate(Model):
 
 
 class Execution(Model):
+    """
+    A Model which represents an execution
+    """
     TERMINATED = 'terminated'
     FAILED = 'failed'
     CANCELLED = 'cancelled'
@@ -199,6 +217,9 @@ class Execution(Model):
 
 
 class Operation(Model):
+    """
+    A Model which represents an operation
+    """
     PENDING = 'pending'
     STARTED = 'started'
     SUCCESS = 'success'
@@ -222,6 +243,9 @@ class Operation(Model):
 
 
 class Relationship(Model):
+    """
+    A Model which represents a relationship
+    """
     id = Field(type=basestring, default=uuid_generator)
     target_id = Field(type=basestring)
     source_interfaces = Field(type=dict)
@@ -234,6 +258,9 @@ class Relationship(Model):
 
 
 class Node(Model):
+    """
+    A Model which represents a node
+    """
     id = Field(type=basestring, default=uuid_generator)
     blueprint_id = Field(type=basestring)
     type = Field(type=basestring)
@@ -251,6 +278,11 @@ class Node(Model):
     max_number_of_instances = Field(type=int)
 
     def relationships_by_target(self, target_id):
+        """
+        Retreives all of the relationship by target.
+        :param target_id: the node id of the target  of the relationship
+        :return:
+        """
         for relationship in self.relationships:
             if relationship.target_id == target_id:
                 yield relationship
@@ -258,6 +290,9 @@ class Node(Model):
 
 
 class RelationshipInstance(Model):
+    """
+    A Model which represents a relationship instance
+    """
     id = Field(type=basestring, default=uuid_generator)
     target_id = Field(type=basestring)
     target_name = Field(type=basestring)
@@ -266,6 +301,9 @@ class RelationshipInstance(Model):
 
 
 class NodeInstance(Model):
+    """
+    A Model which represents a node instance
+    """
     # todo: add statuses
     UNINITIALIZED = 'uninitialized'
     INITIALIZING = 'initializing'
@@ -297,6 +335,11 @@ class NodeInstance(Model):
     scaling_groups = Field(default=())
 
     def relationships_by_target(self, target_id):
+        """
+        Retreives all of the relationship by target.
+        :param target_id: the instance id of the target  of the relationship
+        :return:
+        """
         for relationship_instance in self.relationship_instances:
             if relationship_instance.target_id == target_id:
                 yield relationship_instance
@@ -304,6 +347,9 @@ class NodeInstance(Model):
 
 
 class DeploymentModification(Model):
+    """
+    A Model which represents a deployment modification
+    """
     STARTED = 'started'
     FINISHED = 'finished'
     ROLLEDBACK = 'rolledback'
@@ -324,12 +370,18 @@ class DeploymentModification(Model):
 
 
 class ProviderContext(Model):
+    """
+    A Model which represents a provider context
+    """
     id = Field(type=basestring, default=uuid_generator)
     context = Field(type=dict)
     name = Field(type=basestring)
 
 
 class Plugin(Model):
+    """
+    A Model which represents a plugin
+    """
     id = Field(type=basestring, default=uuid_generator)
     package_name = Field(type=basestring)
     archive_name = Field(type=basestring)

http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/03b2a22b/aria/storage/structures.py
----------------------------------------------------------------------
diff --git a/aria/storage/structures.py b/aria/storage/structures.py
index 5ebd8b8..8fb3e53 100644
--- a/aria/storage/structures.py
+++ b/aria/storage/structures.py
@@ -48,6 +48,10 @@ __all__ = (
 
 
 def uuid_generator():
+    """
+    wrapper function which generates ids
+    :return:
+    """
     return str(uuid4())
 
 
@@ -132,6 +136,9 @@ class Field(ValidatorMixin):
 
 
 class IterField(Field):
+    """
+    Represents an iterable field.
+    """
     def __init__(self, **kwargs):
         """
         Simple iterable field manager.
@@ -174,6 +181,12 @@ class IterPointerField(IterField, PointerField):
 
 
 class Model(object):
+    """
+    Base class for all of the storage models.
+    """
+    # Setting id to avoid missing class member is usage
+    id = None
+
     def __init__(self, **fields):
         """
         Abstract class for any model in the storage.
@@ -206,6 +219,10 @@ class Model(object):
 
     @property
     def fields(self):
+        """
+        iterates over the fields of the model.
+        :return:
+        """
         for name, field in vars(self.__class__).items():
             if isinstance(field, Field):
                 yield name
@@ -254,6 +271,9 @@ class Model(object):
 
 
 class Storage(LoggerMixin):
+    """
+    Represents the storage
+    """
     def __init__(self, driver, items=(), **kwargs):
         super(Storage, self).__init__(**kwargs)
         self.driver = driver

Reply via email to