Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
neoppod
Commits
56d0b764
Commit
56d0b764
authored
Jul 19, 2018
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
neolog: use argparse instead of optparse
parent
05e19861
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
+28
-28
neo/scripts/neolog.py
neo/scripts/neolog.py
+28
-28
No files found.
neo/scripts/neolog.py
View file @
56d0b764
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
# You should have received a copy of the GNU General Public License
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
bz2
,
gzip
,
errno
,
optparse
,
os
,
signal
,
sqlite3
,
sys
,
time
import
argparse
,
bz2
,
gzip
,
errno
,
os
,
signal
,
sqlite3
,
sys
,
time
from
bisect
import
insort
from
bisect
import
insort
from
logging
import
getLevelName
from
logging
import
getLevelName
from
zlib
import
decompress
from
zlib
import
decompress
...
@@ -225,38 +225,38 @@ def emit_many(log_list):
...
@@ -225,38 +225,38 @@ def emit_many(log_list):
insort
(
event_list
,
(
-
event
[
0
],
next
,
emit
,
event
))
insort
(
event_list
,
(
-
event
[
0
],
next
,
emit
,
event
))
def
main
():
def
main
():
parser
=
optparse
.
OptionParser
()
parser
=
argparse
.
ArgumentParser
(
description
=
'NEO Log Reader'
)
parser
.
add_option
(
'-a'
,
'--all'
,
action
=
"store_true"
,
_
=
parser
.
add_argument
_
(
'-a'
,
'--all'
,
action
=
"store_true"
,
help
=
'decode body of packets'
)
help
=
'decode body of packets'
)
parser
.
add_option
(
'-A'
,
'--decompress'
,
action
=
"store_true"
,
_
(
'-A'
,
'--decompress'
,
action
=
"store_true"
,
help
=
'decompress data when decode body of packets (implies --all)'
)
help
=
'decompress data when decode body of packets (implies --all)'
)
parser
.
add_option
(
'-d'
,
'--date'
,
metavar
=
'FORMAT'
,
_
(
'-d'
,
'--date'
,
metavar
=
'FORMAT'
,
help
=
'custom date format, according to strftime(3)'
)
help
=
'custom date format, according to strftime(3)'
)
parser
.
add_option
(
'-f'
,
'--follow'
,
action
=
"store_true"
,
_
(
'-f'
,
'--follow'
,
action
=
"store_true"
,
help
=
'output appended data as the file grows'
)
help
=
'output appended data as the file grows'
)
parser
.
add_option
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
"int"
,
_
(
'-F'
,
'--flush'
,
action
=
"append"
,
type
=
int
,
metavar
=
'PID'
,
help
=
'with -f, tell process PID to flush logs approximately N'
help
=
'with -f, tell process PID to flush logs approximately N'
' seconds (see -s)'
,
metavar
=
'PID'
)
' seconds (see -s)'
)
parser
.
add_option
(
'-n'
,
'--node'
,
action
=
"append"
,
_
(
'-n'
,
'--node'
,
action
=
"append"
,
help
=
'only show log entries from the given node'
help
=
'only show log entries from the given node'
' (only useful for logs produced by threaded tests),'
' (only useful for logs produced by threaded tests),'
" special value '-' hides the column"
)
" special value '-' hides the column"
)
parser
.
add_option
(
'-s'
,
'--sleep-interval'
,
type
=
"float"
,
default
=
1
,
_
(
'-s'
,
'--sleep-interval'
,
type
=
float
,
default
=
1
,
metavar
=
'N'
,
help
=
'with -f, sleep for approximately N seconds (default 1.0)'
help
=
'with -f, sleep for approximately N seconds (default 1.0)'
' between iterations'
,
metavar
=
'N'
)
' between iterations'
)
parser
.
add_option
(
'--from'
,
dest
=
'filter_from'
,
_
(
'--from'
,
dest
=
'filter_from'
,
metavar
=
'N'
,
help
=
'show records more recent that timestamp N if N > 0,'
help
=
'show records more recent that timestamp N if N > 0, or now+N'
' or now+N if N < 0; N can also be a string that is'
' if N < 0; N can also be a string that is parseable by dateutil'
)
' parseable by dateutil '
,
metavar
=
'N'
)
_
(
'file'
,
nargs
=
'+'
,
options
,
args
=
parser
.
parse_args
()
help
=
'log file, compressed (gz, bz2 or xz) or not'
)
if
options
.
sleep_interval
<=
0
:
args
=
parser
.
parse_args
()
if
args
.
sleep_interval
<=
0
:
parser
.
error
(
"sleep_interval must be positive"
)
parser
.
error
(
"sleep_interval must be positive"
)
if
not
args
:
filter_from
=
args
.
filter_from
parser
.
error
(
"no log specified"
)
filter_from
=
options
.
filter_from
if
filter_from
:
if
filter_from
:
try
:
try
:
filter_from
=
float
(
option
s
.
filter_from
)
filter_from
=
float
(
arg
s
.
filter_from
)
except
ValueError
:
except
ValueError
:
from
dateutil.parser
import
parse
from
dateutil.parser
import
parse
x
=
parse
(
filter_from
)
x
=
parse
(
filter_from
)
...
@@ -267,24 +267,24 @@ def main():
...
@@ -267,24 +267,24 @@ def main():
else
:
else
:
if
filter_from
<
0
:
if
filter_from
<
0
:
filter_from
+=
time
.
time
()
filter_from
+=
time
.
time
()
node_list
=
option
s
.
node
or
[]
node_list
=
arg
s
.
node
or
[]
try
:
try
:
node_list
.
remove
(
'-'
)
node_list
.
remove
(
'-'
)
node_column
=
False
node_column
=
False
except
ValueError
:
except
ValueError
:
node_column
=
True
node_column
=
True
log_list
=
[
Log
(
db_path
,
log_list
=
[
Log
(
db_path
,
2
if
options
.
decompress
else
1
if
option
s
.
all
else
0
,
2
if
args
.
decompress
else
1
if
arg
s
.
all
else
0
,
option
s
.
date
,
filter_from
,
node_column
,
node_list
)
arg
s
.
date
,
filter_from
,
node_column
,
node_list
)
for
db_path
in
args
]
for
db_path
in
args
.
file
]
if
option
s
.
follow
:
if
arg
s
.
follow
:
try
:
try
:
pid_list
=
option
s
.
flush
or
()
pid_list
=
arg
s
.
flush
or
()
while
True
:
while
True
:
emit_many
(
log_list
)
emit_many
(
log_list
)
for
pid
in
pid_list
:
for
pid
in
pid_list
:
os
.
kill
(
pid
,
signal
.
SIGRTMIN
)
os
.
kill
(
pid
,
signal
.
SIGRTMIN
)
time
.
sleep
(
option
s
.
sleep_interval
)
time
.
sleep
(
arg
s
.
sleep_interval
)
except
KeyboardInterrupt
:
except
KeyboardInterrupt
:
pass
pass
else
:
else
:
...
...
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