projects
/
snf-image-creator
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Don't execute syspreps if the fs is not mounted rw
[snf-image-creator]
/
image_creator
/
output
/
cli.py
diff --git
a/image_creator/output/cli.py
b/image_creator/output/cli.py
index
c7b5a55
..
f88fdbf
100644
(file)
--- a/
image_creator/output/cli.py
+++ b/
image_creator/output/cli.py
@@
-31,6
+31,8
@@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
+"""Normal Command-line interface output"""
+
from image_creator.output import Output
import sys
from image_creator.output import Output
import sys
@@
-38,48
+40,68
@@
from colors import red, green, yellow
from progress.bar import Bar
from progress.bar import Bar
-def output(msg='', new_line=True, decorate=lambda x: x):
+def output(msg, new_line, decorate, stream):
nl = "\n" if new_line else ' '
nl = "\n" if new_line else ' '
- sys.stderr.write(decorate(msg) + nl)
+ stream.write(decorate(msg) + nl)
-def error(msg, new_line=True, colored=True):
+def error(msg, new_line, colored, stream):
color = red if colored else lambda x: x
color = red if colored else lambda x: x
- output("Error: %s" % msg, new_line, color)
+ output("Error: %s" % msg, new_line, color, stream)
-def warn(msg, new_line=True, colored=True):
+def warn(msg, new_line, colored, stream):
color = yellow if colored else lambda x: x
color = yellow if colored else lambda x: x
- output("Warning: %s" % msg, new_line, color)
+ output("Warning: %s" % msg, new_line, color, stream)
-def success(msg, new_line=True, colored=True):
+def success(msg, new_line, colored, stream):
color = green if colored else lambda x: x
color = green if colored else lambda x: x
- output(msg, new_line, color)
+ output(msg, new_line, color, stream)
+
+
+def clear(stream):
+ #clear the page
+ if stream.isatty():
+ stream.write('\033[H\033[2J')
class SilentOutput(Output):
class SilentOutput(Output):
+ """Silent Output class. Only Errors are printed"""
pass
class SimpleOutput(Output):
pass
class SimpleOutput(Output):
- def __init__(self, colored=True):
+ """Print messages but not progress bars. Progress bars are treated as
+ output messages. The user gets informed when the action begins and when it
+ ends, but no progress is shown in between."""
+ def __init__(self, colored=True, stream=None):
self.colored = colored
self.colored = colored
+ self.stream = sys.stderr if stream is None else stream
def error(self, msg, new_line=True):
def error(self, msg, new_line=True):
- error(msg, new_line, self.colored)
+ """Print an error"""
+ error(msg, new_line, self.colored, self.stream)
def warn(self, msg, new_line=True):
def warn(self, msg, new_line=True):
- warn(msg, new_line, self.colored)
+ """Print a warning"""
+ warn(msg, new_line, self.colored, self.stream)
def success(self, msg, new_line=True):
def success(self, msg, new_line=True):
- success(msg, new_line, self.colored)
+ """Print msg after an action is completed"""
+ success(msg, new_line, self.colored, self.stream)
def output(self, msg='', new_line=True):
def output(self, msg='', new_line=True):
- output(msg, new_line)
+ """Print msg as normal program output"""
+ output(msg, new_line, lambda x: x, self.stream)
+
+ def clear(self):
+ """Clear the screen"""
+ clear(self.stream)
class OutputWthProgress(SimpleOutput):
class OutputWthProgress(SimpleOutput):
+ """Output class with progress."""
class _Progress(Bar):
MESSAGE_LENGTH = 30
class _Progress(Bar):
MESSAGE_LENGTH = 30
@@
-92,6
+114,8
@@
class OutputWthProgress(SimpleOutput):
}
def __init__(self, size, title, bar_type='default'):
}
def __init__(self, size, title, bar_type='default'):
+ """Create a Progress bar"""
+ self.hide_cursor = False
super(OutputWthProgress._Progress, self).__init__()
self.title = title
self.fill = '#'
super(OutputWthProgress._Progress, self).__init__()
self.title = title
self.fill = '#'
@@
-101,12
+125,12
@@
class OutputWthProgress(SimpleOutput):
self.suffix = self.template[bar_type]
self.max = size
self.suffix = self.template[bar_type]
self.max = size
- # print empty progress bar workaround
- self.goto(1)
+ # print empty progress bar
+ self.start()
def success(self, result):
def success(self, result):
- self.output.output("\r%s...\033[K" % self.title, False)
+ """Print result after progress has finished"""
+ self.output.output("\r%s ...\033[K" % self.title, False)
self.output.success(result)
self.output.success(result)
-
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :