Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
refscrub
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software Public
PASSOFT
refscrub
Commits
f5c8c3f4
Commit
f5c8c3f4
authored
4 years ago
by
Maeva Pourpoint
Browse files
Options
Downloads
Patches
Plain Diff
Refactoring of refscrub main module - Use argparse.ArgumentParser instead of optparse.OptionParser
parent
b6b8b781
No related branches found
No related tags found
1 merge request
!4
Porting Python 2 code to Python 3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
refscrub/refscrub.py
+38
-22
38 additions, 22 deletions
refscrub/refscrub.py
with
38 additions
and
22 deletions
refscrub/refscrub.py
+
38
−
22
View file @
f5c8c3f4
...
...
@@ -14,11 +14,11 @@ Updates to work on both Python 2 & 3.
Code cleanup to match PEP 8.
Cleanup global vars.
"""
from
os.path
import
join
,
basename
,
getsize
import
sys
import
argparse
import
struct
from
os.path
import
basename
,
getsize
,
isfile
USAGE
=
'
usage: %prog [options] infile1 [ infile2 ... infileN]
'
PROG_VERSION
=
'
2018.228
'
VERBOSE
=
False
EXTRACT
=
False
...
...
@@ -220,26 +220,40 @@ def main():
global
PREFIX
global
FILESIZE
summaryfh
=
None
from
optparse
import
OptionParser
parser
=
OptionParser
(
USAGE
,
version
=
"
%prog
"
+
PROG_VERSION
)
parser
.
description
=
"
infile can be a REFTEK file or a raw disk (/dev/disk1) of a CF card.
"
parser
.
add_option
(
'
-v
'
,
'
--verbose
'
,
dest
=
"
VERBOSE
"
,
action
=
'
store_true
'
,
default
=
False
,
help
=
"
Prints info about each packet, good or bad. This will increase runtime.
"
)
parser
.
add_option
(
'
-e
'
,
'
--extract
'
,
dest
=
'
EXTRACT
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
Writes good packets to files named infile.SNXX.scrub.ref OR PREFIX.SNXX.scrub.ref,
'
'
if given, for each Serial Number found. If output file exists it will append. Be careful
'
'
not to duplicate data by running more than once on the same file in the same dir.
'
)
parser
.
add_option
(
'
-p
'
,
'
--prefix
'
,
dest
=
'
PREFIX
'
,
help
=
'
Prefix of output filename. Defaults to inputfilename
'
)
parser
.
add_option
(
'
-s
'
,
'
--savesum
'
,
dest
=
'
SUMMARY
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
Appends summary to %s
'
%
SUMMARY_FILE
)
options
,
args
=
parser
.
parse_args
()
VERBOSE
=
options
.
VERBOSE
EXTRACT
=
options
.
EXTRACT
PREFIX
=
options
.
PREFIX
if
options
.
SUMMARY
:
parser
=
argparse
.
ArgumentParser
(
prog
=
"
refscrub
"
,
usage
=
"
%(prog)s [options] infile1
"
"
[ infile2 ... infileN]
"
)
parser
.
add_argument
(
'
infile
'
,
nargs
=
'
*
'
,
metavar
=
'
infile
'
,
help
=
"
infile can be a REFTEK file or a raw disk
"
"
(/dev/disk1) of a CF card.
"
)
parser
.
add_argument
(
'
--version
'
,
action
=
'
version
'
,
version
=
"
%(prog)s
"
+
PROG_VERSION
)
parser
.
add_argument
(
'
-v
'
,
'
--verbose
'
,
dest
=
"
VERBOSE
"
,
action
=
'
store_true
'
,
default
=
False
,
help
=
"
Prints info about each packet,
"
"
good or bad. This will increase runtime.
"
)
parser
.
add_argument
(
'
-e
'
,
'
--extract
'
,
dest
=
'
EXTRACT
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
"
Writes good packets to files
"
"
named infile.SNXX.scrub.ref OR
"
"
PREFIX.SNXX.scrub.ref, if given, for each Serial
"
"
Number found. If output file exists it will append.
"
"
Be careful not to duplicate data by running more
"
"
than once on the same file in the same dir.
"
)
parser
.
add_argument
(
'
-p
'
,
'
--prefix
'
,
dest
=
'
PREFIX
'
,
help
=
"
Prefix of output filename. Defaults to input
"
"
filename
"
)
parser
.
add_argument
(
'
-s
'
,
'
--savesum
'
,
dest
=
'
SUMMARY
'
,
action
=
'
store_true
'
,
default
=
False
,
help
=
'
Appends summary to %s
'
%
SUMMARY_FILE
)
args
=
parser
.
parse_args
()
if
not
args
.
infile
:
parser
.
print_help
()
sys
.
exit
(
1
)
VERBOSE
=
args
.
VERBOSE
EXTRACT
=
args
.
EXTRACT
PREFIX
=
args
.
PREFIX
if
args
.
SUMMARY
:
summaryfh
=
open
(
SUMMARY_FILE
,
'
a
'
)
for
infilename
in
args
:
for
infilename
in
args
.
infile
:
print
(
"
Processing: %s
"
%
infilename
)
if
not
PREFIX
:
PREFIX
=
basename
(
infilename
)
...
...
@@ -248,11 +262,13 @@ def main():
# Must open the file in binary mode or else we will have unicode issues when reading.
with
open
(
infilename
,
"
rb
"
)
as
infile
:
readfile
(
infile
)
if
option
s
.
SUMMARY
:
if
arg
s
.
SUMMARY
:
summaryfh
.
write
(
infilename
+
'
,
'
+
PREFIX
+
'
\n
'
)
summaryfh
.
write
(
summary
(
infile
))
print
(
"
----------------------------------------
"
)
if
isfile
(
SUMMARY_FILE
):
summaryfh
.
close
()
if
__name__
==
'
__main__
'
:
...
...
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