ARIA-21 Move general code from parser.utils to top level utils
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/3895f8ca Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/3895f8ca Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/3895f8ca Branch: refs/heads/ARIA-21-extract-some-parser-code Commit: 3895f8ca63210bd2d9d060834ff36323bec9e897 Parents: 653365d Author: Dan Kilman <d...@gigaspaces.com> Authored: Wed Nov 16 17:16:12 2016 +0200 Committer: Dan Kilman <d...@gigaspaces.com> Committed: Wed Nov 16 20:50:26 2016 +0200 ---------------------------------------------------------------------- aria/__init__.py | 2 +- aria/cli/commands.py | 2 +- aria/exceptions.py | 21 +- aria/orchestrator/context/common.py | 4 - aria/orchestrator/decorators.py | 2 +- aria/orchestrator/events/__init__.py | 2 +- .../orchestrator/workflows/executor/blocking.py | 4 +- .../workflows/executor/multiprocess.py | 4 +- aria/orchestrator/workflows/executor/thread.py | 4 +- aria/parser/__init__.py | 8 - aria/parser/consumption/consumer.py | 4 +- aria/parser/consumption/exceptions.py | 2 +- aria/parser/consumption/inputs.py | 2 +- aria/parser/consumption/modeling.py | 2 +- aria/parser/consumption/presentation.py | 3 +- aria/parser/consumption/style.py | 3 +- aria/parser/exceptions.py | 20 +- aria/parser/loading/context.py | 2 +- aria/parser/loading/exceptions.py | 2 +- aria/parser/loading/location.py | 2 +- aria/parser/loading/uri.py | 4 +- aria/parser/modeling/context.py | 8 +- aria/parser/modeling/elements.py | 7 +- aria/parser/modeling/exceptions.py | 2 +- aria/parser/modeling/instance_elements.py | 9 +- aria/parser/modeling/model_elements.py | 11 +- aria/parser/modeling/types.py | 8 +- aria/parser/modeling/utils.py | 9 +- aria/parser/presentation/exceptions.py | 2 +- aria/parser/presentation/fields.py | 17 +- aria/parser/presentation/null.py | 2 +- aria/parser/presentation/presentation.py | 5 +- aria/parser/presentation/presenter.py | 3 +- aria/parser/presentation/utils.py | 2 +- aria/parser/reading/context.py | 4 +- aria/parser/reading/exceptions.py | 2 +- aria/parser/reading/jinja.py | 4 +- aria/parser/reading/json.py | 5 +- aria/parser/reading/locator.py | 2 +- aria/parser/reading/reader.py | 2 +- aria/parser/reading/yaml.py | 6 +- aria/parser/specification.py | 7 +- aria/parser/tools/__init__.py | 14 - aria/parser/tools/cli.py | 69 ----- aria/parser/tools/rest.py | 266 ----------------- aria/parser/tools/spec.py | 60 ---- aria/parser/tools/utils.py | 73 ----- aria/parser/tools/web/index.html | 8 - aria/parser/utils/__init__.py | 81 ----- aria/parser/utils/argparse.py | 113 ------- aria/parser/utils/caching.py | 134 --------- aria/parser/utils/collections.py | 287 ------------------ aria/parser/utils/console.py | 60 ---- aria/parser/utils/daemon.py | 70 ----- aria/parser/utils/exceptions.py | 64 ---- aria/parser/utils/formatting.py | 207 ------------- aria/parser/utils/imports.py | 51 ---- aria/parser/utils/openclose.py | 32 -- aria/parser/utils/rest_client.py | 59 ---- aria/parser/utils/rest_server.py | 252 ---------------- aria/parser/utils/threading.py | 252 ---------------- aria/parser/utils/uris.py | 28 -- aria/parser/validation/context.py | 7 +- aria/parser/validation/issue.py | 8 +- aria/storage/structures.py | 2 +- aria/tools/__init__.py | 20 -- aria/tools/application.py | 294 ------------------- aria/tools/lru_cache.py | 136 --------- aria/tools/module.py | 38 --- aria/tools/plugin.py | 39 --- aria/tools/process.py | 186 ------------ aria/tools/validation.py | 95 ------ aria/utils/__init__.py | 14 + aria/utils/application.py | 294 +++++++++++++++++++ aria/utils/caching.py | 133 +++++++++ aria/utils/collections.py | 291 ++++++++++++++++++ aria/utils/console.py | 64 ++++ aria/utils/exceptions.py | 64 ++++ aria/utils/formatting.py | 203 +++++++++++++ aria/utils/imports.py | 78 +++++ aria/utils/openclose.py | 32 ++ aria/utils/plugin.py | 39 +++ aria/utils/threading.py | 252 ++++++++++++++++ aria/utils/uris.py | 28 ++ aria/utils/validation.py | 95 ++++++ .../simple_nfv_v1_0/presenter.py | 4 +- .../simple_v1_0/assignments.py | 3 +- .../simple_v1_0/data_types.py | 8 +- .../simple_v1_0/definitions.py | 3 +- .../aria_extension_tosca/simple_v1_0/filters.py | 2 +- .../simple_v1_0/functions.py | 3 +- .../aria_extension_tosca/simple_v1_0/misc.py | 4 +- .../simple_v1_0/modeling/artifacts.py | 6 +- .../simple_v1_0/modeling/capabilities.py | 7 +- .../simple_v1_0/modeling/data_types.py | 8 +- .../simple_v1_0/modeling/interfaces.py | 7 +- .../simple_v1_0/modeling/properties.py | 7 +- .../simple_v1_0/modeling/requirements.py | 6 +- .../modeling/substitution_mappings.py | 2 +- .../simple_v1_0/presentation/extensible.py | 2 +- .../simple_v1_0/presentation/field_getters.py | 3 +- .../presentation/field_validators.py | 2 +- .../simple_v1_0/presenter.py | 3 +- .../simple_v1_0/templates.py | 3 +- .../aria_extension_tosca/simple_v1_0/types.py | 3 +- requirements.txt | 1 - setup.py | 27 +- tests/orchestrator/context/test_workflow.py | 1 + 108 files changed, 1744 insertions(+), 3179 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/__init__.py ---------------------------------------------------------------------- diff --git a/aria/__init__.py b/aria/__init__.py index b2d1157..eb04e39 100644 --- a/aria/__init__.py +++ b/aria/__init__.py @@ -22,7 +22,7 @@ from .VERSION import version as __version__ from .orchestrator.decorators import workflow, operation from .storage import ModelStorage, ResourceStorage, models, ModelDriver, ResourceDriver from . import ( - tools, + utils, parser, storage, orchestrator, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/cli/commands.py ---------------------------------------------------------------------- diff --git a/aria/cli/commands.py b/aria/cli/commands.py index 2fff4f0..341b13a 100644 --- a/aria/cli/commands.py +++ b/aria/cli/commands.py @@ -31,7 +31,7 @@ from aria import application_model_storage, application_resource_storage from aria.orchestrator.context.workflow import WorkflowContext from aria.logger import LoggerMixin from aria.storage import FileSystemModelDriver, FileSystemResourceDriver -from aria.tools.application import StorageManager +from aria.utils.application import StorageManager from aria.orchestrator.workflows.core.engine import Engine from aria.orchestrator.workflows.executor.thread import ThreadExecutor from .exceptions import ( http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/exceptions.py b/aria/exceptions.py index 472b264..28f8be9 100644 --- a/aria/exceptions.py +++ b/aria/exceptions.py @@ -19,9 +19,28 @@ Every sub-package in Aria has a module with its exceptions. aria.exceptions module conveniently collects all these exceptions for easier imports. """ +import sys + class AriaError(Exception): """ - General aria exception + Base class for ARIA errors. """ pass + + +class AriaException(Exception): + """ + Base class for ARIA exceptions. + """ + + def __init__(self, message=None, cause=None, cause_traceback=None): + super(AriaException, self).__init__(message) + self.cause = cause + self.issue = None + if cause_traceback is None: + _, e, traceback = sys.exc_info() + if cause == e: + # Make sure it's our traceback + cause_traceback = traceback + self.cause_tb = cause_traceback http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/context/common.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/context/common.py b/aria/orchestrator/context/common.py index 48f4557..f2bf83b 100644 --- a/aria/orchestrator/context/common.py +++ b/aria/orchestrator/context/common.py @@ -19,7 +19,6 @@ from uuid import uuid4 from aria import logger from aria.storage import exceptions -from aria.tools.lru_cache import lru_cache class BaseContext(logger.LoggerMixin): @@ -76,7 +75,6 @@ class BaseContext(logger.LoggerMixin): return self._resource @property - @lru_cache() def blueprint(self): """ The blueprint model @@ -84,7 +82,6 @@ class BaseContext(logger.LoggerMixin): return self.model.blueprint.get(self.deployment.blueprint_id) @property - @lru_cache() def deployment(self): """ The deployment model @@ -134,7 +131,6 @@ class BaseContext(logger.LoggerMixin): destination=destination, path=path) - @lru_cache() def get_resource(self, path=None): """ Read a deployment resource as string from the resource storage http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/decorators.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/decorators.py b/aria/orchestrator/decorators.py index 7f7685d..6e8ab39 100644 --- a/aria/orchestrator/decorators.py +++ b/aria/orchestrator/decorators.py @@ -20,7 +20,7 @@ Workflow and operation decorators from uuid import uuid4 from functools import partial, wraps -from aria.tools.validation import validate_function_arguments +from aria.utils.validation import validate_function_arguments from . import context from .workflows.api import task_graph http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/events/__init__.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/events/__init__.py b/aria/orchestrator/events/__init__.py index 40bdd24..fbc0f32 100644 --- a/aria/orchestrator/events/__init__.py +++ b/aria/orchestrator/events/__init__.py @@ -36,7 +36,7 @@ import os from blinker import signal -from aria.tools import plugin_installer +from aria.utils.plugin import plugin_installer # workflow engine task signals: sent_task_signal = signal('sent_task_signal') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/workflows/executor/blocking.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/blocking.py b/aria/orchestrator/workflows/executor/blocking.py index 30bebbe..9d3a9ba 100644 --- a/aria/orchestrator/workflows/executor/blocking.py +++ b/aria/orchestrator/workflows/executor/blocking.py @@ -17,7 +17,7 @@ Blocking executor """ -from aria.tools import module +from aria.utils import imports from .base import BaseExecutor @@ -29,7 +29,7 @@ class CurrentThreadBlockingExecutor(BaseExecutor): def execute(self, task): self._task_started(task) try: - task_func = module.load_attribute(task.operation_mapping) + task_func = imports.load_attribute(task.operation_mapping) task_func(ctx=task.context, **task.inputs) self._task_succeeded(task) except BaseException as e: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/workflows/executor/multiprocess.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/multiprocess.py b/aria/orchestrator/workflows/executor/multiprocess.py index e73ab09..d770e07 100644 --- a/aria/orchestrator/workflows/executor/multiprocess.py +++ b/aria/orchestrator/workflows/executor/multiprocess.py @@ -22,7 +22,7 @@ import threading import jsonpickle -from aria.tools import module +from aria.utils import imports from .base import BaseExecutor @@ -90,7 +90,7 @@ class _MultiprocessMessage(object): def _multiprocess_handler(queue, ctx, task_id, operation_mapping, operation_inputs): queue.put(_MultiprocessMessage(type='task_started', task_id=task_id)) try: - task_func = module.load_attribute(operation_mapping) + task_func = imports.load_attribute(operation_mapping) task_func(ctx=ctx, **operation_inputs) queue.put(_MultiprocessMessage(type='task_succeeded', task_id=task_id)) except BaseException as e: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/orchestrator/workflows/executor/thread.py ---------------------------------------------------------------------- diff --git a/aria/orchestrator/workflows/executor/thread.py b/aria/orchestrator/workflows/executor/thread.py index fd7b302..76ceefd 100644 --- a/aria/orchestrator/workflows/executor/thread.py +++ b/aria/orchestrator/workflows/executor/thread.py @@ -20,7 +20,7 @@ Thread based executor import Queue import threading -from aria.tools import module +from aria.utils import imports from .base import BaseExecutor @@ -55,7 +55,7 @@ class ThreadExecutor(BaseExecutor): task = self._queue.get(timeout=1) self._task_started(task) try: - task_func = module.load_attribute(task.operation_mapping) + task_func = imports.load_attribute(task.operation_mapping) task_func(ctx=task.context, **task.inputs) self._task_succeeded(task) except BaseException as e: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/__init__.py ---------------------------------------------------------------------- diff --git a/aria/parser/__init__.py b/aria/parser/__init__.py index d479082..c2e2fd6 100644 --- a/aria/parser/__init__.py +++ b/aria/parser/__init__.py @@ -16,12 +16,9 @@ import sys import pkgutil -from .exceptions import AriaException, InvalidValueError from .specification import (DSL_SPECIFICATION, DSL_SPECIFICATION_PACKAGES, dsl_specification, iter_spec) -VERSION = '0.1' - def install_aria_extensions(): """ @@ -45,16 +42,11 @@ MODULES = ( 'modeling', 'presentation', 'reading', - 'tools', - 'utils', 'validation') __all__ = ( 'MODULES', - 'VERSION', 'install_aria_extensions', - 'AriaException', - 'InvalidValueError', 'DSL_SPECIFICATION', 'DSL_SPECIFICATION_PACKAGES', 'dsl_specification', http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/consumer.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/consumer.py b/aria/parser/consumption/consumer.py index 847d015..f9c2f2e 100644 --- a/aria/parser/consumption/consumer.py +++ b/aria/parser/consumption/consumer.py @@ -14,9 +14,9 @@ # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException +from ...utils.exceptions import print_exception from ..validation import Issue -from ..utils import print_exception class Consumer(object): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/exceptions.py b/aria/parser/consumption/exceptions.py index 564e71f..78509cb 100644 --- a/aria/parser/consumption/exceptions.py +++ b/aria/parser/consumption/exceptions.py @@ -14,7 +14,7 @@ # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException class ConsumerException(AriaException): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/inputs.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/inputs.py b/aria/parser/consumption/inputs.py index 3711001..fe7e192 100644 --- a/aria/parser/consumption/inputs.py +++ b/aria/parser/consumption/inputs.py @@ -13,9 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ...utils.formatting import safe_repr from ..loading import UriLocation, LiteralLocation from ..reading import JsonReader -from ..utils import safe_repr from .consumer import Consumer http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/modeling.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/modeling.py b/aria/parser/consumption/modeling.py index 8f8ee53..599c260 100644 --- a/aria/parser/consumption/modeling.py +++ b/aria/parser/consumption/modeling.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..utils import json_dumps, yaml_dumps +from ...utils.formatting import json_dumps, yaml_dumps from .consumer import Consumer, ConsumerChain http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/presentation.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/presentation.py b/aria/parser/consumption/presentation.py index 9723b9f..4d0f282 100644 --- a/aria/parser/consumption/presentation.py +++ b/aria/parser/consumption/presentation.py @@ -14,7 +14,8 @@ # limitations under the License. -from ..utils import FixedThreadPoolExecutor, json_dumps, yaml_dumps +from ...utils.threading import FixedThreadPoolExecutor +from ...utils.formatting import json_dumps, yaml_dumps from ..loading import UriLocation from ..reading import AlreadyReadException from ..presentation import PresenterNotFoundError http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/consumption/style.py ---------------------------------------------------------------------- diff --git a/aria/parser/consumption/style.py b/aria/parser/consumption/style.py index 8222f3e..88ad934 100644 --- a/aria/parser/consumption/style.py +++ b/aria/parser/consumption/style.py @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..utils import safe_repr, Colored, indent +from ...utils.console import Colored, indent +from ...utils.formatting import safe_repr class Style(object): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/exceptions.py b/aria/parser/exceptions.py index ab1b4fd..5d1a55c 100644 --- a/aria/parser/exceptions.py +++ b/aria/parser/exceptions.py @@ -13,28 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys - +from ..exceptions import AriaException from .validation import Issue -class AriaException(Exception): - """ - Base class for ARIA exceptions. - """ - - def __init__(self, message=None, cause=None, cause_traceback=None): - super(AriaException, self).__init__(message) - self.cause = cause - self.issue = None - if cause_traceback is None: - _, e, traceback = sys.exc_info() - if cause == e: - # Make sure it's our traceback - cause_traceback = traceback - self.cause_tb = cause_traceback - - class InvalidValueError(AriaException): """ ARIA error: value is invalid. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/loading/context.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/context.py b/aria/parser/loading/context.py index 2c52086..44e3fd1 100644 --- a/aria/parser/loading/context.py +++ b/aria/parser/loading/context.py @@ -14,7 +14,7 @@ # limitations under the License. -from ..utils import StrictList +from ...utils.collections import StrictList from .source import DefaultLoaderSource http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/loading/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/exceptions.py b/aria/parser/loading/exceptions.py index 204ad28..6e8267a 100644 --- a/aria/parser/loading/exceptions.py +++ b/aria/parser/loading/exceptions.py @@ -14,7 +14,7 @@ # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException class LoaderException(AriaException): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/loading/location.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/location.py b/aria/parser/loading/location.py index 0a3d428..5bc6fab 100644 --- a/aria/parser/loading/location.py +++ b/aria/parser/loading/location.py @@ -16,7 +16,7 @@ import os -from ..utils import as_file +from ...utils.uris import as_file class Location(object): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/loading/uri.py ---------------------------------------------------------------------- diff --git a/aria/parser/loading/uri.py b/aria/parser/loading/uri.py index 5e6ff39..f94a003 100644 --- a/aria/parser/loading/uri.py +++ b/aria/parser/loading/uri.py @@ -16,7 +16,8 @@ import os from urlparse import urljoin -from ..utils import StrictList, as_file +from ...utils.collections import StrictList +from ...utils.uris import as_file from .loader import Loader from .file import FileTextLoader from .request import RequestTextLoader @@ -24,6 +25,7 @@ from .exceptions import DocumentNotFoundException URI_LOADER_PREFIXES = StrictList(value_class=basestring) + class UriTextLoader(Loader): """ Base class for ARIA URI loaders. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/context.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/context.py b/aria/parser/modeling/context.py index 9e64ac5..d47c202 100644 --- a/aria/parser/modeling/context.py +++ b/aria/parser/modeling/context.py @@ -13,13 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict import itertools -from ..utils import StrictDict, prune, puts, as_raw +from ...utils.collections import StrictDict, prune, OrderedDict +from ...utils.formatting import as_raw +from ...utils.console import puts from .types import TypeHierarchy from .utils import generate_id_string http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/elements.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/elements.py b/aria/parser/modeling/elements.py index ffde635..62bc7b8 100644 --- a/aria/parser/modeling/elements.py +++ b/aria/parser/modeling/elements.py @@ -13,11 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict -from ..utils import StrictDict, puts +from ...utils.collections import StrictDict, OrderedDict +from ...utils.console import puts from .utils import coerce_value http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/exceptions.py b/aria/parser/modeling/exceptions.py index 66fb7d2..c7f08df 100644 --- a/aria/parser/modeling/exceptions.py +++ b/aria/parser/modeling/exceptions.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException class CannotEvaluateFunctionException(AriaException): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/instance_elements.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/instance_elements.py b/aria/parser/modeling/instance_elements.py index 5fbf4f4..523de0b 100644 --- a/aria/parser/modeling/instance_elements.py +++ b/aria/parser/modeling/instance_elements.py @@ -13,13 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from ...utils.collections import StrictList, StrictDict, FrozenList, OrderedDict +from ...utils.formatting import as_raw, as_raw_list, as_raw_dict, as_agnostic, safe_repr +from ...utils.console import puts, indent from ..validation import Issue -from ..utils import (StrictList, StrictDict, FrozenList, puts, indent, as_raw, as_raw_list,\ - as_raw_dict, as_agnostic, safe_repr) from .elements import Element, Parameter from .utils import (validate_dict_values, validate_list_values, coerce_dict_values, coerce_list_values, dump_list_values, dump_dict_values, dump_parameters, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/model_elements.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/model_elements.py b/aria/parser/modeling/model_elements.py index ec081e7..7346a54 100644 --- a/aria/parser/modeling/model_elements.py +++ b/aria/parser/modeling/model_elements.py @@ -14,16 +14,13 @@ # limitations under the License. from __future__ import absolute_import # so we can import standard 'types' -from types import FunctionType -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from types import FunctionType +from ...utils.collections import StrictList, StrictDict, deepcopy_with_locators, OrderedDict +from ...utils.formatting import as_raw, as_raw_list, as_raw_dict, as_agnostic, safe_repr +from ...utils.console import puts from ..validation import Issue -from ..utils import (StrictList, StrictDict, puts, safe_repr, as_raw, as_raw_list, as_raw_dict, - as_agnostic, deepcopy_with_locators) from .elements import ModelElement, Parameter from .instance_elements import (ServiceInstance, Node, Capability, Relationship, Artifact, Group, Policy, GroupPolicy, GroupPolicyTrigger, Mapping, Substitution, http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/types.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/types.py b/aria/parser/modeling/types.py index 4795fe0..e6249ef 100644 --- a/aria/parser/modeling/types.py +++ b/aria/parser/modeling/types.py @@ -13,11 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict -from ..utils import StrictList, StrictDict, puts, as_raw +from ...utils.collections import StrictList, StrictDict, OrderedDict +from ...utils.formatting import as_raw +from ...utils.console import puts class Type(object): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/modeling/utils.py ---------------------------------------------------------------------- diff --git a/aria/parser/modeling/utils.py b/aria/parser/modeling/utils.py index 5d99eb5..906106e 100644 --- a/aria/parser/modeling/utils.py +++ b/aria/parser/modeling/utils.py @@ -15,15 +15,12 @@ from random import randrange -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict from shortuuid import ShortUUID -from .. import InvalidValueError +from ...utils.collections import OrderedDict +from ...utils.console import puts +from ..exceptions import InvalidValueError from ..presentation import Value -from ..utils import puts from .exceptions import CannotEvaluateFunctionException # UUID = ShortUUID() # default alphabet is base57, which is alphanumeric without visually ambiguous http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/exceptions.py b/aria/parser/presentation/exceptions.py index 7c0e1f8..cd7eb07 100644 --- a/aria/parser/presentation/exceptions.py +++ b/aria/parser/presentation/exceptions.py @@ -14,7 +14,7 @@ # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException class PresenterException(AriaException): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/fields.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/fields.py b/aria/parser/presentation/fields.py index a3a9f12..da3cb05 100644 --- a/aria/parser/presentation/fields.py +++ b/aria/parser/presentation/fields.py @@ -16,14 +16,15 @@ import threading from functools import wraps from types import MethodType -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - -from ..exceptions import InvalidValueError, AriaException -from ..utils import (FrozenList, FrozenDict, print_exception, deepcopy_with_locators, merge, - cachedmethod, puts, as_raw, full_type_name, safe_repr) + +from ...exceptions import AriaException +from ...utils.collections import FrozenDict, FrozenList, deepcopy_with_locators, merge, OrderedDict +from ...utils.caching import cachedmethod +from ...utils.console import puts +from ...utils.formatting import as_raw, safe_repr, full_type_name +from ...utils.exceptions import print_exception +from ..exceptions import InvalidValueError + from .null import NULL from .utils import validate_primitive http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/null.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/null.py b/aria/parser/presentation/null.py index a69134e..a018df4 100644 --- a/aria/parser/presentation/null.py +++ b/aria/parser/presentation/null.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..utils import deepcopy_with_locators +from ...utils.collections import deepcopy_with_locators class Null(object): http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/presentation.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/presentation.py b/aria/parser/presentation/presentation.py index 15cb5ed..0f098b5 100644 --- a/aria/parser/presentation/presentation.py +++ b/aria/parser/presentation/presentation.py @@ -13,8 +13,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ...utils.caching import HasCachedMethods +from ...utils.collections import deepcopy_with_locators +from ...utils.formatting import full_type_name, safe_repr +from ...utils.console import puts from ..validation import Issue -from ..utils import HasCachedMethods, full_type_name, deepcopy_with_locators, puts, safe_repr from .null import none_to_null from .utils import (get_locator, validate_no_short_form, validate_no_unknown_fields, validate_known_fields, validate_primitive) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/presenter.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/presenter.py b/aria/parser/presentation/presenter.py index 4cade3a..9fd296f 100644 --- a/aria/parser/presentation/presenter.py +++ b/aria/parser/presentation/presenter.py @@ -13,8 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ...utils.collections import merge +from ...utils.formatting import safe_repr from ..validation import Issue -from ..utils import merge, safe_repr from .presentation import Presentation http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/presentation/utils.py ---------------------------------------------------------------------- diff --git a/aria/parser/presentation/utils.py b/aria/parser/presentation/utils.py index 2e4d873..74adbd1 100644 --- a/aria/parser/presentation/utils.py +++ b/aria/parser/presentation/utils.py @@ -15,8 +15,8 @@ from types import FunctionType +from ...utils.formatting import full_type_name, safe_repr from ..validation import Issue -from ..utils import full_type_name, safe_repr from .null import NULL http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/context.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/context.py b/aria/parser/reading/context.py index 81135dc..02d4de9 100644 --- a/aria/parser/reading/context.py +++ b/aria/parser/reading/context.py @@ -10,8 +10,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from ...utils.threading import LockedList from .source import DefaultReaderSource -from ..utils import LockedList class ReadingContext(object): @@ -26,4 +26,4 @@ class ReadingContext(object): self.reader_source = DefaultReaderSource() self.reader = None - self._locations = LockedList() # for keeping track of locations already read + self._locations = LockedList() # for keeping track of locations already read http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/exceptions.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/exceptions.py b/aria/parser/reading/exceptions.py index bc2d2d5..3699729 100644 --- a/aria/parser/reading/exceptions.py +++ b/aria/parser/reading/exceptions.py @@ -10,7 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from .. import AriaException +from ...exceptions import AriaException from ..validation import Issue http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/jinja.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/jinja.py b/aria/parser/reading/jinja.py index e15e54e..17bf49e 100644 --- a/aria/parser/reading/jinja.py +++ b/aria/parser/reading/jinja.py @@ -14,7 +14,7 @@ import os from jinja2 import Template -from .. import VERSION +from ...VERSION import version from ..loading import LiteralLocation, LiteralLoader from .reader import Reader from .exceptions import ReaderSyntaxError @@ -22,7 +22,7 @@ from .exceptions import ReaderSyntaxError # TODO: we could put a lot of other useful stuff here. CONTEXT = { - 'ARIA_VERSION': VERSION, + 'ARIA_VERSION': version, 'ENV': os.environ} http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/json.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/json.py b/aria/parser/reading/json.py index 24c4df0..d144f80 100644 --- a/aria/parser/reading/json.py +++ b/aria/parser/reading/json.py @@ -13,11 +13,8 @@ from __future__ import absolute_import # so we can import standard 'json' import json -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict +from ...utils.collections import OrderedDict from .reader import Reader from .exceptions import ReaderSyntaxError http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/locator.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/locator.py b/aria/parser/reading/locator.py index 90b9e73..a1cfa9c 100644 --- a/aria/parser/reading/locator.py +++ b/aria/parser/reading/locator.py @@ -10,7 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..utils import puts, Colored, indent +from ...utils.console import puts, Colored, indent # We are inheriting the primitive types in order to add the ability to set # an attribute (_locator) on them. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/reader.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/reader.py b/aria/parser/reading/reader.py index 3a50739..fe64697 100644 --- a/aria/parser/reading/reader.py +++ b/aria/parser/reading/reader.py @@ -10,7 +10,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -from ..utils import OpenClose +from ...utils.openclose import OpenClose from .exceptions import ReaderException, AlreadyReadException http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/reading/yaml.py ---------------------------------------------------------------------- diff --git a/aria/parser/reading/yaml.py b/aria/parser/reading/yaml.py index 097816a..f5eac43 100644 --- a/aria/parser/reading/yaml.py +++ b/aria/parser/reading/yaml.py @@ -10,13 +10,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - from ruamel import yaml # @UnresolvedImport +from ...utils.collections import OrderedDict from .reader import Reader from .locator import Locator from .exceptions import ReaderSyntaxError http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/specification.py ---------------------------------------------------------------------- diff --git a/aria/parser/specification.py b/aria/parser/specification.py index ec9959a..6e022bc 100644 --- a/aria/parser/specification.py +++ b/aria/parser/specification.py @@ -13,11 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict -from .utils import full_type_name +from ..utils.collections import OrderedDict +from ..utils.formatting import full_type_name DSL_SPECIFICATION = {} DSL_SPECIFICATION_PACKAGES = [] http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/__init__.py ---------------------------------------------------------------------- diff --git a/aria/parser/tools/__init__.py b/aria/parser/tools/__init__.py deleted file mode 100644 index ae1e83e..0000000 --- a/aria/parser/tools/__init__.py +++ /dev/null @@ -1,14 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/cli.py ---------------------------------------------------------------------- diff --git a/aria/parser/tools/cli.py b/aria/parser/tools/cli.py deleted file mode 100644 index a274e49..0000000 --- a/aria/parser/tools/cli.py +++ /dev/null @@ -1,69 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from aria.parser import install_aria_extensions -from aria.parser.utils import (print_exception, import_fullname) -from aria.parser.tools.utils import (CommonArgumentParser, create_context_from_namespace) -from aria.parser.consumption import (ConsumerChain, Read, Validate, Model, Types, Inputs, Instance) - -class ArgumentParser(CommonArgumentParser): - def __init__(self): - super(ArgumentParser, self).__init__(description='CLI', prog='aria') - self.add_argument('uri', help='URI or file path to profile') - self.add_argument('consumer', - nargs='?', - default='instance', - help='consumer class name (full class path or short name)') - -def main(): - try: - - args, unknown_args = ArgumentParser().parse_known_args() - - install_aria_extensions() - - context = create_context_from_namespace(args) - context.args = unknown_args - - consumer = ConsumerChain(context, (Read, Validate)) - - consumer_class_name = args.consumer - dumper = None - if consumer_class_name == 'presentation': - dumper = consumer.consumers[0] - elif consumer_class_name == 'model': - consumer.append(Model) - elif consumer_class_name == 'types': - consumer.append(Model, Types) - elif consumer_class_name == 'instance': - consumer.append(Model, Inputs, Instance) - else: - consumer.append(Model, Inputs, Instance) - consumer.append(import_fullname(consumer_class_name)) - - if dumper is None: - # Default to last consumer - dumper = consumer.consumers[-1] - - consumer.consume() - - if not context.validation.dump_issues(): - dumper.dump() - - except Exception as e: - print_exception(e) - -if __name__ == '__main__': - main() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/rest.py ---------------------------------------------------------------------- diff --git a/aria/parser/tools/rest.py b/aria/parser/tools/rest.py deleted file mode 100644 index 5c3dd5e..0000000 --- a/aria/parser/tools/rest.py +++ /dev/null @@ -1,266 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import os -import urllib -from urlparse import (urlparse, parse_qs) - -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - -from ..loading import LiteralLocation -from .. import install_aria_extensions -from .utils import (CommonArgumentParser, - create_context_from_namespace) -from ..consumption import (ConsumerChain, Read, Validate, Model, Inputs, Instance) -from ..utils import (RestServer, JsonAsRawEncoder, print_exception, start_daemon, stop_daemon, - status_daemon, puts, Colored) - -VALIDATE_PATH = 'validate' -INDIRECT_VALIDATE_PATH = 'indirect/validate' -MODEL_PATH = 'model' -INDIRECT_MODEL_PATH = 'indirect/model' -INSTANCE_PATH = 'instance' -INDIRECT_INSTANCE_PATH = 'indirect/instance' - -DEFAULT_PORT = 8080 - -# -# Utils -# - -class Configuration(object): - def __init__(self, arguments): - self.arguments = arguments - - def create_context(self, uri): - return create_context_from_namespace(self.arguments, uri=uri) - -def parse_path(handler): - parsed = urlparse(urllib.unquote(handler.path)) - uri = parsed.path[len(handler.matched_re):] - query = parse_qs(parsed.query, keep_blank_values=True) - return uri, query - -def parse_indirect_payload(handler): - try: - payload = handler.json_payload - except BaseException: - handler.send_plain_text_response(400, 'Payload is not JSON\n') - return None, None - - for key in payload.iterkeys(): - if key not in ('uri', 'inputs'): - handler.send_plain_text_response(400, 'Payload has unsupported field: %s\n' % key) - return None, None - - try: - uri = payload['uri'] - except BaseException: - handler.send_plain_text_response(400, 'Payload does not have required "uri" field\n') - return None, None - - inputs = payload.get('inputs') - - return uri, inputs - -def validate(handler, uri): - context = handler.rest_server.configuration.create_context(uri) - ConsumerChain(context, (Read, Validate)).consume() - return context - -def model(handler, uri): - context = handler.rest_server.configuration.create_context(uri) - ConsumerChain(context, (Read, Validate, Model)).consume() - return context - -def instance(handler, uri, inputs): - context = handler.rest_server.configuration.create_context(uri) - if inputs: - if isinstance(inputs, dict): - for name, value in inputs.iteritems(): - context.modeling.set_input(name, value) - else: - context.args.append('--inputs=%s' % inputs) - ConsumerChain(context, (Read, Validate, Model, Inputs, Instance)).consume() - return context - -def issues(context): - return {'issues': context.validation.issues_as_raw} - -# -# Handlers -# - -# Validate - -def validate_get(handler): - uri, _ = parse_path(handler) - context = validate(handler, uri) - return issues(context) if context.validation.has_issues else {} - -def validate_post(handler): - payload = handler.payload - context = validate(handler, LiteralLocation(payload)) - return issues(context) if context.validation.has_issues else {} - -def indirect_validate_post(handler): - uri, _ = parse_indirect_payload(handler) - if uri is None: - return None - context = validate(handler, uri) - return issues(context) if context.validation.has_issues else {} - -# Model - -def model_get(handler): - uri, _ = parse_path(handler) - context = model(handler, uri) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw - } - -def model_post(handler): - payload = handler.payload - context = model(handler, LiteralLocation(payload)) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw - } - -def indirect_model_post(handler): - uri, _ = parse_indirect_payload(handler) - if uri is None: - return None - context = model(handler, uri) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw - } - -# Instance - -def instance_get(handler): - uri, query = parse_path(handler) - inputs = query.get('inputs') - if inputs: - inputs = inputs[0] - context = instance(handler, uri, inputs) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw, - 'instance': context.modeling.instance_as_raw - } - -def instance_post(handler): - _, query = parse_path(handler) - inputs = query.get('inputs') - if inputs: - inputs = inputs[0] - payload = handler.payload - context = instance(handler, LiteralLocation(payload), inputs) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw, - 'instance': context.modeling.instance_as_raw - } - -def indirect_instance_post(handler): - uri, inputs = parse_indirect_payload(handler) - if uri is None: - return None - context = instance(handler, uri, inputs) - return issues(context) if context.validation.has_issues else { - 'types': context.modeling.types_as_raw, - 'model': context.modeling.model_as_raw, - 'instance': context.modeling.instance_as_raw - } - -# -# Server -# - -ROUTES = OrderedDict(( - ('^/$', {'file': 'index.html', 'media_type': 'text/html'}), - ('^/' + VALIDATE_PATH, {'GET': validate_get, - 'POST': validate_post, - 'media_type': 'application/json'}), - ('^/' + MODEL_PATH, {'GET': model_get, 'POST': model_post, 'media_type': 'application/json'}), - ('^/' + INSTANCE_PATH, {'GET': instance_get, - 'POST': instance_post, - 'media_type': 'application/json'}), - ('^/' + INDIRECT_VALIDATE_PATH, {'POST': indirect_validate_post, - 'media_type': 'application/json'}), - ('^/' + INDIRECT_MODEL_PATH, {'POST': indirect_model_post, 'media_type': 'application/json'}), - ('^/' + INDIRECT_INSTANCE_PATH, {'POST': indirect_instance_post, - 'media_type': 'application/json'}))) - -class ArgumentParser(CommonArgumentParser): - def __init__(self): - super(ArgumentParser, self).__init__(description='REST Server', prog='aria-rest') - self.add_argument('command', - nargs='?', - help='daemon command: start, stop, restart, or status') - self.add_argument('--port', type=int, default=DEFAULT_PORT, help='HTTP port') - self.add_argument('--root', help='web root directory') - self.add_argument('--rundir', - help='pid and log files directory for daemons (defaults to user home)') - -def main(): - try: - install_aria_extensions() - - arguments, _ = ArgumentParser().parse_known_args() - - rest_server = RestServer() - rest_server.configuration = Configuration(arguments) - rest_server.port = arguments.port - rest_server.routes = ROUTES - rest_server.static_root = arguments.root or os.path.join(os.path.dirname(__file__), 'web') - rest_server.json_encoder = JsonAsRawEncoder(ensure_ascii=False, separators=(',', ':')) - - if arguments.command: - rundir = os.path.abspath(arguments.rundir or os.path.expanduser('~')) - pidfile_path = os.path.join(rundir, 'aria-rest.pid') - - def start(): - log_path = os.path.join(rundir, 'aria-rest.log') - context = start_daemon(pidfile_path, log_path) - if context is not None: - with context: - rest_server.start(daemon=True) - - if arguments.command == 'start': - start() - elif arguments.command == 'stop': - stop_daemon(pidfile_path) - elif arguments.command == 'restart': - stop_daemon(pidfile_path) - start() - elif arguments.command == 'status': - status_daemon(pidfile_path) - else: - puts(Colored.red('Unknown command: %s' % arguments.command)) - else: - rest_server.start() - - except Exception as e: - print_exception(e) - -if __name__ == '__main__': - main() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/spec.py ---------------------------------------------------------------------- diff --git a/aria/parser/tools/spec.py b/aria/parser/tools/spec.py deleted file mode 100644 index ecb4010..0000000 --- a/aria/parser/tools/spec.py +++ /dev/null @@ -1,60 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import csv -import sys - -from .utils import BaseArgumentParser -from ..utils import (print_exception, import_modules, puts, Colored, indent) -from .. import (install_aria_extensions, DSL_SPECIFICATION_PACKAGES, DSL_SPECIFICATION, - iter_spec) - -class ArgumentParser(BaseArgumentParser): - def __init__(self): - super(ArgumentParser, self).__init__(description='Specification Tool', prog='aria-spec') - self.add_argument('--csv', action='store_true', help='output as CSV') - -def main(): - try: - args, _ = ArgumentParser().parse_known_args() - - install_aria_extensions() - - # Make sure that all @dsl_specification decorators are processed - for pkg in DSL_SPECIFICATION_PACKAGES: - import_modules(pkg) - - if args.csv: - writer = csv.writer(sys.stdout, quoting=csv.QUOTE_ALL) - writer.writerow(('Specification', 'Section', 'Code', 'URL')) - for spec in sorted(DSL_SPECIFICATION): - for section, details in iter_spec(spec): - writer.writerow((spec, section, details['code'], details['url'])) - - else: - for spec in sorted(DSL_SPECIFICATION): - puts(Colored.cyan(spec)) - with indent(2): - for section, details in iter_spec(spec): - puts(Colored.blue(section)) - with indent(2): - for k, v in details.iteritems(): - puts('%s: %s' % (Colored.magenta(k), v)) - - except Exception as e: - print_exception(e) - -if __name__ == '__main__': - main() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/utils.py ---------------------------------------------------------------------- diff --git a/aria/parser/tools/utils.py b/aria/parser/tools/utils.py deleted file mode 100644 index 9080e43..0000000 --- a/aria/parser/tools/utils.py +++ /dev/null @@ -1,73 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from .. import VERSION -from ..consumption import ConsumptionContext -from ..loading import (UriLocation, URI_LOADER_PREFIXES) -from ..utils import (ArgumentParser, import_fullname, cachedmethod) - -class BaseArgumentParser(ArgumentParser): - def __init__(self, description, **kwargs): - super(BaseArgumentParser, self).__init__( - description='%s for ARIA version %s' % (description, VERSION), **kwargs) - -class CommonArgumentParser(BaseArgumentParser): - def __init__(self, description, **kwargs): - super(CommonArgumentParser, self).__init__(description, **kwargs) - - self.add_argument('--loader-source', - default='aria.loading.DefaultLoaderSource', - help='loader source class for the parser') - self.add_argument('--reader-source', - default='aria.reading.DefaultReaderSource', - help='reader source class for the parser') - self.add_argument('--presenter-source', - default='aria.presentation.DefaultPresenterSource', - help='presenter source class for the parser') - self.add_argument('--presenter', help='force use of this presenter class in parser') - self.add_argument('--prefix', nargs='*', help='prefixes for imports') - self.add_flag_argument('debug', - help_true='print debug info', - help_false='don\'t print debug info') - self.add_flag_argument('cached-methods', - help_true='enable cached methods', - help_false='disable cached methods', - default=True) - - def parse_known_args(self, args=None, namespace=None): - namespace, args = super(CommonArgumentParser, self).parse_known_args(args, namespace) - - if namespace.prefix: - for prefix in namespace.prefix: - URI_LOADER_PREFIXES.append(prefix) - - cachedmethod.ENABLED = namespace.cached_methods - - return namespace, args - -def create_context_from_namespace(namespace, **kwargs): - args = vars(namespace).copy() - args.update(kwargs) - return create_context(**args) - -def create_context(uri, loader_source, reader_source, presenter_source, presenter, debug, **kwargs): - context = ConsumptionContext() - context.loading.loader_source = import_fullname(loader_source)() - context.reading.reader_source = import_fullname(reader_source)() - context.presentation.location = UriLocation(uri) if isinstance(uri, basestring) else uri - context.presentation.presenter_source = import_fullname(presenter_source)() - context.presentation.presenter_class = import_fullname(presenter) - context.presentation.print_exceptions = debug - return context http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/tools/web/index.html ---------------------------------------------------------------------- diff --git a/aria/parser/tools/web/index.html b/aria/parser/tools/web/index.html deleted file mode 100644 index 31b459d..0000000 --- a/aria/parser/tools/web/index.html +++ /dev/null @@ -1,8 +0,0 @@ -<html> -<head> - <title>ARIA REST Service</title> -</head> -<body> - <h1>ARIA REST Service</h1> -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/utils/__init__.py ---------------------------------------------------------------------- diff --git a/aria/parser/utils/__init__.py b/aria/parser/utils/__init__.py deleted file mode 100644 index ba42565..0000000 --- a/aria/parser/utils/__init__.py +++ /dev/null @@ -1,81 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from clint.textui import indent - -from .uris import as_file -from .openclose import OpenClose -from .rest_client import call_rest -from .argparse import ArgumentParser -from .console import (puts, Colored) -from .caching import (cachedmethod, HasCachedMethods) -from .imports import (import_fullname, import_modules) -from .rest_server import (RestServer, RestRequestHandler) -from .exceptions import (print_exception, print_traceback) -from .daemon import (start_daemon, stop_daemon, status_daemon) -from .threading import (ExecutorException, FixedThreadPoolExecutor, LockedList) -from .collections import (FrozenList, EMPTY_READ_ONLY_LIST, FrozenDict, EMPTY_READ_ONLY_DICT, - StrictList, StrictDict, merge, prune, deepcopy_with_locators, - copy_locators, is_removable) -from .formatting import (JsonAsRawEncoder, YamlAsRawDumper, full_type_name, safe_str, safe_repr, - string_list_as_string, as_raw, as_raw_list, as_raw_dict, as_agnostic, - json_dumps, yaml_dumps, yaml_loads) - -__all__ = ( - 'OpenClose', - 'cachedmethod', - 'HasCachedMethods', - 'JsonAsRawEncoder', - 'YamlAsRawDumper', - 'full_type_name', - 'safe_str', - 'safe_repr', - 'string_list_as_string', - 'as_raw', - 'as_raw_list', - 'as_raw_dict', - 'as_agnostic', - 'json_dumps', - 'yaml_dumps', - 'yaml_loads', - 'FrozenList', - 'EMPTY_READ_ONLY_LIST', - 'FrozenDict', - 'EMPTY_READ_ONLY_DICT', - 'StrictList', - 'StrictDict', - 'merge', - 'prune', - 'deepcopy_with_locators', - 'copy_locators', - 'is_removable', - 'print_exception', - 'print_traceback', - 'import_fullname', - 'import_modules', - 'ExecutorException', - 'FixedThreadPoolExecutor', - 'LockedList', - 'as_file', - 'ArgumentParser', - 'puts', - 'Colored', - 'indent', - 'RestServer', - 'RestRequestHandler', - 'call_rest', - 'start_daemon', - 'stop_daemon', - 'status_daemon') http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/utils/argparse.py ---------------------------------------------------------------------- diff --git a/aria/parser/utils/argparse.py b/aria/parser/utils/argparse.py deleted file mode 100644 index 071752d..0000000 --- a/aria/parser/utils/argparse.py +++ /dev/null @@ -1,113 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import # so we can import standard 'argparse' - -from argparse import ArgumentParser as BaseArgumentParser - -class ArgumentParser(BaseArgumentParser): - """ - Enhanced argument parser. - - Applied patch to fix `this issue <https://bugs.python.org/issue22433>`__. - """ - - def add_flag_argument(self, name, help_true=None, help_false=None, default=False): - """ - Adds a flag argument as two arguments: :code:`--my-flag` and :code:`--no-my-flag`. - """ - - dest = name.replace('-', '_') - - if default: - if help_true is not None: - help_true += ' (default)' - else: - help_true = '(default)' - else: - if help_false is not None: - help_false += ' (default)' - else: - help_false = '(default)' - - group = self.add_mutually_exclusive_group() - group.add_argument('--%s' % name, action='store_true', help=help_true) - group.add_argument('--no-%s' % name, dest=dest, action='store_false', help=help_false) - - self.set_defaults(**{dest: default}) - - def _parse_optional(self, arg_string): - - if self._is_positional(arg_string): - return None - - # if the option string is present in the parser, return the action - if arg_string in self._option_string_actions: - action = self._option_string_actions[arg_string] - return action, arg_string, None - - # if the option string before the "=" is present, return the action - if '=' in arg_string: - option_string, explicit_arg = arg_string.split('=', 1) - if option_string in self._option_string_actions: - action = self._option_string_actions[option_string] - return action, option_string, explicit_arg - - # search through all possible prefixes of the option string - # and all actions in the parser for possible interpretations - option_tuples = self._get_option_tuples(arg_string) - - # if multiple actions match, the option string was ambiguous - if len(option_tuples) > 1: - options = ', '.join( - [option_string for action, option_string, explicit_arg in option_tuples]) - tup = arg_string, options - self.error('ambiguous option: %s could match %s' % tup) - - # if exactly one action matched, this segmentation is good, - # so return the parsed action - elif len(option_tuples) == 1: - option_tuple = option_tuples - return option_tuple - - # if it was not found as an option, but it looks like a negative - # number, it was meant to be positional - # unless there are negative-number-like options - if self._negative_number_matcher.match(arg_string): - if not self._has_negative_number_optionals: - return None - - # it was meant to be an optional but there is no such option - # in this parser (though it might be a valid option in a subparser) - return None, arg_string, None - - def _is_positional(self, arg_string): - # if it's an empty string, it was meant to be a positional - if not arg_string: - return True - - # if it doesn't start with a prefix, it was meant to be positional - if not arg_string[0] in self.prefix_chars: - return True - - # if it's just a single character, it was meant to be positional - if len(arg_string) == 1: - return True - - # if it contains a space, it was meant to be a positional - if ' ' in arg_string and arg_string[0] not in self.prefix_chars: - return True - - return False http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/utils/caching.py ---------------------------------------------------------------------- diff --git a/aria/parser/utils/caching.py b/aria/parser/utils/caching.py deleted file mode 100644 index 8ebeef7..0000000 --- a/aria/parser/utils/caching.py +++ /dev/null @@ -1,134 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import # so we can import standard 'collections' and 'threading' - -from threading import Lock -from functools import partial -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - - -class cachedmethod(object): # pylint: disable=invalid-name - """ - Decorator for caching method return values. - - The implementation is thread-safe. - - Supports :code:`cache_info` to be compatible with Python 3's :code:`functools.lru_cache`. - Note that the statistics are combined for all instances of the class. - - Won't use the cache if not called when bound to an object, allowing you to override the cache. - - Adapted from `this solution - <http://code.activestate.com/recipes/577452-a-memoize-decorator-for-instance-methods/>`__. - """ - - ENABLED = True - - def __init__(self, func): - self.func = func - self.hits = 0 - self.misses = 0 - self.lock = Lock() - - def cache_info(self): - with self.lock: - return (self.hits, self.misses, None, self.misses) - - def reset_cache_info(self): - with self.lock: - self.hits = 0 - self.misses = 0 - - def __get__(self, instance, owner): - if instance is None: - # Don't use cache if not bound to an object - # Note: This is also a way for callers to override the cache - return self.func - return partial(self, instance) - - def __call__(self, *args, **kwargs): - if not self.ENABLED: - return self.func(*args, **kwargs) - - instance = args[0] - cache = instance.get_method_cache() - - key = (self.func, args[1:], frozenset(kwargs.items())) - - try: - with self.lock: - return_value = cache[key] - self.hits += 1 - except KeyError: - return_value = self.func(*args, **kwargs) - with self.lock: - cache[key] = return_value - self.misses += 1 - # Another thread may override our cache entry here, so we need to read - # it again to make sure all threads use the same return value - return_value = cache.get(key, return_value) - - return return_value - -class HasCachedMethods(object): - """ - Provides convenience methods for working with :class:`cachedmethod`. - """ - - def __init__(self, method_cache=None): - self._method_cache = method_cache or {} - - def get_method_cache(self): - return self._method_cache - - @property - def _method_cache_info(self): - """ - The cache infos of all cached methods. - - :rtype: dict of str, 4-tuple - """ - - cached_info = OrderedDict() - for k, v in self.__class__.__dict__.iteritems(): - if isinstance(v, property): - # The property getter might be cached - v = v.fget - if hasattr(v, 'cache_info'): - cached_info[k] = v.cache_info() - return cached_info - - def _reset_method_cache(self): - """ - Resets the caches of all cached methods. - """ - - if hasattr(self, '_method_cache'): - self._method_cache = {} - - # Note: Another thread may already be storing entries in the cache here. - # But it's not a big deal! It only means that our cache_info isn't - # guaranteed to be accurate. - - for entry in self.__class__.__dict__.itervalues(): - if isinstance(entry, property): - # The property getter might be cached - entry = entry.fget - if hasattr(entry, 'reset_cache_info'): - entry.reset_cache_info() http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/utils/collections.py ---------------------------------------------------------------------- diff --git a/aria/parser/utils/collections.py b/aria/parser/utils/collections.py deleted file mode 100644 index ae45b25..0000000 --- a/aria/parser/utils/collections.py +++ /dev/null @@ -1,287 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from __future__ import absolute_import # so we can import standard 'collections' - -from copy import deepcopy -try: - from collections import OrderedDict -except ImportError: - from ordereddict import OrderedDict - - -def cls_name(cls): - module = str(cls.__module__) - name = str(cls.__name__) - return name if module == '__builtin__' else '%s.%s' % (module, name) - -class FrozenList(list): - """ - An immutable list. - - After initialization it will raise :class:`TypeError` exceptions if modification - is attempted. - - Note that objects stored in the list may not be immutable. - """ - def __init__(self, *args, **kwargs): - self.locked = False - super(FrozenList, self).__init__(*args, **kwargs) - self.locked = True - - def __setitem__(self, index, value): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).__setitem__(index, value) - - def __delitem__(self, index): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).__delitem__(index) - - def __iadd__(self, values): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).__iadd__(values) - - def __deepcopy__(self, memo): - res = [deepcopy(v, memo) for v in self] - return FrozenList(res) - - def append(self, value): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).append(value) - - def extend(self, values): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).append(values) - - def insert(self, index, value): - if self.locked: - raise TypeError('frozen list') - return super(FrozenList, self).insert(index, value) - -EMPTY_READ_ONLY_LIST = FrozenList() - -class FrozenDict(OrderedDict): - """ - An immutable ordered dict. - - After initialization it will raise :class:`TypeError` exceptions if modification - is attempted. - - Note that objects stored in the dict may not be immutable. - """ - - def __init__(self, *args, **kwargs): - self.locked = False - super(FrozenDict, self).__init__(*args, **kwargs) - self.locked = True - - def __setitem__(self, key, value, **_): - if self.locked: - raise TypeError('frozen dict') - return super(FrozenDict, self).__setitem__(key, value) - - def __delitem__(self, key, **_): - if self.locked: - raise TypeError('frozen dict') - return super(FrozenDict, self).__delitem__(key) - - def __deepcopy__(self, memo): - res = [(deepcopy(k, memo), deepcopy(v, memo)) for k, v in self.iteritems()] - return FrozenDict(res) - -EMPTY_READ_ONLY_DICT = FrozenDict() - -class StrictList(list): - """ - A list that raises :class:`TypeError` exceptions when objects of the wrong type are inserted. - """ - - def __init__(self, - items=None, - value_class=None, - wrapper_function=None, - unwrapper_function=None): - super(StrictList, self).__init__() - if isinstance(items, StrictList): - self.value_class = items.value_class - self.wrapper_function = items.wrapper_function - self.unwrapper_function = items.unwrapper_function - self.value_class = value_class - self.wrapper_function = wrapper_function - self.unwrapper_function = unwrapper_function - if items: - for item in items: - self.append(item) - - def _wrap(self, value): - if (self.value_class is not None) and (not isinstance(value, self.value_class)): - raise TypeError('value must be a "%s": %s' % (cls_name(self.value_class), repr(value))) - if self.wrapper_function is not None: - value = self.wrapper_function(value) - return value - - def _unwrap(self, value): - if self.unwrapper_function is not None: - value = self.unwrapper_function(value) - return value - - def __getitem__(self, index): - value = super(StrictList, self).__getitem__(index) - value = self._unwrap(value) - return value - - def __setitem__(self, index, value): - value = self._wrap(value) - return super(StrictList, self).__setitem__(index, value) - - def __iadd__(self, values): - values = [self._wrap(v) for v in values] - return super(StrictList, self).__iadd__(values) - - def append(self, value): - value = self._wrap(value) - return super(StrictList, self).append(value) - - def extend(self, values): - values = [self._wrap(v) for v in values] - return super(StrictList, self).extend(values) - - def insert(self, index, value): - value = self._wrap(value) - return super(StrictList, self).insert(index, value) - -class StrictDict(OrderedDict): - """ - An ordered dict that raises :class:`TypeError` exceptions - when keys or values of the wrong type are used. - """ - - def __init__(self, - items=None, - key_class=None, - value_class=None, - wrapper_function=None, - unwrapper_function=None): - super(StrictDict, self).__init__() - if isinstance(items, StrictDict): - self.key_class = items.key_class - self.value_class = items.value_class - self.wrapper_function = items.wrapper_function - self.unwrapper_function = items.unwrapper_function - self.key_class = key_class - self.value_class = value_class - self.wrapper_function = wrapper_function - self.unwrapper_function = unwrapper_function - if items: - for k, v in items: - self[k] = v - - def __getitem__(self, key): - if (self.key_class is not None) and (not isinstance(key, self.key_class)): - raise TypeError('key must be a "%s": %s' % (cls_name(self.key_class), repr(key))) - value = super(StrictDict, self).__getitem__(key) - if self.unwrapper_function is not None: - value = self.unwrapper_function(value) - return value - - def __setitem__(self, key, value, **_): - if (self.key_class is not None) and (not isinstance(key, self.key_class)): - raise TypeError('key must be a "%s": %s' % (cls_name(self.key_class), repr(key))) - if (self.value_class is not None) and (not isinstance(value, self.value_class)): - raise TypeError('value must be a "%s": %s' % (cls_name(self.value_class), repr(value))) - if self.wrapper_function is not None: - value = self.wrapper_function(value) - return super(StrictDict, self).__setitem__(key, value) - -def merge(dict_a, dict_b, path=None, strict=False): - """ - Merges dicts, recursively. - """ - - # TODO: a.add_yaml_merge(b), see https://bitbucket.org/ruamel/yaml/src/ - # TODO: 86622a1408e0f171a12e140d53c4ffac4b6caaa3/comments.py?fileviewer=file-view-default - - path = path or [] - for key, value_b in dict_b.iteritems(): - if key in dict_a: - value_a = dict_a[key] - if isinstance(value_a, dict) and isinstance(value_b, dict): - merge(value_a, value_b, path + [str(key)], strict) - elif value_a != value_b: - if strict: - raise ValueError('dict merge conflict at %s' % '.'.join(path + [str(key)])) - else: - dict_a[key] = value_b - else: - dict_a[key] = value_b - return dict_a - -def is_removable(_container, _key, v): - return (v is None) or ((isinstance(v, dict) or isinstance(v, list)) and (len(v) == 0)) - -def prune(value, is_removable_function=is_removable): - """ - Deletes :code:`None` and empty lists and dicts, recursively. - """ - - if isinstance(value, list): - for i, v in enumerate(value): - if is_removable_function(value, i, v): - del value[i] - else: - prune(v, is_removable_function) - elif isinstance(value, dict): - for k, v in value.iteritems(): - if is_removable_function(value, k, v): - del value[k] - else: - prune(v, is_removable_function) - - return value - -def deepcopy_with_locators(value): - """ - Like :code:`deepcopy`, but also copies over locators. - """ - - res = deepcopy(value) - copy_locators(res, value) - return res - -def copy_locators(target, source): - """ - Copies over :code:`_locator` for all elements, recursively. - - Assumes that target and source have exactly the same list/dict structure. - """ - - locator = getattr(source, '_locator', None) - if locator is not None: - try: - setattr(target, '_locator', locator) - except AttributeError: - pass - - if isinstance(target, list) and isinstance(source, list): - for i, _ in enumerate(target): - copy_locators(target[i], source[i]) - elif isinstance(target, dict) and isinstance(source, dict): - for k, v in target.iteritems(): - copy_locators(v, source[k]) http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/3895f8ca/aria/parser/utils/console.py ---------------------------------------------------------------------- diff --git a/aria/parser/utils/console.py b/aria/parser/utils/console.py deleted file mode 100644 index 15c01e2..0000000 --- a/aria/parser/utils/console.py +++ /dev/null @@ -1,60 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one or more -# contributor license agreements. See the NOTICE file distributed with -# this work for additional information regarding copyright ownership. -# The ASF licenses this file to You under the Apache License, Version 2.0 -# (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from clint.textui.core import STDOUT -from clint.textui import puts as _puts -from clint.textui.colored import ColoredString as _ColoredString - -from .formatting import safe_str - -class ColoredString(_ColoredString): - def __init__(self, color, str_, always_color=False, bold=False): - super(ColoredString, self).__init__(color, safe_str(str_), always_color, bold) - -def puts(string='', newline=True, stream=STDOUT): - _puts(safe_str(string), newline, stream) - -class Colored(object): - @staticmethod - def black(string, always=False, bold=False): - return ColoredString('BLACK', string, always_color=always, bold=bold) - - @staticmethod - def red(string, always=False, bold=False): - return ColoredString('RED', string, always_color=always, bold=bold) - - @staticmethod - def green(string, always=False, bold=False): - return ColoredString('GREEN', string, always_color=always, bold=bold) - - @staticmethod - def yellow(string, always=False, bold=False): - return ColoredString('YELLOW', string, always_color=always, bold=bold) - - @staticmethod - def blue(string, always=False, bold=False): - return ColoredString('BLUE', string, always_color=always, bold=bold) - - @staticmethod - def magenta(string, always=False, bold=False): - return ColoredString('MAGENTA', string, always_color=always, bold=bold) - - @staticmethod - def cyan(string, always=False, bold=False): - return ColoredString('CYAN', string, always_color=always, bold=bold) - - @staticmethod - def white(string, always=False, bold=False): - return ColoredString('WHITE', string, always_color=always, bold=bold)