Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IPI_annot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maxence Ferrari
IPI_annot
Commits
e71078b3
Commit
e71078b3
authored
4 years ago
by
ferrari
Browse files
Options
Downloads
Patches
Plain Diff
Add input() style option parsing
parent
598683ab
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
ipi_extract.py
+32
-3
32 additions, 3 deletions
ipi_extract.py
with
32 additions
and
3 deletions
ipi_extract.py
+
32
−
3
View file @
e71078b3
...
...
@@ -573,7 +573,6 @@ def reset(callback, in_path, channel, low=2e3, high=20e3):
callback
.
reset
(
song
,
sr
,
song_resample
)
def
main
(
args
):
if
args
.
out
==
''
:
outpath
=
args
.
input
.
rsplit
(
'
.
'
,
1
)[
0
]
+
'
.pred.h5
'
...
...
@@ -590,12 +589,42 @@ def main(args):
if
__name__
==
'
__main__
'
:
parser
=
argparse
.
ArgumentParser
(
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
class
ArgumentParser
(
argparse
.
ArgumentParser
):
def
error
(
self
,
message
):
if
message
.
startswith
(
'
the following arguments are required:
'
):
raise
ValueError
()
super
(
ArgumentParser
,
self
).
error
(
message
)
parser
=
ArgumentParser
(
formatter_class
=
argparse
.
ArgumentDefaultsHelpFormatter
)
parser
.
add_argument
(
"
input
"
,
type
=
str
,
help
=
"
Input file
"
)
parser
.
add_argument
(
"
--out
"
,
type
=
str
,
default
=
''
,
help
=
"
Output file. Default to the input_path
'
.pred.h5
'"
)
parser
.
add_argument
(
"
--channel
"
,
type
=
int
,
default
=
0
,
help
=
"
Sound channel to be analysed. Indices start from 0.
"
)
parser
.
add_argument
(
"
--erase
"
,
action
=
'
store_true
'
,
help
=
"
If out file exist and this option is not given,
"
"
the computation will be halted
"
)
try
:
args
=
parser
.
parse_args
()
except
ValueError
as
e
:
print
(
f
'
Error while parsing the command line arguments:
{
e
}
'
)
def
ask
(
string
):
y
=
{
'
y
'
,
'
yes
'
,
'
o
'
,
'
oui
'
}
a
=
{
'
y
'
,
'
yes
'
,
'
o
'
,
'
oui
'
,
'
n
'
,
'
no
'
,
'
non
'
}
while
True
:
ans
=
input
(
string
+
'
[y/n]
'
).
lower
()
if
ans
in
a
:
return
ans
in
y
if
not
ask
(
'
Do you want to manually specify them?
'
):
sys
.
exit
(
2
)
# exit code of invalid argparse
class
VirtualArgParse
(
object
):
def
__init__
(
self
):
self
.
input
=
input
(
"
What is the input file path?
"
)
self
.
out
=
input
(
"
What is the out file path? (Leave empty for default)
"
)
self
.
channel
=
int
(
input
(
"
Which channel do you want to use starting from 0?
"
))
self
.
erase
=
ask
(
"
Do you want to erase the out file if it already exist?
"
)
args
=
VirtualArgParse
()
sys
.
exit
(
main
(
args
))
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