Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snf-image-creator
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
itminedu
snf-image-creator
Commits
46544c32
Commit
46544c32
authored
12 years ago
by
Nikos Skalkotos
Browse files
Options
Downloads
Patches
Plain Diff
Check if stdout is a tty
If not then don't output progressbars and colors
parent
08f26796
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
image_creator/main.py
+8
-4
8 additions, 4 deletions
image_creator/main.py
image_creator/output.py
+36
-12
36 additions, 12 deletions
image_creator/output.py
with
44 additions
and
16 deletions
image_creator/main.py
+
8
−
4
View file @
46544c32
...
...
@@ -37,7 +37,8 @@ from image_creator import __version__ as version
from
image_creator
import
util
from
image_creator.disk
import
Disk
from
image_creator.util
import
get_command
,
FatalError
,
MD5
from
image_creator.output
import
Output
,
Output_with_progress
,
Silent
,
error
from
image_creator.output
import
Output
,
Output_wth_progress
,
Silent
,
\
Silent_wth_colors
,
error
from
image_creator.os_type
import
get_os_class
from
image_creator.kamaki_wrapper
import
Kamaki
import
sys
...
...
@@ -159,9 +160,9 @@ def image_creator():
"
must be set
"
)
if
options
.
silent
:
out
=
Silent
()
out
=
Silent_wth_colors
()
if
sys
.
stdout
.
isatty
()
else
Silent
()
else
:
out
=
Output_w
i
th_progress
()
out
=
Output_wth_progress
()
if
sys
.
stdout
.
isatty
()
else
Output
()
title
=
'
snf-image-creator %s
'
%
version
out
.
output
(
title
)
...
...
@@ -281,7 +282,10 @@ def main():
ret
=
image_creator
()
sys
.
exit
(
ret
)
except
FatalError
as
e
:
error
(
e
)
if
sys
.
stdout
.
isatty
():
error
(
e
)
else
:
error
(
e
,
True
,
False
)
sys
.
exit
(
1
)
...
...
This diff is collapsed.
Click to expand it.
image_creator/output.py
+
36
−
12
View file @
46544c32
...
...
@@ -36,19 +36,28 @@ from progress.bar import Bar
from
colors
import
red
,
green
,
yellow
def
error
(
msg
,
new_line
=
True
):
def
error
(
msg
,
new_line
=
True
,
color
=
True
):
nl
=
"
\n
"
if
new_line
else
''
sys
.
stderr
.
write
(
red
(
'
Error: %s
'
%
msg
)
+
nl
)
if
color
:
sys
.
stderr
.
write
(
red
(
'
Error: %s
'
%
msg
)
+
nl
)
else
:
sys
.
stderr
.
write
(
'
Error: %s
'
%
msg
+
nl
)
def
warn
(
msg
,
new_line
=
True
):
def
warn
(
msg
,
new_line
=
True
,
color
=
True
):
nl
=
"
\n
"
if
new_line
else
''
sys
.
stderr
.
write
(
yellow
(
"
Warning: %s
"
%
msg
)
+
nl
)
if
color
:
sys
.
stderr
.
write
(
yellow
(
"
Warning: %s
"
%
msg
)
+
nl
)
else
:
sys
.
stderr
.
write
(
"
Warning: %s
"
%
msg
+
nl
)
def
success
(
msg
,
new_line
=
True
):
def
success
(
msg
,
new_line
=
True
,
color
=
True
):
nl
=
"
\n
"
if
new_line
else
''
sys
.
stdout
.
write
(
green
(
msg
)
+
nl
)
if
color
:
sys
.
stdout
.
write
(
green
(
msg
)
+
nl
)
else
:
sys
.
stdout
.
write
(
msg
+
nl
)
if
not
nl
:
sys
.
stdout
.
flush
()
...
...
@@ -62,13 +71,13 @@ def output(msg='', new_line=True):
class
Output
(
object
):
def
error
(
self
,
msg
,
new_line
=
True
):
error
(
msg
,
new_line
)
error
(
msg
,
new_line
,
False
)
def
warn
(
self
,
msg
,
new_line
=
True
):
warn
(
msg
,
new_line
)
warn
(
msg
,
new_line
,
False
)
def
success
(
self
,
msg
,
new_line
=
True
):
success
(
msg
,
new_line
)
success
(
msg
,
new_line
,
False
)
def
output
(
self
,
msg
=
''
,
new_line
=
True
):
output
(
msg
,
new_line
)
...
...
@@ -100,7 +109,18 @@ class Output(object):
return
generator
class
Output_with_progress
(
Output
):
class
Output_wth_colors
(
Output
):
def
error
(
self
,
msg
,
new_line
=
True
):
error
(
msg
,
new_line
)
def
warn
(
self
,
msg
,
new_line
=
True
):
warn
(
msg
,
new_line
)
def
success
(
self
,
msg
,
new_line
=
True
):
success
(
msg
,
new_line
)
class
Output_wth_progress
(
Output_wth_colors
):
class
Progress
(
Bar
):
MESSAGE_LENGTH
=
30
...
...
@@ -113,7 +133,7 @@ class Output_with_progress(Output):
}
def
__init__
(
self
,
title
,
bar_type
=
'
default
'
):
super
(
Output_w
i
th_progress
.
Progress
,
self
).
__init__
()
super
(
Output_wth_progress
.
Progress
,
self
).
__init__
()
self
.
title
=
title
self
.
fill
=
'
#
'
self
.
bar_prefix
=
'
[
'
...
...
@@ -137,10 +157,14 @@ class Silent(Output):
pass
class
Progress
(
Output
.
Progress
):
def
__init__
(
self
,
title
,
bar_type
):
def
__init__
(
self
,
title
,
bar_type
=
'
default
'
):
pass
def
success
(
self
,
result
):
pass
class
Silent_wth_colors
(
Silent
):
def
error
(
self
,
msg
,
new_line
=
True
):
error
(
msg
,
new_line
)
# vim: set sta sts=4 shiftwidth=4 sw=4 et ai :
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment