Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aladdin
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
gene
aladdin
Commits
7ab8a38f
Commit
7ab8a38f
authored
6 years ago
by
Christian Eichler
Browse files
Options
Downloads
Patches
Plain Diff
Log: Cleanup / add type annotations
parent
a0025e68
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Helper/Log.py
+16
-21
16 additions, 21 deletions
Helper/Log.py
with
16 additions
and
21 deletions
Helper/Log.py
+
16
−
21
View file @
7ab8a38f
...
...
@@ -18,43 +18,46 @@ def __print(line: str, end='\n', silent=False):
if
not
__silent
and
not
silent
:
print
(
line
,
end
=
end
)
@typechecked
def
__write
(
line
:
str
)
->
None
:
if
__fh
!=
None
:
__fh
.
write
(
'
\033
[1;35m
'
+
str
(
datetime
.
datetime
.
now
())
+
'
\033
[1;m
'
+
line
+
'
\n
'
)
__fh
.
flush
()
def
set_logfile
(
fpath
):
@typechecked
def
set_logfile
(
fpath
:
str
)
->
None
:
global
__fpath
global
__fh
__fpath
=
fpath
__fh
=
open
(
fpath
,
'
w
'
)
def
fail
(
msg
:
str
,
silent
=
False
):
@typechecked
def
fail
(
msg
:
str
,
silent
=
False
)
->
None
:
for
line
in
msg
.
splitlines
():
__print
(
red
(
'
[fail]
'
)
+
'
'
+
line
,
silent
=
silent
)
__write
(
red
(
'
[fail]
'
)
+
'
'
+
line
)
def
warn
(
msg
:
str
,
silent
=
False
):
def
warn
(
msg
:
str
,
silent
=
False
)
->
None
:
for
line
in
msg
.
splitlines
():
__print
(
yellow
(
'
[warn]
'
)
+
'
'
+
line
,
silent
=
silent
)
__write
(
yellow
(
'
[warn]
'
)
+
'
'
+
line
)
def
info
(
msg
:
str
,
silent
=
False
):
def
info
(
msg
:
str
,
silent
=
False
)
->
None
:
for
line
in
msg
.
splitlines
():
__print
(
blue
(
'
[info]
'
)
+
'
'
+
line
,
silent
=
silent
)
__write
(
blue
(
'
[info]
'
)
+
'
'
+
line
)
def
debug
(
msg
:
str
):
def
debug
(
msg
:
str
)
->
None
:
# debug does not print to std*
for
line
in
msg
.
splitlines
():
__write
(
pink
(
'
[debg]
'
)
+
'
'
+
line
)
def
operation_start
(
msg
:
str
,
silent
=
False
):
def
operation_start
(
msg
:
str
,
silent
=
False
)
->
None
:
__print
(
'
\r
'
+
yellow
(
'
[....]
'
)
+
'
'
+
msg
,
end
=
''
,
silent
=
silent
)
sys
.
stdout
.
flush
()
__write
(
blue
(
'
[strt]
'
)
+
'
'
+
msg
)
def
operation_end
(
msg
:
str
,
fail
=
False
,
silent
=
False
):
def
operation_end
(
msg
:
str
,
fail
=
False
,
silent
=
False
)
->
None
:
if
fail
:
__print
(
'
\r
'
+
red
(
'
[fail]
'
)
+
'
'
+
msg
,
silent
=
silent
)
__write
(
red
(
'
[fail]
'
)
+
'
'
+
msg
)
...
...
@@ -63,7 +66,7 @@ def operation_end(msg: str, fail=False, silent=False):
__write
(
green
(
'
[done]
'
)
+
'
'
+
msg
)
__last_start
=
None
def
start
(
msg
:
str
,
silent
=
False
):
def
start
(
msg
:
str
,
silent
=
False
)
->
None
:
global
__last_start
__last_start
=
msg
...
...
@@ -71,13 +74,10 @@ def start(msg: str, silent=False):
sys
.
stdout
.
flush
()
__write
(
blue
(
'
[strt]
'
)
+
'
'
+
msg
)
def
end
(
msg
:
str
=
None
,
fail
:
bool
=
False
,
silent
:
bool
=
False
):
def
end
(
msg
:
str
=
None
,
fail
:
bool
=
False
,
silent
:
bool
=
False
)
->
None
:
global
__last_start
if
None
==
msg
:
suffix
=
""
else
:
suffix
=
"
:
"
+
msg
suffix
=
""
if
msg
is
None
else
"
: {}
"
.
format
(
msg
)
assert
None
!=
__last_start
if
fail
:
...
...
@@ -89,10 +89,5 @@ def end(msg: str=None, fail: bool=False, silent: bool=False):
__last_start
=
None
def
get_longest
(
arr
:
List
[
str
]):
length
=
0
for
s
in
arr
:
if
length
<
len
(
s
):
length
=
len
(
s
)
return
length
def
get_longest
(
arr
:
List
[
str
])
->
int
:
return
max
([
len
(
s
)
for
s
in
arr
],
default
=
0
)
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