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 E51D013800E for ; Mon, 30 Jul 2012 08:54:27 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 96A4FE071D; Mon, 30 Jul 2012 08:52:54 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 567A5E071D for ; Mon, 30 Jul 2012 08:52:54 +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 871711B4025 for ; Mon, 30 Jul 2012 08:52:48 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 3AC02E544D for ; Mon, 30 Jul 2012 08:52:46 +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: <1343637773.68a36f34b652b88dcf3763b2ef86182e1395ce76.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/, roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config/loader.py roverlay/config/util.py roverlay/strutil.py roverlay/util.py X-VCS-Directories: roverlay/config/ roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 68a36f34b652b88dcf3763b2ef86182e1395ce76 X-VCS-Branch: master Date: Mon, 30 Jul 2012 08:52:46 +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: 24407655-aec0-49ce-ac0c-36eeab22b0cb X-Archives-Hash: 8cbf1789d529c92a76e6322c54b6a846 Message-ID: <20120730085246.6GYAiiAVitW6YVQJxixDM2EoDZSqvJ47kfynG_j9W-g@z> commit: 68a36f34b652b88dcf3763b2ef86182e1395ce76 Author: André Erdmann mailerd de> AuthorDate: Mon Jul 30 08:42:53 2012 +0000 Commit: André Erdmann mailerd de> CommitDate: Mon Jul 30 08:42:53 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=68a36f34 split str util functions from util.py --- roverlay/config/loader.py | 3 +- roverlay/config/util.py | 17 --------------- roverlay/strutil.py | 50 +++++++++++++++++++++++++++++++++++++++++++++ roverlay/util.py | 37 +------------------------------- 4 files changed, 54 insertions(+), 53 deletions(-) diff --git a/roverlay/config/loader.py b/roverlay/config/loader.py index 57027ec..81e904a 100644 --- a/roverlay/config/loader.py +++ b/roverlay/config/loader.py @@ -6,8 +6,9 @@ import re import shlex import os.path +from roverlay.strutil import unquote from roverlay.config import fielddef -from roverlay.config.util import get_config_path, unquote +from roverlay.config.util import get_config_path from roverlay.config.entrymap import CONFIG_ENTRY_MAP class ConfigLoader ( object ): diff --git a/roverlay/config/util.py b/roverlay/config/util.py index ea70465..d463b62 100644 --- a/roverlay/config/util.py +++ b/roverlay/config/util.py @@ -16,20 +16,3 @@ def get_config_path ( key ): else: return _path # --- end of get_config_path (...) --- - -def unquote ( _str, keep_going=False): - """Removes enclosing quotes from a string. - - arguments: - * _str -- - * keep_going -- remove all enclosing quotes ("'"a"'" -> a) - """ - if len ( _str ) < 2: return _str - chars = '\"\'' - - for c in chars: - if _str [0] == c and _str [-1] == c: - return unquote ( _str[1:-1] ) if keep_going else _str[1:-1] - - return _str -# --- end of unquote (...) --- diff --git a/roverlay/strutil.py b/roverlay/strutil.py new file mode 100644 index 0000000..d2f094c --- /dev/null +++ b/roverlay/strutil.py @@ -0,0 +1,50 @@ +# R overlay -- string utility functions +import re + +_EBUILD_NAME_ILLEGAL_CHARS = re.compile ( "[.:]{1,}" ) +_EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY = '_' + +def fix_ebuild_name ( name ): + return _EBUILD_NAME_ILLEGAL_CHARS.sub ( + _EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY, + name + ) +# --- end of fix_ebuild_name (...) --- + +def ascii_filter ( _str ): + """Removes all non-ascii chars from a string and returns the result.""" + return ''.join ( c for c in _str if ord ( c ) < 128 ) +# --- end of ascii_filter (...) --- + +def shorten_str ( s, maxlen, replace_end=None ): + if not replace_end is None: + rlen = maxlen - len ( replace_end ) + if rlen >= 0: + return s[:rlen] + replace_end if len (s) > maxlen else s + + return s[:maxlen] if len (s) > maxlen else s +# --- end of shorten_str (...) --- + +def pipe_lines ( _pipe, use_filter=False, filter_func=None ): + lines = _pipe.decode().split ('\n') + if use_filter: + return filter ( filter_func, lines ) + else: + return lines +# --- end of pipe_lines (...) --- + +def unquote ( _str, keep_going=False): + """Removes enclosing quotes from a string. + + arguments: + * _str -- + * keep_going -- remove all enclosing quotes ("'"a"'" -> a) + """ + if len ( _str ) < 2: return _str + chars = '\"\'' + + if _str [0] == _str [-1] and _str [0] in chars: + return unquote ( _str[1:-1] ) if keep_going else _str[1:-1] + + return _str +# --- end of unquote (...) --- diff --git a/roverlay/util.py b/roverlay/util.py index 3f32646..4577226 100644 --- a/roverlay/util.py +++ b/roverlay/util.py @@ -2,47 +2,14 @@ # Copyright 2006-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 -import re import os import logging -import threading -from roverlay import config +# FIXME: update modules: strutil <> util +from roverlay.strutil import * LOGGER = logging.getLogger ( 'util' ) -_EBUILD_NAME_ILLEGAL_CHARS = re.compile ( "[.:]{1,}" ) -_EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY = '_' - -def fix_ebuild_name ( name ): - return _EBUILD_NAME_ILLEGAL_CHARS.sub ( - _EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY, - name - ) -# --- end of fix_ebuild_name (...) --- - -def ascii_filter ( _str ): - """Removes all non-ascii chars from a string and returns the result.""" - return ''.join ( c for c in _str if ord ( c ) < 128 ) -# --- end of ascii_filter (...) --- - -def shorten_str ( s, maxlen, replace_end=None ): - if not replace_end is None: - rlen = maxlen - len ( replace_end ) - if rlen >= 0: - return s[:rlen] + replace_end if len (s) > maxlen else s - - return s[:maxlen] if len (s) > maxlen else s -# --- end of shorten_str (...) --- - -def pipe_lines ( _pipe, use_filter=False, filter_func=None ): - lines = _pipe.decode().split ('\n') - if use_filter: - return filter ( filter_func, lines ) - else: - return lines -# --- end of pipe_lines (...) --- - def keepenv ( *to_keep ): """Selectively imports os.environ.