From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.77) (envelope-from ) id 1Sm7DG-00019L-D7 for garchives@archives.gentoo.org; Tue, 03 Jul 2012 17:48:34 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 795C0E07A4; Tue, 3 Jul 2012 17:48:07 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 3A2BEE07A4 for ; Tue, 3 Jul 2012 17:48:07 +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 6800B1B40C4 for ; Tue, 3 Jul 2012 17:48:06 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id D0179E5436 for ; Tue, 3 Jul 2012 17:48:04 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1341337062.7a6de49dd07aea5d7a5e4eb34a4735b354e838ff.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config/__init__.py roverlay/config/const.py roverlay/config/entrymap.py roverlay/config/tree.py X-VCS-Directories: roverlay/config/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 7a6de49dd07aea5d7a5e4eb34a4735b354e838ff X-VCS-Branch: master Date: Tue, 3 Jul 2012 17:48:04 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 99cdd289-ef3d-4a32-b377-5149a3a096fb X-Archives-Hash: c0690651cd38b542a3aa28255b7d46d9 commit: 7a6de49dd07aea5d7a5e4eb34a4735b354e838ff Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Tue Jul 3 17:37:42 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Tue Jul 3 17:37:42 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3D7a6de49d config module, ConfigTree ConfigTree: * can now be merged with dicts * added get_or_fail() * uses logging now instead of InitialLogger added field_definition_file to the config entry map modified: roverlay/config/__init__.py modified: roverlay/config/const.py modified: roverlay/config/entrymap.py modified: roverlay/config/tree.py --- roverlay/config/__init__.py | 2 +- roverlay/config/const.py | 13 ++++++---- roverlay/config/entrymap.py | 6 +++++ roverlay/config/tree.py | 51 ++++++++++++++++++++++++++-----------= ----- 4 files changed, 46 insertions(+), 26 deletions(-) diff --git a/roverlay/config/__init__.py b/roverlay/config/__init__.py index 9640c9f..50f5eba 100644 --- a/roverlay/config/__init__.py +++ b/roverlay/config/__init__.py @@ -35,5 +35,5 @@ def get ( key, fallback_value=3DNone, fail_if_unset=3DF= alse ): # --- end of get (...) --- =20 def get_or_fail ( key ): - return access().get ( key, fail_if_unset=3DTrue ) + return access().get_or_fail ( key ) # --- end of get_or_fail (...) --- diff --git a/roverlay/config/const.py b/roverlay/config/const.py index 18e4614..80763ce 100644 --- a/roverlay/config/const.py +++ b/roverlay/config/const.py @@ -7,17 +7,18 @@ import time =20 _CONSTANTS =3D dict ( DESCRIPTION =3D dict ( - field_separator =3D ':', - comment_chars =3D '#;', - list_split_regex =3D '\s*[,;]{1}\s*', - file_name =3D 'DESCRIPTION', + field_separator =3D ':', + comment_chars =3D '#;', + list_split_regex =3D '\s*[,;]{1}\s*', + file_name =3D 'DESCRIPTION', ), R_PACKAGE =3D dict ( suffix_regex =3D '[.](tgz|tbz2|tar|(tar[.](gz|bz2)))', name_ver_separator =3D '_', ), EBUILD =3D dict ( - indent =3D '\t', + # indent is currently not in use, FIXME + #indent =3D '\t', default_header =3D '\n'.join ( ( '# Copyright 1999-%i Gentoo Foundation' % ( time.gmtime() [0] ), '# Distributed under the terms of the GNU General Public License v2', @@ -25,6 +26,8 @@ _CONSTANTS =3D dict ( '', 'EAPI=3D4', '', + # FIXME: don't include eclasses here, calculate their names + # using OVERLAY.eclass_files 'inherit R-packages' ) ), ), diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py index 4179c4f..d1e8eca 100644 --- a/roverlay/config/entrymap.py +++ b/roverlay/config/entrymap.py @@ -130,6 +130,11 @@ CONFIG_ENTRY_MAP =3D dict ( =20 # =3D=3D description reader =3D=3D =20 + field_definition_file =3D dict ( + path =3D [ 'DESCRIPTION', 'field_definition_file' ], + value_type =3D fs_file, + ), + # * for debugging # if set: write _all_ description files to dir/ description_descfiles_dir =3D dict ( @@ -139,5 +144,6 @@ CONFIG_ENTRY_MAP =3D dict ( =20 # * alias description_dir =3D 'description_descfiles_dir', + field_definition =3D 'field_definition_file', =20 ) diff --git a/roverlay/config/tree.py b/roverlay/config/tree.py index adcdcde..426343e 100644 --- a/roverlay/config/tree.py +++ b/roverlay/config/tree.py @@ -2,6 +2,7 @@ # Copyright 2006-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 =20 +import logging import sys =20 from roverlay.config import const @@ -10,24 +11,6 @@ from roverlay.config.util import get_config_path =20 CONFIG_INJECTION_IS_BAD =3D True =20 -class InitialLogger: - - def __init__ ( self ): - """Initializes an InitialLogger. - It implements the debug/info/warning/error/critical/exception methods - known from the logging module and its output goes directly to sys.stde= rr. - This can be used until the real logging has been configured. - """ - # @return None - self.debug =3D lambda x : sys.stdout.write ( "DBG %s\n" % x ) - self.info =3D lambda x : sys.stdout.write ( "INFO %s\n" % x ) - self.warning =3D lambda x : sys.stderr.write ( "WARN %s\n" % x ) - self.error =3D lambda x : sys.stderr.write ( "ERR %s\n" % x ) - self.critical =3D lambda x : sys.stderr.write ( "CRIT %s\n" % x ) - self.exception =3D lambda x : sys.stderr.write ( "EXC! %s\n" % x ) - - # --- end of __init__ (...) --- - class ConfigTree ( object ): # static access to the first created ConfigTree instance =3D None @@ -45,8 +28,10 @@ class ConfigTree ( object ): """ if ConfigTree.instance is None: ConfigTree.instance =3D self - - self.logger =3D InitialLogger() + self.logger =3D logging.getLogger ( self.__class__.__name__ ) + else: + self.logger =3D logging.getLogger ( + self.__class__.__name__ + "(%i)" % id ( self ) ) =20 self._config =3D const.clone() if import_const else dict () self._const_imported =3D import_const @@ -59,6 +44,28 @@ class ConfigTree ( object ): return ConfigLoader ( self ) # --- end of get_loader (...) --- =20 + def merge_with ( self, _dict, allow_empty_value=3DFalse ): + # strategy =3D theirs + # unsafe operation (empty values,...) + if not _dict: + pass + + elif not isinstance ( _dict, dict ): + raise Exception ( "bad usage" ) + + elif allow_empty_value: + self._config.update ( _dict ) + + elif sys.version_info >=3D ( 2, 7 ): + u =3D { k : v for ( k, v ) in _dict.items() if v or v =3D=3D 0 } + self._config.update ( u ) + else: + # FIXME remove < 2.7 statement, roverlay (probably) doesn't work + # with python version prior to 2.7 + u =3D dict ( x for x in _dict.items() if x [1] or x [1] =3D=3D 0 ) + + # --- end of merge_with (...) --- + def _findpath ( self, path, root=3DNone, create=3DFalse, value=3DNone, forcepath=3DFalse, forceval= =3DFalse @@ -164,6 +171,10 @@ class ConfigTree ( object ): =20 # --- end of get (...) --- =20 + def get_or_fail ( self, key ): + return self.get ( key, fail_if_unset=3DTrue ) + # --- end of get_or_fail --- + def get_field_definition ( self, force_update=3DFalse ): """Gets the field definition stored in this ConfigTree. =20