summaryrefslogtreecommitdiffstats
path: root/hostinfo/prefix.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-05-29 11:34:06 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-05-29 11:34:42 +0200
commitabd8e47f48de60a9ef07a5629e09dad5fb6945f5 (patch)
tree1ffcaa38a6a1daa66121ad4790c71b290ac44ae7 /hostinfo/prefix.py
parentbcf16599846f4fbce3b603231888b1aeb3aa3519 (diff)
downloadtools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.tar.gz
tools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.tar.bz2
tools-abd8e47f48de60a9ef07a5629e09dad5fb6945f5.zip
Printer: refactoring the whole thing for better pylint result0.1.9
Diffstat (limited to 'hostinfo/prefix.py')
-rw-r--r--hostinfo/prefix.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/hostinfo/prefix.py b/hostinfo/prefix.py
new file mode 100644
index 0000000..e9f0bf2
--- /dev/null
+++ b/hostinfo/prefix.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function
+
+class Printer:
+ flags = list()
+
+ def __init__(self, full_key='', printer=None):
+ if printer is None:
+ self.output = print
+ else:
+ self.output = printer.pprint
+
+ self.parent = printer
+ self.empty = 'oneline' in self.__class__.flags
+ self.full_key = full_key
+ self.has_output = False
+ self.label = ''
+
+ def set_label(self, label='', maxlength=0):
+ self.label = self._get_label(label, maxlength)
+
+ def _get_label(self, label, maxlength):
+ if label == '':
+ return label
+
+ label = "%s: " % label
+ if self.parent is not None and self.parent.full_key == '':
+ if 'nospaces' in self.__class__.flags:
+ return label.rjust(maxlength+4)
+ else:
+ return (label + " ").rjust(maxlength+6)
+ else:
+ return label.ljust(maxlength+2)
+
+ def pprint(self, data):
+ self.output("%s%s" % (self.label, data))
+ self.has_output = True
+ if not self.empty:
+ self.label = ' ' * len(self.label)
+ self.empty = True
+
+ def space(self, force=False):
+ if 'nospaces' not in self.__class__.flags:
+ if self.has_output or force:
+ self.output('')
+