Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
genotoul-bioinfo
jflow
Commits
bfae822e
Commit
bfae822e
authored
Sep 16, 2014
by
Jerome Mariette
Browse files
handle color with html email
parent
b0792588
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/jflow/workflow.py
View file @
bfae822e
...
@@ -303,7 +303,7 @@ class Workflow(threading.Thread):
...
@@ -303,7 +303,7 @@ class Workflow(threading.Thread):
for
arg
in
arg_lines
:
for
arg
in
arg_lines
:
yield
arg
yield
arg
def
get_status_under_text_format
(
self
,
detailed
=
False
,
display_errors
=
False
):
def
get_status_under_text_format
(
self
,
detailed
=
False
,
display_errors
=
False
,
html
=
False
):
if
self
.
start_time
:
start_time
=
time
.
asctime
(
time
.
localtime
(
self
.
start_time
))
if
self
.
start_time
:
start_time
=
time
.
asctime
(
time
.
localtime
(
self
.
start_time
))
else
:
start_time
=
"-"
else
:
start_time
=
"-"
if
self
.
start_time
and
self
.
end_time
:
elapsed_time
=
str
(
self
.
end_time
-
self
.
start_time
)
if
self
.
start_time
and
self
.
end_time
:
elapsed_time
=
str
(
self
.
end_time
-
self
.
start_time
)
...
@@ -319,7 +319,8 @@ class Workflow(threading.Thread):
...
@@ -319,7 +319,8 @@ class Workflow(threading.Thread):
worflow_errors
=
""
worflow_errors
=
""
error
=
self
.
get_errors
()
error
=
self
.
get_errors
()
if
error
is
not
None
:
if
error
is
not
None
:
worflow_errors
=
"Workflow Error :
\n
\033
[91m"
+
error
[
"location"
]
+
"
\n
"
+
"
\n
"
.
join
(
error
[
"msg"
])
+
"
\033
[0m"
if
html
:
worflow_errors
=
"Workflow Error :
\n
<span style='color:#ff0000'>"
+
error
[
"location"
]
+
"
\n
"
+
"
\n
"
.
join
(
error
[
"msg"
])
+
"</span>"
else
:
worflow_errors
=
"Workflow Error :
\n
\033
[91m"
+
error
[
"location"
]
+
"
\n
"
+
"
\n
"
.
join
(
error
[
"msg"
])
+
"
\033
[0m"
# By components
# By components
components_errors
=
""
components_errors
=
""
status
=
"Components Status :
\n
"
status
=
"Components Status :
\n
"
...
@@ -336,15 +337,25 @@ class Workflow(threading.Thread):
...
@@ -336,15 +337,25 @@ class Workflow(threading.Thread):
try
:
perc_completed
=
(
status_info
[
"completed"
]
*
100.0
)
/
status_info
[
"tasks"
]
try
:
perc_completed
=
(
status_info
[
"completed"
]
*
100.0
)
/
status_info
[
"tasks"
]
except
:
perc_completed
=
0
except
:
perc_completed
=
0
if
status_info
[
"running"
]
>
0
:
running
=
"
\033
[94mrunning:"
+
str
(
status_info
[
"running"
])
+
"
\033
[0m"
if
status_info
[
"running"
]
>
0
:
if
html
:
running
=
"<span style='color:#3b3bff'>running:"
+
str
(
status_info
[
"running"
])
+
"</span>"
else
:
running
=
"
\033
[94mrunning:"
+
str
(
status_info
[
"running"
])
+
"
\033
[0m"
else
:
running
=
"running:"
+
str
(
status_info
[
"running"
])
else
:
running
=
"running:"
+
str
(
status_info
[
"running"
])
if
status_info
[
"waiting"
]
>
0
:
waiting
=
"
\033
[93mwaiting:"
+
str
(
status_info
[
"waiting"
])
+
"
\033
[0m"
if
status_info
[
"waiting"
]
>
0
:
if
html
:
waiting
=
"<span style='color:#ffea00'>waiting:"
+
str
(
status_info
[
"waiting"
])
+
"</span>"
else
:
waiting
=
"
\033
[93mwaiting:"
+
str
(
status_info
[
"waiting"
])
+
"
\033
[0m"
else
:
waiting
=
"waiting:"
+
str
(
status_info
[
"waiting"
])
else
:
waiting
=
"waiting:"
+
str
(
status_info
[
"waiting"
])
if
status_info
[
"failed"
]
>
0
:
failed
=
"
\033
[91mfailed:"
+
str
(
status_info
[
"failed"
])
+
"
\033
[0m"
if
status_info
[
"failed"
]
>
0
:
if
html
:
failed
=
"<span style='color:#ff0000'>failed:"
+
str
(
status_info
[
"failed"
])
+
"</span>"
else
:
failed
=
"
\033
[91mfailed:"
+
str
(
status_info
[
"failed"
])
+
"
\033
[0m"
else
:
failed
=
"failed:"
+
str
(
status_info
[
"failed"
])
else
:
failed
=
"failed:"
+
str
(
status_info
[
"failed"
])
if
status_info
[
"aborted"
]
>
0
:
aborted
=
"
\033
[95maborted:"
+
str
(
status_info
[
"aborted"
])
+
"
\033
[0m"
if
status_info
[
"aborted"
]
>
0
:
if
html
:
aborted
=
"<span style='color:#ff01ba'>aborted:"
+
str
(
status_info
[
"aborted"
])
+
"</span>"
else
:
aborted
=
"
\033
[95maborted:"
+
str
(
status_info
[
"aborted"
])
+
"
\033
[0m"
else
:
aborted
=
"aborted:"
+
str
(
status_info
[
"aborted"
])
else
:
aborted
=
"aborted:"
+
str
(
status_info
[
"aborted"
])
if
status_info
[
"completed"
]
==
status_info
[
"tasks"
]
and
status_info
[
"completed"
]
>
0
:
completed
=
"
\033
[92mcompleted:"
+
str
(
status_info
[
"completed"
])
+
"
\033
[0m"
if
status_info
[
"completed"
]
==
status_info
[
"tasks"
]
and
status_info
[
"completed"
]
>
0
:
if
html
:
completed
=
"<span style='color:#14ac00'>completed:"
+
str
(
status_info
[
"completed"
])
+
"</span>"
else
:
completed
=
"
\033
[92mcompleted:"
+
str
(
status_info
[
"completed"
])
+
"
\033
[0m"
else
:
completed
=
"completed:"
+
str
(
status_info
[
"completed"
])
else
:
completed
=
"completed:"
+
str
(
status_info
[
"completed"
])
if
display_errors
and
len
(
status_info
[
"failed_commands"
])
>
0
:
if
display_errors
and
len
(
status_info
[
"failed_commands"
])
>
0
:
...
@@ -360,7 +371,8 @@ class Workflow(threading.Thread):
...
@@ -360,7 +371,8 @@ class Workflow(threading.Thread):
pretty_str
+=
(
"
\n
"
+
worflow_errors
)
if
worflow_errors
!=
""
else
""
pretty_str
+=
(
"
\n
"
+
worflow_errors
)
if
worflow_errors
!=
""
else
""
pretty_str
+=
(
"
\n
"
+
status
)
if
status
!=
""
else
""
pretty_str
+=
(
"
\n
"
+
status
)
if
status
!=
""
else
""
pretty_str
+=
(
"
\n
"
+
components_errors
)
if
components_errors
!=
""
else
""
pretty_str
+=
(
"
\n
"
+
components_errors
)
if
components_errors
!=
""
else
""
return
pretty_str
if
html
:
return
pretty_str
.
replace
(
"
\n
"
,
"<br />"
)
else
:
return
pretty_str
else
:
else
:
return
utils
.
get_nb_string
(
self
.
id
)
+
"
\t
"
+
self
.
name
+
"
\t
"
+
self
.
get_status
()
+
\
return
utils
.
get_nb_string
(
self
.
id
)
+
"
\t
"
+
self
.
name
+
"
\t
"
+
self
.
get_status
()
+
\
"
\t
"
+
elapsed_time
+
"
\t
"
+
start_time
+
"
\t
"
+
end_time
"
\t
"
+
elapsed_time
+
"
\t
"
+
start_time
+
"
\t
"
+
end_time
...
@@ -450,8 +462,8 @@ class Workflow(threading.Thread):
...
@@ -450,8 +462,8 @@ class Workflow(threading.Thread):
# the text file contains only ASCII characters.
# the text file contains only ASCII characters.
# Create a text/plain message
# Create a text/plain message
if
not
message
:
if
not
message
:
message
=
self
.
get_status_under_text_format
(
True
,
True
)
message
=
self
.
get_status_under_text_format
(
True
,
True
,
True
)
msg
=
MIMEText
(
message
)
msg
=
MIMEText
(
message
,
'html'
)
me
=
froma
me
=
froma
you
=
toa
you
=
toa
if
not
subject
:
subject
=
"JFlow - Workflow #"
+
str
(
self
.
id
)
+
" is "
+
self
.
status
if
not
subject
:
subject
=
"JFlow - Workflow #"
+
str
(
self
.
id
)
+
" is "
+
self
.
status
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment