diff options
| author | Brian Dolbec <brian.dolbec@gmail.com> | 2011-01-25 00:28:32 -0800 |
|---|---|---|
| committer | Brian Dolbec <brian.dolbec@gmail.com> | 2011-01-25 00:28:32 -0800 |
| commit | e680f6a3acb1dd4af0f1d85532116ec7ed7855de (patch) | |
| tree | 940a81c4cc4e3a0431cb480fa1f249fac105bae0 | |
| parent | 436ded8a7e9e32b419d0f0423d2b4da1c3ca77d2 (diff) | |
| download | gentoolkit-e680f6a3acb1dd4af0f1d85532116ec7ed7855de.tar.gz | |
Add a new cpv and values textwrapping class
| -rw-r--r-- | pym/gentoolkit/formatters.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/pym/gentoolkit/formatters.py b/pym/gentoolkit/formatters.py index 413a1c8..c0a1747 100644 --- a/pym/gentoolkit/formatters.py +++ b/pym/gentoolkit/formatters.py @@ -97,3 +97,42 @@ def format_timestamp(timestamp): return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(timestamp))) +class CpvValueWrapper(object): + """Format a cpv and linewrap pre-formatted values""" + + def __init__(self, cpv_width=None, width=None): + self.cpv_width = cpv_width + if width is None: + width = gentoolkit.CONFIG['termWidth'] + self.twrap = TextWrapper(width=width) + #self.init_indent = len(self.spacer) + + def _format_values(self, key, values): + """Format entry values ie. USE flags, keywords,... + + @type key: str + @param key: a pre-formatted cpv + @type values: list of pre-formatted strings + @param values: ['flag1', 'flag2',...] + @rtype: str + @return: formatted options string + """ + + result = [] + if self.cpv_width > 1: + _cpv = pp.cpv(key+'.'*(self.cpv_width-len(key))) + if not len(values): + return _cpv + self.twrap.initial_indent = _cpv + self.twrap.subsequent_indent = " " * (self.cpv_width+1) + else: + _cpv = pp.cpv(key+' ') + if not len(values): + return _cpv + self.twrap.initial_indent = _cpv + self.twrap.subsequent_indent = " " * (len(key)+1) + + result.append(self.twrap.fill(values)) + return '\n'.join(result) + + |
