Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
ipaaca
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
Ramin Yaghoubzadeh Torky
ipaaca
Commits
521321f4
Commit
521321f4
authored
8 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
ipaaca-catlog: can output to file; plain or colorized html (rudimentary)
parent
f48ac6b8
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipaacatools/scripts/ipaaca-catlog
+106
-1
106 additions, 1 deletion
ipaacatools/scripts/ipaaca-catlog
with
106 additions
and
1 deletion
ipaacatools/scripts/ipaaca-catlog
+
106
−
1
View file @
521321f4
...
@@ -37,6 +37,7 @@ from __future__ import division, print_function
...
@@ -37,6 +37,7 @@ from __future__ import division, print_function
import sys
import sys
import ipaaca
import ipaaca
import traceback
import traceback
import io
def pretty_printed_time(t):
def pretty_printed_time(t):
if t
<
0
:
if t
<
0
:
...
@@ -51,6 +52,91 @@ def pretty_printed_time(t):
...
@@ -51,6 +52,91 @@ def pretty_printed_time(t):
ms =
int((s-int(s))*1000)
ms =
int((s-int(s))*1000)
return
sign
+'%01
d:
%02
d:
%02
d.
%03
d
'%(
h
,
m
,
int
(
s
),
ms
)
return
sign
+'%01
d:
%02
d:
%02
d.
%03
d
'%(
h
,
m
,
int
(
s
),
ms
)
REPLACEMENT_COLORS=
{
'30'
:
'
black
',
'31'
:
'
red
',
'32'
:
'
green
',
'33'
:
'
cyan
',
'34'
:
'
blue
',
'35'
:
'
brown
',
'36'
:
'
magenta
',
'37'
:
'
grey
',
'248'
:
'
lightgray
',
#
should
add
more
colors
}
def
replace_ansi_html
(
s
)
:
r =
u''
in_esc =
False
last_color =
u''
#skip_one_double_wide_bar
=
False
for
c
in
s:
if
in_esc:
if
c=
='m':
in_esc =
False
itms =
last_color.replace('[','').replace(']','').split(';')
col =
None
bold =
False
if
itms[0]=
='':
r
+=
'</
code
></font><code>
'
else:
for i in itms:
if i=='1':
bold = True
elif i in REPLACEMENT_COLORS:
col = REPLACEMENT_COLORS[i]
if col is None:
if bold:
col = 'grey'
else:
col = 'black'
print('Warning: unknown colors '+str(itms))
r += '
</code><font
color=
"'+col+'"
><code>
'
else:
last_color += c
else:
#if c in u'▁▂▃▄▅▆▇█':
# if skip_one_double_wide_bar:
# skip_one_double_wide_bar = False
# else:
# r += c
# skip_one_double_wide_bar = True
#el
if c=='':
in_esc = True
last_color = ''
else:
r += c
return r
def print_header(formt, fields):
s = u''
if formt=='html':
s += '
<html><head><meta
charset=
"UTF-8"
><title>
flexdiam log view
</title></head>
\n
<body>
\n
<table
width=
"100%"
border=
"1"
bordercolor=
"lightgray"
style=
"white-space:pre"
>
\n
<tr>
'
for f in fields:
s+='
<th>
'+f+'
</th>
'
s += '
</tr>
'
return s
def print_footer(formt):
s = u''
if formt=='html':
s += '
</tr>
\n
</body>
\n
</html>
'
return s
def print_record(data, delimiter, formt):
if formt=='html':
s = u'
<tr>
'
for d in data:
d2 = d.replace('
<
',
'&
lt
;').
replace
('
>
', '
>
').replace('\n', '
<br/>
').replace('"', '
"
')
d3 = replace_ansi_html(d2)
#s += u'
<td><code>
' + d2.replace('
<
',
'&
lt
;').
replace
('
>
', '
>
').replace('\n', '
<br/>
') + u'
</code></td>
'
s += u'
<td><code>
' + d3 + u'
</code></td>
'
s += u'
</tr>
'
return s
else:
return delimiter.join(data)
def modify(key, value, strip=False, pretty_printed_times=False, time_offset=0.0):
def modify(key, value, strip=False, pretty_printed_times=False, time_offset=0.0):
if key=='time':
if key=='time':
f = float(value.strip()) - time_offset
f = float(value.strip()) - time_offset
...
@@ -71,6 +157,16 @@ if __name__=='__main__':
...
@@ -71,6 +157,16 @@ if __name__=='__main__':
dest='pretty_printed_times', action='store_true',
dest='pretty_printed_times', action='store_true',
default=False,
default=False,
help='Print human-readable times (hh:mm:ss.ms) instead of float seconds')
help='Print human-readable times (hh:mm:ss.ms) instead of float seconds')
iap.add_argument(
'--format',
dest='format', nargs=1,
default=['plain'],
help='output format (plain, html) (default plain)')
iap.add_argument(
'-o', '--output-file',
dest='output_file', nargs=1,
default=['-'],
help='output file name (default \'-\' -> standard terminal output)')
iap.add_argument(
iap.add_argument(
'-d', '--delimiter',
'-d', '--delimiter',
dest='delimiter', nargs=1,
dest='delimiter', nargs=1,
...
@@ -92,9 +188,18 @@ if __name__=='__main__':
...
@@ -92,9 +188,18 @@ if __name__=='__main__':
#print(arguments); sys.exit(1)
#print(arguments); sys.exit(1)
#modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s)
#modify = (lambda s: s.strip()) if arguments.strip else (lambda s: s)
#modify = lambda s: type(s).__name__
#modify = lambda s: type(s).__name__
fil = sys.stdout
if arguments.output_file[0] != '-':
fil = io.open(arguments.output_file[0], 'w', encoding='utf8')
fil.write(print_header(arguments.format[0], arguments.fields)+'\n')
for line in sys.stdin:
for line in sys.stdin:
record = eval(line.strip(), {"__builtins__":None}, {} )
record = eval(line.strip(), {"__builtins__":None}, {} )
print
(
delimiter
.
join
([
modify
(
f
,
unicode
(
record
[
f
]),
arguments
.
strip
,
arguments
.
pretty_printed_times
,
time_offset
)
for
f
in
arguments
.
fields
]))
data = [modify(f, unicode(record[f]), arguments.strip, arguments.pretty_printed_times, time_offset) for f in arguments.fields]
u = print_record(data, delimiter, arguments.format[0])
res = u'{}'.format(u) #.decode('utf-8')
fil.write(u''+res+'\n' )
fil.write(print_footer(arguments.format[0])+'\n')
if fil != sys.stdout: fil.close()
except (KeyboardInterrupt, SystemExit):
except (KeyboardInterrupt, SystemExit):
pass # ret below
pass # ret below
except Exception, e:
except Exception, e:
...
...
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