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
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
Social Cognitive Systems
ipaaca
Commits
ea037e20
Commit
ea037e20
authored
11 years ago
by
Ramin Yaghoubzadeh Torky
Browse files
Options
Downloads
Patches
Plain Diff
tools: Improved sniffer (better formatting, color highlighting capability)
parent
6b0a1e0b
No related branches found
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-iu-sniffer.py
+54
-7
54 additions, 7 deletions
ipaacatools/scripts/ipaaca-iu-sniffer.py
with
54 additions
and
7 deletions
ipaacatools/scripts/ipaaca-iu-sniffer.py
+
54
−
7
View file @
ea037e20
...
@@ -33,23 +33,70 @@
...
@@ -33,23 +33,70 @@
import
logging
import
logging
import
sys
import
sys
import
time
import
time
import
ipaaca
import
ipaaca
color
=
False
max_size
=
2048
def
highlight_if_color
(
s
,
c
=
'
1
'
):
return
s
if
not
color
else
'
[
'
+
c
+
'
m
'
+
s
+
'
[m
'
def
pretty_printed_iu_payload
(
iu
):
s
=
'
{
'
for
k
,
v
in
iu
.
payload
.
items
():
v2
=
((
'
\'
'
+
v
+
'
\'
'
)
if
len
(
v
)
<=
max_size
else
(
'
\'
'
+
v
[:
max_size
]
+
'
\'
<excess length omitted>
'
)).
replace
(
'
\\
'
,
'
\\\\
'
).
replace
(
'
\n
'
,
highlight_if_color
(
'
\\
n
'
))
s
+=
'
\n
'
+
'
\t\t\'
'
+
highlight_if_color
(
unicode
(
k
),
'
1
'
)
+
'
\'
:
'
+
unicode
(
v2
)
+
'
,
'
s
+=
'
}
'
return
s
def
event_type_color
(
typ
):
colors
=
{
'
ADDED
'
:
'
32;1
'
,
'
RETRACTED
'
:
'
31;1
'
,
'
UPDATED
'
:
'
33;1
'
,
'
MESSAGE
'
:
'
34;1
'
}
return
'
1
'
if
typ
not
in
colors
else
colors
[
typ
]
def
pretty_printed_iu_event
(
iu
,
event_type
,
local
):
s
=
''
t
=
time
.
time
()
lt
=
time
.
localtime
(
t
)
s
+=
highlight_if_color
(
'
%.3f
'
%
t
,
'
1
'
)
+
'
'
+
"
%02d:%02d:%02d
"
%
(
lt
.
tm_hour
,
lt
.
tm_min
,
lt
.
tm_sec
)
s
+=
'
'
+
highlight_if_color
(
'
%-9s
'
%
event_type
,
event_type_color
(
event_type
))
+
'
category=
'
+
highlight_if_color
(
iu
.
category
,
event_type_color
(
event_type
))
+
'
uid=
'
+
iu
.
uid
+
'
owner=
'
+
iu
.
owner_name
+
'
payload=
'
+
pretty_printed_iu_payload
(
iu
)
return
s
def
my_update_handler
(
iu
,
event_type
,
local
):
def
my_update_handler
(
iu
,
event_type
,
local
):
t
=
time
.
localtime
()
t
=
time
.
localtime
()
print
"
%02d:%02d:%02d
"
%
(
t
.
tm_hour
,
t
.
tm_min
,
t
.
tm_sec
),
print
pretty_printed_iu_event
(
iu
,
event_type
,
local
)
print
time
.
time
(),
print
(
event_type
+
'
:
'
+
unicode
(
iu
))
cats
=
[]
cats
=
[]
if
len
(
sys
.
argv
)
>
1
:
cats
=
sys
.
argv
[
1
:]
keep_going
=
True
idx
=
1
while
keep_going
:
opt
=
sys
.
argv
[
idx
]
if
idx
<
len
(
sys
.
argv
)
else
None
if
opt
==
'
--help
'
:
print
(
'
IU sniffer - usage:
'
)
print
(
'
'
+
sys
.
argv
[
0
]
+
'
[--options] [<category1> [<category2 ...]]
'
)
print
(
'
Listen to specified categories (default: all)
'
)
print
(
'
Option --color : colorize output
'
)
print
(
'
Option --size-limit <size> : limit payload display, chars (def: 2048)
'
)
sys
.
exit
(
0
)
elif
opt
==
'
--color
'
:
color
=
True
idx
+=
1
elif
opt
==
'
--size-limit
'
:
if
len
(
sys
.
argv
)
<
idx
+
2
:
print
(
'
Please specify a max size
'
)
sys
.
exit
(
1
)
max_size
=
int
(
sys
.
argv
[
idx
+
1
])
idx
+=
2
else
:
cats
=
sys
.
argv
[
idx
:]
keep_going
=
False
ib
=
ipaaca
.
InputBuffer
(
'
SnifferIn
'
,
[
''
]
if
len
(
cats
)
==
0
else
cats
)
ib
=
ipaaca
.
InputBuffer
(
'
SnifferIn
'
,
[
''
]
if
len
(
cats
)
==
0
else
cats
)
ib
.
register_handler
(
my_update_handler
)
ib
.
register_handler
(
my_update_handler
)
print
(
"
Listening for IU events of
"
+
(
"
any category...
"
if
len
(
cats
)
==
0
else
"
categories:
"
+
'
'
.
join
(
cats
)))
print
(
''
)
print
(
'
Ipaaca IU Sniffer - run with --help to see options
'
)
print
(
'
Listening for IU events of
'
+
(
'
any category...
'
if
len
(
cats
)
==
0
else
'
categories:
'
+
'
'
.
join
(
cats
)))
print
(
''
)
print
(
''
)
while
True
:
while
True
:
time
.
sleep
(
1
)
time
.
sleep
(
1
)
...
...
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