Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/, roverlay/
Date: Mon, 30 Jul 2012 08:54:27
Message-Id: 1343637773.68a36f34b652b88dcf3763b2ef86182e1395ce76.dywi@gentoo
1 commit: 68a36f34b652b88dcf3763b2ef86182e1395ce76
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Mon Jul 30 08:42:53 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Mon Jul 30 08:42:53 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=68a36f34
7
8 split str util functions from util.py
9
10 ---
11 roverlay/config/loader.py | 3 +-
12 roverlay/config/util.py | 17 ---------------
13 roverlay/strutil.py | 50 +++++++++++++++++++++++++++++++++++++++++++++
14 roverlay/util.py | 37 +-------------------------------
15 4 files changed, 54 insertions(+), 53 deletions(-)
16
17 diff --git a/roverlay/config/loader.py b/roverlay/config/loader.py
18 index 57027ec..81e904a 100644
19 --- a/roverlay/config/loader.py
20 +++ b/roverlay/config/loader.py
21 @@ -6,8 +6,9 @@ import re
22 import shlex
23 import os.path
24
25 +from roverlay.strutil import unquote
26 from roverlay.config import fielddef
27 -from roverlay.config.util import get_config_path, unquote
28 +from roverlay.config.util import get_config_path
29 from roverlay.config.entrymap import CONFIG_ENTRY_MAP
30
31 class ConfigLoader ( object ):
32
33 diff --git a/roverlay/config/util.py b/roverlay/config/util.py
34 index ea70465..d463b62 100644
35 --- a/roverlay/config/util.py
36 +++ b/roverlay/config/util.py
37 @@ -16,20 +16,3 @@ def get_config_path ( key ):
38 else:
39 return _path
40 # --- end of get_config_path (...) ---
41 -
42 -def unquote ( _str, keep_going=False):
43 - """Removes enclosing quotes from a string.
44 -
45 - arguments:
46 - * _str --
47 - * keep_going -- remove all enclosing quotes ("'"a"'" -> a)
48 - """
49 - if len ( _str ) < 2: return _str
50 - chars = '\"\''
51 -
52 - for c in chars:
53 - if _str [0] == c and _str [-1] == c:
54 - return unquote ( _str[1:-1] ) if keep_going else _str[1:-1]
55 -
56 - return _str
57 -# --- end of unquote (...) ---
58
59 diff --git a/roverlay/strutil.py b/roverlay/strutil.py
60 new file mode 100644
61 index 0000000..d2f094c
62 --- /dev/null
63 +++ b/roverlay/strutil.py
64 @@ -0,0 +1,50 @@
65 +# R overlay -- string utility functions
66 +import re
67 +
68 +_EBUILD_NAME_ILLEGAL_CHARS = re.compile ( "[.:]{1,}" )
69 +_EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY = '_'
70 +
71 +def fix_ebuild_name ( name ):
72 + return _EBUILD_NAME_ILLEGAL_CHARS.sub (
73 + _EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY,
74 + name
75 + )
76 +# --- end of fix_ebuild_name (...) ---
77 +
78 +def ascii_filter ( _str ):
79 + """Removes all non-ascii chars from a string and returns the result."""
80 + return ''.join ( c for c in _str if ord ( c ) < 128 )
81 +# --- end of ascii_filter (...) ---
82 +
83 +def shorten_str ( s, maxlen, replace_end=None ):
84 + if not replace_end is None:
85 + rlen = maxlen - len ( replace_end )
86 + if rlen >= 0:
87 + return s[:rlen] + replace_end if len (s) > maxlen else s
88 +
89 + return s[:maxlen] if len (s) > maxlen else s
90 +# --- end of shorten_str (...) ---
91 +
92 +def pipe_lines ( _pipe, use_filter=False, filter_func=None ):
93 + lines = _pipe.decode().split ('\n')
94 + if use_filter:
95 + return filter ( filter_func, lines )
96 + else:
97 + return lines
98 +# --- end of pipe_lines (...) ---
99 +
100 +def unquote ( _str, keep_going=False):
101 + """Removes enclosing quotes from a string.
102 +
103 + arguments:
104 + * _str --
105 + * keep_going -- remove all enclosing quotes ("'"a"'" -> a)
106 + """
107 + if len ( _str ) < 2: return _str
108 + chars = '\"\''
109 +
110 + if _str [0] == _str [-1] and _str [0] in chars:
111 + return unquote ( _str[1:-1] ) if keep_going else _str[1:-1]
112 +
113 + return _str
114 +# --- end of unquote (...) ---
115
116 diff --git a/roverlay/util.py b/roverlay/util.py
117 index 3f32646..4577226 100644
118 --- a/roverlay/util.py
119 +++ b/roverlay/util.py
120 @@ -2,47 +2,14 @@
121 # Copyright 2006-2012 Gentoo Foundation
122 # Distributed under the terms of the GNU General Public License v2
123
124 -import re
125 import os
126 import logging
127 -import threading
128
129 -from roverlay import config
130 +# FIXME: update modules: strutil <> util
131 +from roverlay.strutil import *
132
133 LOGGER = logging.getLogger ( 'util' )
134
135 -_EBUILD_NAME_ILLEGAL_CHARS = re.compile ( "[.:]{1,}" )
136 -_EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY = '_'
137 -
138 -def fix_ebuild_name ( name ):
139 - return _EBUILD_NAME_ILLEGAL_CHARS.sub (
140 - _EBUILD_NAME_ILLEGAL_CHARS_REPLACE_BY,
141 - name
142 - )
143 -# --- end of fix_ebuild_name (...) ---
144 -
145 -def ascii_filter ( _str ):
146 - """Removes all non-ascii chars from a string and returns the result."""
147 - return ''.join ( c for c in _str if ord ( c ) < 128 )
148 -# --- end of ascii_filter (...) ---
149 -
150 -def shorten_str ( s, maxlen, replace_end=None ):
151 - if not replace_end is None:
152 - rlen = maxlen - len ( replace_end )
153 - if rlen >= 0:
154 - return s[:rlen] + replace_end if len (s) > maxlen else s
155 -
156 - return s[:maxlen] if len (s) > maxlen else s
157 -# --- end of shorten_str (...) ---
158 -
159 -def pipe_lines ( _pipe, use_filter=False, filter_func=None ):
160 - lines = _pipe.decode().split ('\n')
161 - if use_filter:
162 - return filter ( filter_func, lines )
163 - else:
164 - return lines
165 -# --- end of pipe_lines (...) ---
166 -
167 def keepenv ( *to_keep ):
168 """Selectively imports os.environ.