History

[py] improve style of cmd.py

Paul Brossier committed 8 years ago

Commit 78ebc271 parent a5c3f2a1 file · +38 −30Browse files

Showing the changes to python (1 of 1 file). Show all

Unified · Split

python/lib/aubio/cmd.py+38−30
@@ -168,10 +168,10 @@ class AubioArgumentParser(argparse.ArgumentParser): · 167 unmodified lines
168168 help="samplerate at which the file should be represented")
169169
170170 def add_verbose_help(self):
171− self.add_argument("-v","--verbose",
171+ self.add_argument("-v", "--verbose",
172172 action="count", dest="verbose", default=1,
173173 help="make lots of noise [default]")
174− self.add_argument("-q","--quiet",
174+ self.add_argument("-q", "--quiet",
175175 action="store_const", dest="verbose", const=0,
176176 help="be quiet")
177177
@@ -180,25 +180,25 @@ class AubioArgumentParser(argparse.ArgumentParser): · 2 unmodified lines
180180 self.add_hop_size(hop_size=hop_size)
181181
182182 def add_buf_size(self, buf_size=512):
183− self.add_argument("-B","--bufsize",
183+ self.add_argument("-B", "--bufsize",
184184 action="store", dest="buf_size", default=buf_size,
185185 metavar = "<size>", type=int,
186186 help="buffer size [default=%d]" % buf_size)
187187
188188 def add_hop_size(self, hop_size=256):
189− self.add_argument("-H","--hopsize",
189+ self.add_argument("-H", "--hopsize",
190190 metavar = "<size>", type=int,
191191 action="store", dest="hop_size", default=hop_size,
192192 help="overlap size [default=%d]" % hop_size)
193193
194194 def add_method(self, method='default', helpstr='method'):
195− self.add_argument("-m","--method",
195+ self.add_argument("-m", "--method",
196196 metavar = "<method>", type=str,
197197 action="store", dest="method", default=method,
198198 help="%s [default=%s]" % (helpstr, method))
199199
200200 def add_threshold(self, default=None):
201− self.add_argument("-t","--threshold",
201+ self.add_argument("-t", "--threshold",
202202 metavar = "<threshold>", type=float,
203203 action="store", dest="threshold", default=default,
204204 help="threshold [default=%s]" % default)
@@ -239,14 +239,16 @@ class AubioArgumentParser(argparse.ArgumentParser): · 34 unmodified lines
239239 help=helpstr)
240240
241241 def add_slicer_options(self):
242− self.add_argument("-o","--output", type = str,
242+ self.add_argument("-o", "--output", type = str,
243243 metavar = "<outputdir>",
244244 action="store", dest="output_directory", default=None,
245− help="specify path where slices of the original file should be created")
245+ help="specify path where slices of the original file should'
246+ ' be created")
246247 self.add_argument("--cut-until-nsamples", type = int,
247248 metavar = "<samples>",
248249 action = "store", dest = "cut_until_nsamples", default = None,
249− help="how many extra samples should be added at the end of each slice")
250+ help="how many extra samples should be added at the end of'
251+ ' each slice")
250252 self.add_argument("--cut-every-nslices", type = int,
251253 metavar = "<samples>",
252254 action = "store", dest = "cut_every_nslices", default = None,
@@ -254,7 +256,8 @@ class AubioArgumentParser(argparse.ArgumentParser): · 1 unmodified line
254256 self.add_argument("--cut-until-nslices", type = int,
255257 metavar = "<slices>",
256258 action = "store", dest = "cut_until_nslices", default = None,
257− help="how many extra slices should be added at the end of each slice")
259+ help="how many extra slices should be added at the end of'
260+ ' each slice")
258261 self.add_argument("--create-first",
259262 action = "store_true", dest = "create_first", default = False,
260263 help="always include first slice")
@@ -288,7 +291,8 @@ class default_process(object): · 27 unmodified lines
288291 self.time2string = timefunc(args.time_format)
289292 if args.verbose > 2 and hasattr(self, 'options'):
290293 name = type(self).__name__.split('_')[1]
291− optstr = ' '.join(['running', name, 'with options', repr(self.options), '\n'])
294+ optstr = ' '.join(['running', name, 'with options',
295+ repr(self.options), '\n'])
292296 sys.stderr.write(optstr)
293297 def flush(self, frames_read, samplerate):
294298 # optionally called at the end of process
@@ -296,7 +300,7 @@ class default_process(object): · 1 unmodified line
296300
297301 def parse_options(self, args, valid_opts):
298302 # get any valid options found in a dictionnary of arguments
299− options = {k :v for k,v in vars(args).items() if k in valid_opts}
303+ options = {k: v for k, v in vars(args).items() if k in valid_opts}
300304 self.options = options
301305
302306 def remap_pvoc_options(self, options):
@@ -377,7 +381,7 @@ class process_tempo(process_beat): · 74 unmodified lines
377381 if len(self.beat_locations) < 2:
378382 outstr = "unknown bpm"
379383 else:
380− bpms = 60./ np.diff(self.beat_locations)
384+ bpms = 60. / np.diff(self.beat_locations)
381385 median_bpm = np.mean(bpms)
382386 if len(self.beat_locations) < 10:
383387 outstr = "%.2f bpm (uncertain)" % median_bpm
@@ -398,14 +402,14 @@ class process_notes(default_process): · 14 unmodified lines
398402 def __call__(self, block):
399403 return self.notes(block)
400404 def repr_res(self, res, frames_read, samplerate):
401− if res[2] != 0: # note off
405+ if res[2] != 0: # note off
402406 fmt_out = self.time2string(frames_read, samplerate)
403407 sys.stdout.write(fmt_out + '\n')
404− if res[0] != 0: # note on
408+ if res[0] != 0: # note on
405409 lastmidi = res[0]
406410 fmt_out = "%f\t" % lastmidi
407411 fmt_out += self.time2string(frames_read, samplerate)
408− sys.stdout.write(fmt_out) # + '\t')
412+ sys.stdout.write(fmt_out) # + '\t')
409413 def flush(self, frames_read, samplerate):
410414 eof = self.time2string(frames_read, samplerate)
411415 sys.stdout.write(eof + '\n')
@@ -472,13 +476,13 @@ class process_quiet(default_process): · 60 unmodified lines
472476 if aubio.silence_detection(block, self.silence) == 1:
473477 if self.wassilence != 1:
474478 self.wassilence = 1
475− return 2 # newly found silence
476− return 1 # silence again
479+ return 2 # newly found silence
480+ return 1 # silence again
477481 else:
478482 if self.wassilence != 0:
479483 self.wassilence = 0
480− return -1 # newly found noise
481− return 0 # noise again
484+ return -1 # newly found noise
485+ return 0 # noise again
482486
483487 def repr_res(self, res, frames_read, samplerate):
484488 fmt_out = None
@@ -498,16 +502,18 @@ class process_cut(process_onset): · 13 unmodified lines
498502
499503 def __call__(self, block):
500504 ret = super(process_cut, self).__call__(block)
501− if ret: self.slices.append(self.onset.get_last())
505+ if ret:
506+ self.slices.append(self.onset.get_last())
502507 return ret
503508
504509 def flush(self, frames_read, samplerate):
505510 from aubio.cut import _cut_slice
506511 _cut_slice(self.options, self.slices)
507− duration = float (frames_read) / float(samplerate)
508− base_info = '%(source_file)s' % {'source_file': self.options.source_uri}
512+ duration = float(frames_read) / float(samplerate)
513+ base_info = '%(source_file)s' % \
514+ {'source_file': self.options.source_uri}
509515 base_info += ' (total %(duration).2fs at %(samplerate)dHz)\n' % \
510− {'duration': duration, 'samplerate': samplerate}
516+ {'duration': duration, 'samplerate': samplerate}
511517 info = "created %d slices from " % len(self.slices)
512518 info += base_info
513519 sys.stderr.write(info)
@@ -525,19 +531,20 @@ def main(): · 11 unmodified lines
525531 parser_root.add_argument('-V', '--version', help="show version",
526532 action="store_true", dest="show_version")
527533 args, extras = parser_root.parse_known_args()
528− if args.show_version == False: # no -V, forward to parser
534+ if not args.show_version: # no -V, forward to parser
529535 args = parser.parse_args(extras, namespace=args)
530− elif len(extras) != 0: # -V with other arguments, print help
536+ elif len(extras) != 0: # -V with other arguments, print help
531537 parser.print_help()
532538 sys.exit(1)
533− else: # in py3, we can simply use parser directly
539+ else: # in py3, we can simply use parser directly
534540 args = parser.parse_args()
535541 if 'show_version' in args and args.show_version:
536542 sys.stdout.write('aubio version ' + aubio.version + '\n')
537543 sys.exit(0)
538544 elif 'verbose' in args and args.verbose > 3:
539545 sys.stderr.write('aubio version ' + aubio.version + '\n')
540− if 'command' not in args or args.command is None or args.command in ['help']:
546+ if 'command' not in args or args.command is None \
547+ or args.command in ['help']:
541548 # no command given, print help and return 1
542549 parser.print_help()
543550 if args.command and args.command in ['help']:
@@ -571,7 +578,8 @@ def main(): · 27 unmodified lines
571578 # increment total number of frames read
572579 frames_read += read
573580 # exit loop at end of file
574− if read < a_source.hop_size: break
581+ if read < a_source.hop_size:
582+ break
575583 # flush the processor if needed
576584 processor.flush(frames_read, a_source.samplerate)
577585 if args.verbose > 1:
@@ -579,7 +587,7 @@ def main(): · 1 unmodified line
579587 fmt_string += " ({:d} samples in {:d} blocks of {:d})"
580588 fmt_string += " from {:s} at {:d}Hz\n"
581589 sys.stderr.write(fmt_string.format(
582− frames_read/float(a_source.samplerate),
590+ frames_read / float(a_source.samplerate),
583591 frames_read,
584592 frames_read // a_source.hop_size + 1,
585593 a_source.hop_size,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t