Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 11D1C200C80 for ; Thu, 25 May 2017 17:20:15 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 0E306160BCA; Thu, 25 May 2017 15:20:15 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 551E5160BC7 for ; Thu, 25 May 2017 17:20:14 +0200 (CEST) Received: (qmail 76164 invoked by uid 500); 25 May 2017 15:20:13 -0000 Mailing-List: contact commits-help@ariatosca.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ariatosca.incubator.apache.org Delivered-To: mailing list commits@ariatosca.incubator.apache.org Received: (qmail 76155 invoked by uid 99); 25 May 2017 15:20:13 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 25 May 2017 15:20:13 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 73ADADFAEB; Thu, 25 May 2017 15:20:13 +0000 (UTC) From: mxmrlv To: commits@ariatosca.apache.org Reply-To: commits@ariatosca.apache.org References: In-Reply-To: Subject: [GitHub] incubator-ariatosca pull request #133: Convert runtime_properties to attribu... Content-Type: text/plain Message-Id: <20170525152013.73ADADFAEB@git1-us-west.apache.org> Date: Thu, 25 May 2017 15:20:13 +0000 (UTC) archived-at: Thu, 25 May 2017 15:20:15 -0000 Github user mxmrlv commented on a diff in the pull request: https://github.com/apache/incubator-ariatosca/pull/133#discussion_r118509708 --- Diff: aria/orchestrator/context/common.py --- @@ -381,33 +381,41 @@ def _raw(self): return list(self) -class InstrumentCollection(object): +class _InstrumentedModel(object): - def __init__(self, field_name): - super(InstrumentCollection, self).__init__() + def __init__(self, field_name, original_model, model_storage): + super(_InstrumentedModel, self).__init__() self._field_name = field_name - self._actor = None - - @property - def actor(self): - return self._actor + self._model_storage = model_storage + self._original_model = original_model + self._apply_instrumentation() def __getattr__(self, item): - return getattr(self._actor, item) - - def __call__(self, func, *args, **kwargs): - def _wrapper(func_self, *args, **kwargs): - self._actor = func(func_self, *args, **kwargs) - field = getattr(self._actor, self._field_name) - - # Preserve the original value. e.g. original attributes would be located under - # _attributes - setattr(self, '_{0}'.format(self._field_name), field) - - # set instrumented value - setattr(self, self._field_name, _InstrumentedDict(func_self.model, - self._actor, - self._field_name, - field)) - return self - return _wrapper + return getattr(self._original_model, item) + + def _apply_instrumentation(self): + + field = getattr(self._original_model, self._field_name) + + # Preserve the original value. e.g. original attributes would be located under + # _attributes + setattr(self, '_{0}'.format(self._field_name), field) + + # set instrumented value + setattr(self, self._field_name, _InstrumentedDict(self._model_storage, + self._original_model, + self._field_name, + field)) + + +def instrument_collection(field_name, func=None): --- End diff -- move new classes to parameter_collection_instrumentation.py --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---