From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 2CAB4138202 for ; Fri, 6 Sep 2013 17:27:48 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 97A07E0FB0; Fri, 6 Sep 2013 17:27:47 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 0645CE0FB4 for ; Fri, 6 Sep 2013 17:27:46 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id DF92533EBC9 for ; Fri, 6 Sep 2013 17:27:45 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 68BF9E5467 for ; Fri, 6 Sep 2013 17:27:43 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1378488166.62c81650a1ce027d376dd04c70861a8be9faa934.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config/tree.py X-VCS-Directories: roverlay/config/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 62c81650a1ce027d376dd04c70861a8be9faa934 X-VCS-Branch: master Date: Fri, 6 Sep 2013 17:27:43 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 6cb65016-90ca-4d62-890d-778ad5a23ed8 X-Archives-Hash: 27bc40a99ffa683cee7f01aab84a9b5c commit: 62c81650a1ce027d376dd04c70861a8be9faa934 Author: André Erdmann mailerd de> AuthorDate: Fri Sep 6 17:22:46 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Fri Sep 6 17:22:46 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=62c81650 config tree: register_static, reset() Optionally do not register a created ConfigTree instance as static instance. Support for re-setting the config tree (which removes all config options from it). --- roverlay/config/tree.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/roverlay/config/tree.py b/roverlay/config/tree.py index 4be20c1..c87df55 100644 --- a/roverlay/config/tree.py +++ b/roverlay/config/tree.py @@ -31,7 +31,7 @@ class ConfigTree ( object ): # static access to the first created ConfigTree instance = None - def __init__ ( self, import_const=True ): + def __init__ ( self, import_const=True, register_static=None ): """Initializes an ConfigTree, which is a container for options/values. Values can be stored directly (such as the field_definitions) or in a tree-like { section -> subsection[s] -> option = value } structure. @@ -41,21 +41,38 @@ class ConfigTree ( object ): arguments: * import_const -- whether to deepcopy constants into the config tree or not. Copying allows faster lookups. + * register_static -- if True: register new instance as static + if None: same as for True unless a static instance + is already registered + else: do nothing """ - if ConfigTree.instance is None: - ConfigTree.instance = self + if register_static is True or ( + self.__class__.instance is None and register_static is None + ): + self.__class__.instance = self self.logger = logging.getLogger ( self.__class__.__name__ ) else: self.logger = logging.getLogger ( - self.__class__.__name__ + "(%i)" % id ( self ) ) + "{}({:d}".format ( self.__class__.__name__, id ( self ) ) + ) - self._config = const.clone() if import_const else dict () - self._const_imported = import_const - self._field_definition = None - self._use_extend_map = None + self._config = None + self._const_imported = False + self._field_definition = None + self._use_extend_map = None + self.reset ( import_const=import_const ) # --- end of __init__ (...) --- + def reset ( self, import_const=None ): + if import_const is not None: + self._const_imported = bool ( import_const ) + + self._config = const.clone() if self._const_imported else dict() + self._field_definition = None + self._use_extend_map = None + # --- end of reset (...) --- + def get_loader ( self ): """Returns a ConfigLoader for this ConfigTree.""" return ConfigLoader ( self )