Index: python/lib/aubio/cut.py
===================================================================
--- python/lib/aubio/cut.py	(revision 2bf530e070a005629fe0985a4945c491c4c8889a)
+++ python/lib/aubio/cut.py	(revision 995602795ce1863f07eb0e77c744a25b03982721)
@@ -6,13 +6,15 @@
 
 import sys
+import argparse
 
 def parse_args():
-    from optparse import OptionParser
     usage = "usage: %s [options] -i soundfile" % sys.argv[0]
     usage += "\n help: %s -h" % sys.argv[0]
-    parser = OptionParser(usage=usage)
-    parser.add_option("-i", "--input", action = "store", dest = "source_file",
+    parser = argparse.ArgumentParser()
+    parser.add_argument("source_file", default=None, nargs='?',
             help="input sound file to analyse", metavar = "<source_file>")
-    parser.add_option("-O","--onset-method",
+    parser.add_argument("-i", "--input", action = "store", dest = "source_file2",
+            help="input sound file to analyse", metavar = "<source_file>")
+    parser.add_argument("-O","--onset-method",
             action="store", dest="onset_method", default='default',
             metavar = "<onset_method>",
@@ -20,12 +22,12 @@
                     complexdomain|hfc|phase|specdiff|energy|kl|mkl")
     # cutting methods
-    parser.add_option("-b","--beat",
+    parser.add_argument("-b","--beat",
             action="store_true", dest="beat", default=False,
             help="use beat locations")
     """
-    parser.add_option("-S","--silencecut",
+    parser.add_argument("-S","--silencecut",
             action="store_true", dest="silencecut", default=False,
             help="use silence locations")
-    parser.add_option("-s","--silence",
+    parser.add_argument("-s","--silence",
             metavar = "<value>",
             action="store", dest="silence", default=-70,
@@ -33,21 +35,21 @@
             """
     # algorithm parameters
-    parser.add_option("-r", "--samplerate",
-            metavar = "<freq>", type='int',
+    parser.add_argument("-r", "--samplerate",
+            metavar = "<freq>", type=int,
             action="store", dest="samplerate", default=0,
             help="samplerate at which the file should be represented")
-    parser.add_option("-B","--bufsize",
+    parser.add_argument("-B","--bufsize",
             action="store", dest="bufsize", default=512,
-            metavar = "<size>", type='int',
+            metavar = "<size>", type=int,
             help="buffer size [default=512]")
-    parser.add_option("-H","--hopsize",
-            metavar = "<size>", type='int',
+    parser.add_argument("-H","--hopsize",
+            metavar = "<size>", type=int,
             action="store", dest="hopsize", default=256,
             help="overlap size [default=256]")
-    parser.add_option("-t","--onset-threshold",
-            metavar = "<value>", type="float",
+    parser.add_argument("-t","--onset-threshold",
+            metavar = "<value>", type=float,
             action="store", dest="threshold", default=0.3,
             help="onset peak picking threshold [default=0.3]")
-    parser.add_option("-c","--cut",
+    parser.add_argument("-c","--cut",
             action="store_true", dest="cut", default=False,
             help="cut input sound file at detected labels \
@@ -55,26 +57,26 @@
 
     # minioi
-    parser.add_option("-M","--minioi",
-            metavar = "<value>", type='string',
+    parser.add_argument("-M","--minioi",
+            metavar = "<value>", type=str,
             action="store", dest="minioi", default="12ms",
             help="minimum inter onset interval [default=12ms]")
 
     """
-    parser.add_option("-D","--delay",
-            action = "store", dest = "delay", type = "float",
+    parser.add_argument("-D","--delay",
+            action = "store", dest = "delay", type = float,
             metavar = "<seconds>", default=0,
             help="number of seconds to take back [default=system]\
                     default system delay is 3*hopsize/samplerate")
-    parser.add_option("-C","--dcthreshold",
+    parser.add_argument("-C","--dcthreshold",
             metavar = "<value>",
             action="store", dest="dcthreshold", default=1.,
             help="onset peak picking DC component [default=1.]")
-    parser.add_option("-L","--localmin",
+    parser.add_argument("-L","--localmin",
             action="store_true", dest="localmin", default=False,
             help="use local minima after peak detection")
-    parser.add_option("-d","--derivate",
+    parser.add_argument("-d","--derivate",
             action="store_true", dest="derivate", default=False,
             help="derivate onset detection function")
-    parser.add_option("-z","--zerocross",
+    parser.add_argument("-z","--zerocross",
             metavar = "<value>",
             action="store", dest="zerothres", default=0.008,
@@ -83,64 +85,65 @@
     # plotting functions
     """
-    parser.add_option("-p","--plot",
+    parser.add_argument("-p","--plot",
             action="store_true", dest="plot", default=False,
             help="draw plot")
-    parser.add_option("-x","--xsize",
+    parser.add_argument("-x","--xsize",
             metavar = "<size>",
             action="store", dest="xsize", default=1.,
-            type='float', help="define xsize for plot")
-    parser.add_option("-y","--ysize",
+            type=float, help="define xsize for plot")
+    parser.add_argument("-y","--ysize",
             metavar = "<size>",
             action="store", dest="ysize", default=1.,
-            type='float', help="define ysize for plot")
-    parser.add_option("-f","--function",
+            type=float, help="define ysize for plot")
+    parser.add_argument("-f","--function",
             action="store_true", dest="func", default=False,
             help="print detection function")
-    parser.add_option("-n","--no-onsets",
+    parser.add_argument("-n","--no-onsets",
             action="store_true", dest="nplot", default=False,
             help="do not plot detected onsets")
-    parser.add_option("-O","--outplot",
+    parser.add_argument("-O","--outplot",
             metavar = "<output_image>",
             action="store", dest="outplot", default=None,
             help="save plot to output.{ps,png}")
-    parser.add_option("-F","--spectrogram",
+    parser.add_argument("-F","--spectrogram",
             action="store_true", dest="spectro", default=False,
             help="add spectrogram to the plot")
     """
-    parser.add_option("-o","--output", type = str,
+    parser.add_argument("-o","--output", type = str,
             metavar = "<outputdir>",
             action="store", dest="output_directory", default=None,
             help="specify path where slices of the original file should be created")
-    parser.add_option("--cut-until-nsamples", type = int,
+    parser.add_argument("--cut-until-nsamples", type = int,
             metavar = "<samples>",
             action = "store", dest = "cut_until_nsamples", default = None,
             help="how many extra samples should be added at the end of each slice")
-    parser.add_option("--cut-every-nslices", type = int,
+    parser.add_argument("--cut-every-nslices", type = int,
             metavar = "<samples>",
             action = "store", dest = "cut_every_nslices", default = None,
             help="how many slices should be groupped together at each cut")
-    parser.add_option("--cut-until-nslices", type = int,
+    parser.add_argument("--cut-until-nslices", type = int,
             metavar = "<slices>",
             action = "store", dest = "cut_until_nslices", default = None,
             help="how many extra slices should be added at the end of each slice")
 
-    parser.add_option("-v","--verbose",
+    parser.add_argument("-v","--verbose",
             action="store_true", dest="verbose", default=True,
             help="make lots of noise [default]")
-    parser.add_option("-q","--quiet",
+    parser.add_argument("-q","--quiet",
             action="store_false", dest="verbose", default=True,
             help="be quiet")
-    (options, args) = parser.parse_args()
-    if not options.source_file:
-        if len(args) == 1:
-            options.source_file = args[0]
-        else:
-            print ("no file name given\n" + usage)
-            sys.exit(1)
-    return options, args
+    args = parser.parse_args()
+    if not args.source_file and not args.source_file2:
+        sys.stderr.write("Error: no file name given\n")
+        parser.print_help()
+        sys.exit(1)
+    elif args.source_file2 is not None:
+        args.source_file = args.source_file2
+    return args
 
 def main():
-    options, args = parse_args()
-
+    options = parse_args()
+
+    source_file = options.source_file
     hopsize = options.hopsize
     bufsize = options.bufsize
