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.60) (envelope-from ) id 1SbcdD-0001wf-LZ for garchives@archives.gentoo.org; Mon, 04 Jun 2012 19:07:59 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id AEB58E0998; Mon, 4 Jun 2012 19:07:42 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 6A44EE0998 for ; Mon, 4 Jun 2012 19:07:42 +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 97BA21B4024 for ; Mon, 4 Jun 2012 19:07:41 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id EFFF5E5434 for ; Mon, 4 Jun 2012 19:07:38 +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: <1338836812.0070a7fb77e1be78cb49cbd043987b9cc87ba50b.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 0070a7fb77e1be78cb49cbd043987b9cc87ba50b X-VCS-Branch: master Date: Mon, 4 Jun 2012 19:07:38 +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: a1cd6da0-1e93-4bbf-8a51-d39fba69a8a9 X-Archives-Hash: 77a1fe0184971559c8fda9df130e69b0 commit: 0070a7fb77e1be78cb49cbd043987b9cc87ba50b Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Mon Jun 4 19:06:52 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Mon Jun 4 19:06:52 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3D0070a7fb config.py: config entry value types explained --- roverlay/config.py | 62 +++++++++++++++++++++++++++++++++++++++-------= ----- 1 files changed, 47 insertions(+), 15 deletions(-) diff --git a/roverlay/config.py b/roverlay/config.py index bce721c..ab6dfec 100644 --- a/roverlay/config.py +++ b/roverlay/config.py @@ -3,7 +3,7 @@ # Distributed under the terms of the GNU General Public License v2 =20 import copy -import os +import os.path import re import sys import shlex @@ -64,8 +64,21 @@ class ConfigTree: # static access to the first created ConfigTree instance =3D None =20 - # the list of 'normal' config entries (no special config path) (in lowe= rcase) - # the map of config entries + # the map of config entries (keep keys in lowercase) + # * value_type, you can specify: + # ** slist (whitespace-separated list) + # ** list (see DEFAULT_LIST_REGEX below) + # ** int + # ** yesno + # ** fs_path (~ will be expanded) + # ** fs_file (fs_path + must be a file if it exists) + # + # multiple types are generally not supported ('this is an int or a st= r'), + # but subtypes are (list of yesno), which can be specified by either + # using a list of types ['list', 'yesno'] or by separating the types + # with a colon list:yesno, which is parsed in a left-to-right order. + # Nested subtypes such as list:slist:int:fs_file:list may lead to err= ors. + # CONFIG_ENTRY_MAP =3D dict ( log_level =3D '', log_console =3D dict ( @@ -176,6 +189,19 @@ class ConfigTree: return -1 # --- end of yesno (...) --- =20 + def fs_path ( val ): + return os.path.expanduser ( val ) if val else None + # --- end of fs_path (...) --- + + def fs_file ( val ): + if val: + retval =3D os.path.expanduser ( val ) + if os.path.isfile ( retval ) or not os.path.exists ( retval ): + return retval + + return None + # --- end of fs_file (...) --- + value =3D ConfigTree.WHITESPACE.sub ( ' ', value ) =20 if not value_type: @@ -188,23 +214,29 @@ class ConfigTree: self.logger.error ( "Unknown data type for value type." ) return value =20 + # value_type -> function where function accepts one parameter + funcmap =3D { + 'list' : ConfigTree.DEFAULT_LIST_REGEX.split, + 'slist' : ConfigTree.WHITESPACE.split, + 'yesno' : yesno, + 'int' : to_int, + 'fs_path' : fs_path, + 'fs_file' : fs_file, + } + + # dofunc ( function f, v) calls f(x) for every str in v + dofunc =3D lambda f, v : [ f(x) for x in v ] if isinstance ( v, list = ) else f(v) + + retval =3D value - is_list =3D False - for vtype in vtypes: - if vtype =3D=3D 'list': - retval =3D ConfigTree.DEFAULT_LIST_REGEX.split ( retval ) - is_list =3D True - elif vtype =3D=3D 'slist': - retval =3D ConfigTree.WHITESPACE.split ( retval ) - is_list =3D True - elif vtype =3D=3D 'yesno': - retval =3D [ yesno ( x ) for x in retval ] if is_list else yesno (= retval ) - elif vtype =3D=3D 'int': - retval =3D [ to_int ( x ) for x in retval ] if is_list else to_int = ( retval ) =20 + for vtype in vtypes: + if vtype in funcmap: + retval =3D dofunc ( funcmap [vtype], retval ) else: self.logger.warning ( "unknown value type '" + vtype + "'." ) =20 + return retval # --- end of make_and_verify_value (...) --- =20