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/
Date: Fri, 06 Jul 2012 22:19:55
Message-Id: 1341612831.68b95b0e8adfd900ed53330d1e2d5c90f8260efb.dywi@gentoo
1 commit: 68b95b0e8adfd900ed53330d1e2d5c90f8260efb
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Fri Jul 6 22:13:51 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Fri Jul 6 22:13:51 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=68b95b0e
7
8 config: add descriptions to the entry map
9
10 modified: roverlay/config/entrymap.py
11 new file: roverlay/config/entryutil.py
12
13 ---
14 roverlay/config/entrymap.py | 170 ++++++++++++++++++++++++++++++++----------
15 roverlay/config/entryutil.py | 44 +++++++++++
16 2 files changed, 175 insertions(+), 39 deletions(-)
17
18 diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
19 index f8987cf..60e1766 100644
20 --- a/roverlay/config/entrymap.py
21 +++ b/roverlay/config/entrymap.py
22 @@ -35,6 +35,7 @@
23
24 fs_file = 'fs_file'
25 fs_abslist = 'slist:fs_abs'
26 +yesno = 'yesno'
27
28 # often (>1) used entry dicts (it's ok to share a ref to those dicts
29 # 'cause CONFIG_ENTRY_MAP won't be modified)
30 @@ -50,61 +51,112 @@ LOG_LEVEL = frozenset ((
31
32 is_log_level = { 'choices' : LOG_LEVEL, 'flags' : CAPSLOCK }
33
34 +
35 only_vtype = lambda x : { 'value_type': x }
36
37 CONFIG_ENTRY_MAP = dict (
38
39 # == logging ==
40
41 - log_enabled = is_yesno,
42 - log_level = is_log_level,
43 + log_enabled = dict (
44 + value_type = yesno,
45 + description = "enable/disable logging",
46 + ),
47 + log_level = dict (
48 + desc = "global log level, choices are {}.".format (
49 + ', '.join ( LOG_LEVEL )
50 + ),
51 + **is_log_level
52 + ),
53 #log_format = None, # there's no global log format
54 - log_date_format = '',
55 + log_date_format = dict (
56 + desc = "date format, example: '%F %H:%M:%S'.",
57 + ),
58
59 # used in depres listener modules
60 - log_file_resolved = is_fs_file,
61 - log_file_unresolvable = is_fs_file,
62 + log_file_resolved = dict (
63 + value_type = fs_file,
64 + description = '''NOT IN USE.
65 + file where resolved dep strings will be written to.
66 + ''',
67 + ),
68 + log_file_unresolvable = dict (
69 + value_type = fs_file,
70 + description = '''file where unresolved dependency strings
71 + will be written to
72 + '''
73 + ),
74
75 # === logging to console ===
76
77 - log_console_enabled = is_yesno,
78 + log_console_enabled = dict (
79 + value_type = yesno,
80 + description = "enable/disable logging to stdout/stderr",
81 + ),
82 log_console = 'log_console_enabled',
83
84 - log_console_level = is_log_level,
85 + log_console_level = dict (
86 + desc = "log level for console logging.",
87 + **is_log_level
88 + ),
89 log_level_console = 'log_console_level',
90
91 log_console_stream = None, # option not configurable
92
93 - log_console_format = '',
94 + log_console_format = dict (
95 + desc = '''console logging format,
96 + example: '%(levelname)-7s [%(name)s] %(message)s'
97 + ''',
98 + ),
99 log_format_console = 'log_console_format',
100
101 # === logging to file ===
102
103 - log_file_enabled = is_yesno,
104 + log_file_enabled = dict (
105 + value_type = yesno,
106 + description = "enable/disable logging to file",
107 + ),
108
109 - log_file = dict (
110 + log_file = dict (
111 # setting path to LOG.FILE.file to avoid collision with LOG.FILE.*
112 - path = [ 'LOG', 'FILE', 'file' ],
113 - value_type = fs_file,
114 + path = [ 'LOG', 'FILE', 'file' ],
115 + value_type = fs_file,
116 + description = "log file to write",
117 ),
118
119 - log_file_level = is_log_level,
120 + log_file_level = dict (
121 + desc = "log level for file logging",
122 + **is_log_level
123 + ),
124 log_level_file = 'log_file_level',
125
126 - log_file_rotate = is_yesno,
127 + log_file_rotate = dict (
128 + value_type = yesno,
129 + description = "enable/disable log file rotating (per script run)",
130 + ),
131 log_file_rotate_count = dict (
132 - path = [ 'LOG', 'FILE', 'rotate_count' ],
133 - value_type = 'int',
134 + path = [ 'LOG', 'FILE', 'rotate_count' ],
135 + value_type = 'int',
136 + description = "number of rotated log files to keep",
137 ),
138
139 - log_file_format = '',
140 + log_file_format = dict (
141 + desc = '''file logging format,
142 + example: '%(asctime)s %(levelname)-8s %(name)-10s: %(message)s'
143 + '''
144 + ),
145 log_format_file = 'log_file_format',
146
147 - log_file_buffered = is_yesno,
148 + log_file_buffered = dict (
149 + value_type = yesno,
150 + description = "buffer log entries before writing them to file",
151 + ),
152 +
153 log_file_buffer_count = 'log_file_buffer_capacity',
154 log_file_buffer_capacity = dict (
155 - path = [ 'LOG', 'FILE', 'buffer_capacity' ],
156 - value_type = 'int',
157 + path = [ 'LOG', 'FILE', 'buffer_capacity' ],
158 + value_type = 'int',
159 + description = "max number of log entries to buffer",
160 ),
161
162
163 @@ -122,22 +174,40 @@ CONFIG_ENTRY_MAP = dict (
164 # == overlay ==
165
166 # FIXME key is not in use
167 - ebuild_header = is_fs_file,
168 + ebuild_header = dict (
169 + value_type = fs_file,
170 + description = '''NOT IN USE.
171 + ebuild header file that will be included in every created ebuild.
172 + ''',
173 + ),
174
175 - overlay_category = '', # e.g. 'sci-R'
176 - overlay_dir = only_vtype ( 'fs_abs:fs_dir' ),
177 + overlay_category = dict (
178 + desc = "overlay category to use for created ebuilds, e.g. 'sci-R'.",
179 + ),
180 + overlay_dir = dict (
181 + value_type = 'fs_abs:fs_dir',
182 + description = '''overlay root directory where the
183 + ebuilds, profiles/ dir, etc. will be written to.
184 + '''
185 + ),
186
187 overlay_eclass = dict (
188 - path = [ 'OVERLAY', 'eclass_files' ],
189 - value_type = fs_abslist,
190 + path = [ 'OVERLAY', 'eclass_files' ],
191 + value_type = fs_abslist,
192 + description = '''eclass files to import into the overlay.
193 + Automatically inherited in ebuilds.
194 + ''',
195 ),
196
197 - overlay_name = '',
198 + overlay_name = dict (
199 + desc = "overlay name, e.g. 'R-Overlay'.",
200 + ),
201
202 # ebuild is used to create Manifest files
203 ebuild_prog = dict (
204 - path = [ 'TOOLS', 'ebuild_prog' ],
205 - value_type = 'fs_path',
206 + path = [ 'TOOLS', 'ebuild_prog' ],
207 + value_type = 'fs_path',
208 + description = "name of/path to the ebuild executable",
209 ),
210
211 # * alias
212 @@ -151,18 +221,25 @@ CONFIG_ENTRY_MAP = dict (
213 # the distfiles root directory
214 # this is where repos create their own DISTDIR as sub directory unless
215 # they specify another location
216 - distfiles_root = only_vtype ( 'fs_dir' ),
217 + distfiles_root = dict (
218 + value_type = 'fs_dir',
219 + description = '''distfiles root,
220 + repos will create their distdirs in this directory.
221 + ''',
222 + ),
223
224 # the repo config file(s)
225 repo_config_files = dict (
226 - path = [ 'REPO', 'config_files' ],
227 - value_type = fs_abslist,
228 + path = [ 'REPO', 'config_files' ],
229 + value_type = fs_abslist,
230 + description = 'list of repo config files',
231 ),
232
233 # this option is used to limit bandwidth usage while running rsync
234 rsync_bwlimit = dict (
235 - path = [ 'rsync_bwlimit' ],
236 - value_type = 'int',
237 + path = [ 'rsync_bwlimit' ],
238 + value_type = 'int',
239 + description = "max average rsync bandwidth usage (in kilobytes/second)"
240 ),
241
242 # * alias
243 @@ -178,8 +255,9 @@ CONFIG_ENTRY_MAP = dict (
244
245 # the list of simple dep rule files
246 simple_rules_files = dict (
247 - path = [ 'DEPRES', 'SIMPLE_RULES', 'files' ],
248 - value_type = fs_abslist,
249 + path = [ 'DEPRES', 'SIMPLE_RULES', 'files' ],
250 + value_type = fs_abslist,
251 + description = "list of dependency rule files",
252 ),
253
254 # * alias
255 @@ -191,15 +269,19 @@ CONFIG_ENTRY_MAP = dict (
256 # == description reader ==
257
258 field_definition_file = dict (
259 - path = [ 'DESCRIPTION', 'field_definition_file' ],
260 - value_type = fs_file,
261 + path = [ 'DESCRIPTION', 'field_definition_file' ],
262 + value_type = fs_file,
263 + description = "config file that controls DESCRIPTION file reading",
264 ),
265
266 # * for debugging
267 # if set: write _all_ description files to dir/<package_filename>
268 description_descfiles_dir = dict (
269 - path = [ 'DESCRIPTION', 'descfiles_dir' ],
270 - value_type = 'fs_abs:fs_dir',
271 + path = [ 'DESCRIPTION', 'descfiles_dir' ],
272 + value_type = 'fs_abs:fs_dir',
273 + description = '''if set: write description files (read from tarballs)
274 + into this directory. Leave blank / comment out to disable.
275 + '''
276 ),
277
278 # * alias
279 @@ -213,3 +295,13 @@ CONFIG_ENTRY_MAP = dict (
280 del fs_file, fs_abslist, is_fs_file, is_yesno, is_log_level, \
281 CAPSLOCK, LOG_LEVEL, only_vtype
282
283 +def prune_description():
284 + for entry in CONFIG_ENTRY_MAP.values():
285 + if isinstance ( entry, dict ):
286 +
287 + if 'description' in entry:
288 + del entry ['description']
289 + elif 'desc' in entry:
290 + del entry ['desc']
291 +
292 +
293
294 diff --git a/roverlay/config/entryutil.py b/roverlay/config/entryutil.py
295 new file mode 100644
296 index 0000000..dfa7647
297 --- /dev/null
298 +++ b/roverlay/config/entryutil.py
299 @@ -0,0 +1,44 @@
300 +import re
301 +import textwrap
302 +
303 +from roverlay.config.entrymap import CONFIG_ENTRY_MAP
304 +
305 +def _iter_entries():
306 + for entry_key, entry in CONFIG_ENTRY_MAP.items():
307 + name = entry_key.upper()
308 + if entry is None:
309 + # entry is disabled
310 + pass
311 + elif isinstance ( entry, dict ):
312 + if 'description' in entry:
313 + yield ( name, entry ['description'] )
314 + elif 'desc' in entry:
315 + yield ( name, entry ['desc'] )
316 + else:
317 + yield ( name, )
318 + elif isinstance ( entry, str ) and entry:
319 + yield ( name, "alias to " + entry.upper() )
320 + else:
321 + yield ( name, )
322 +
323 +
324 +def list_entries ( newline_after_entry=True ):
325 + wrapper = textwrap.TextWrapper (
326 + initial_indent = 2 * ' ',
327 + subsequent_indent = 3 * ' ',
328 + #width = 75,
329 + )
330 + remove_ws = re.compile ( "\s+" )
331 + wrap = wrapper.wrap
332 +
333 + lines = list()
334 + for entry in sorted ( _iter_entries(), key = lambda x : x[0] ):
335 + lines.append ( entry [0] )
336 + if len ( entry ) > 1:
337 + lines.extend ( wrap ( remove_ws.sub ( ' ', entry [1] ) ) )
338 +
339 + if newline_after_entry:
340 + lines.append ( '' )
341 +
342 + return '\n'.join ( lines )
343 +