From: Thomas Fillon Date: Thu, 15 Jan 2015 17:55:06 +0000 (+0100) Subject: Fix timeside scripts and add tests X-Git-Tag: 0.7^2~18^2~7 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=6bc2813a9bfb0e241b87e43925591b17d02597ad;p=timeside.git Fix timeside scripts and add tests Fix #66 --- diff --git a/.travis.yml b/.travis.yml index f76bbbb..99439e0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,8 +25,18 @@ before_script: script: #- coverage run --source=timeside --omit=timeside/analyzer/aubio/aubio_*.py,timeside/analyzer/yaafe.py,timeside/analyzer/limsi_sad.py,timeside/analyzer/vamp_plugin.py setup.py test + # -------------- + # Run Unit tests + # ------------- - python setup.py test + # ------------- + # Check doctest + # ------------- - cd doc && make doctest + # ----------- + # Test scripts + # ----------- + - cd .. && source tests/test_scripts.sh after_success: #- pip install coveralls diff --git a/scripts/timeside-launch b/scripts/timeside-launch index fa081ce..0bebac0 100755 --- a/scripts/timeside-launch +++ b/scripts/timeside-launch @@ -1,7 +1,7 @@ #! /usr/bin/env python # -*- coding: utf-8 -*- # -# Copyright (c) 2007-2013 Parisson SARL +# Copyright (c) 2007-2014 Parisson SARL # This file is part of TimeSide. @@ -28,7 +28,7 @@ pipeline can be configured using command line options or a configuration file. import sys, os.path -usage = "usage: %s [options] -c file.conf file1.wav [file2.wav ...]" % sys.argv[0] +usage = "usage: %s [options] -C file.conf file1.wav [file2.wav ...]" % sys.argv[0] usage += "\n help: %s -h" % sys.argv[0] def parse_config(path): @@ -139,7 +139,7 @@ def parse_args(): if __name__ == '__main__': options, args = parse_args() # load timeside after parse_args, to avoid gstreamer hijacking - import timeside + import timeside.core if len(args) == 0: print usage @@ -161,10 +161,10 @@ if __name__ == '__main__': graphers = options.graphers encoders = options.encoders - all_decoders = timeside.core.processors(timeside.api.IDecoder) - all_analyzers = timeside.core.processors(timeside.api.IAnalyzer) - all_graphers = timeside.core.processors(timeside.api.IGrapher) - all_encoders = timeside.core.processors(timeside.api.IEncoder) + all_decoders = timeside.core.processor.processors(timeside.core.api.IDecoder) + all_analyzers = timeside.core.processor.processors(timeside.core.api.IAnalyzer) + all_graphers = timeside.core.processor.processors(timeside.core.api.IGrapher) + all_encoders = timeside.core.processor.processors(timeside.core.api.IEncoder) def match_id_or_class(id_or_class, processors): matches = filter(lambda x: x.__name__ == id_or_class, processors) @@ -194,16 +194,25 @@ if __name__ == '__main__': encoders = map(match_encoder, encoders) def process_file(path): - import uuid - from timeside.decoder.utils import get_uri - file_uuid = str(uuid.uuid5(uuid.NAMESPACE_URL, get_uri(path) )) + #import uuid + #from timeside.plugins.decoder.utils import get_uri + from timeside.core import get_processor + + decoder = get_processor('file_decoder')(path) + + #file_uuid = str(uuid.uuid5(uuid.NAMESPACE_URL, get_uri(path) )) + file_uuid = decoder.sha1 + + result_dir = os.path.join(outputdir, file_uuid) + if not os.path.isdir(result_dir): + os.makedirs(result_dir) + - decoder = timeside.decoder.FileDecoder(path, start = 1) #pipe.setup(channels = channels, samplerate = samplerate, blocksize = blocksize) pipe = decoder _analyzers = [a() for a in analyzers] _graphers = [g() for g in graphers] - _encoders = [e(os.path.join(outputdir, file_uuid + '.' + e.file_extension())) for e in encoders] + _encoders = [e(os.path.join(result_dir, file_uuid + '.' + e.file_extension())) for e in encoders] for a in _analyzers: pipe = pipe | a @@ -214,17 +223,16 @@ if __name__ == '__main__': pipe.run(channels = channels, samplerate = samplerate, blocksize = blocksize) if len(_analyzers): - results = pipe.results - for f in r_formats: - result_path = os.path.join(outputdir, file_uuid + '.' + f) - getattr(results,'to_'+f)(result_path) - if verbose : print 'saved', result_path + for res_uuid, result in pipe.results.items(): + + for f in r_formats: + result_path = os.path.join(result_dir, res_uuid + '.' + f) + getattr(result,'to_'+f)(result_path) + if verbose : print 'saved', result_path if len(_graphers): for g in _graphers: for f in i_formats: - graph_path = os.path.join(outputdir, file_uuid, g.id() + '.' + f) - if not os.path.isdir(os.path.dirname(graph_path)): - os.makedirs(os.path.dirname(graph_path)) + graph_path = os.path.join(result_dir, g.uuid() + '.' + f) g.render(graph_path) if verbose : print 'saved', graph_path if len(_encoders): diff --git a/scripts/timeside-waveforms b/scripts/timeside-waveforms index 4799f77..9be4518 100755 --- a/scripts/timeside-waveforms +++ b/scripts/timeside-waveforms @@ -24,7 +24,7 @@ version = '0.4' import os import sys -import timeside +import timeside.core class GrapherScheme: @@ -90,19 +90,20 @@ class Media2Waveform(object): return path_dict def process(self): - waveform = timeside.grapher.Waveform(width=self.width, height=self.height, + + waveform = timeside.core.get_processor('waveform_simple')(width=self.width, height=self.height, bg_color=self.bg_color, color_scheme=self.color_scheme) for source, image in self.path_dict.iteritems(): if not os.path.exists(image) or self.force: print 'Processing ', source audio = os.path.join(os.path.dirname(__file__), source) - decoder = timeside.decoder.FileDecoder(audio) + decoder = timeside.core.get_processor('file_decoder')(audio) (decoder | waveform).run() img_name = os.path.split(image)[1] - image = os.path.split(image)[0]+os.sep+os.path.splitext(img_name)[0] + '_' +\ + filename = os.path.split(image)[0]+os.sep+os.path.splitext(img_name)[0] + '_' +\ '_'.join([str(self.width), str(self.height)])+os.path.splitext(img_name)[1] - waveform.graph.filename = image - print 'Rendering ', waveform.graph.filename + #waveform.graph.filename = image + print 'Rendering %s '% filename #print 'frames per pixel = ', waveform.graph.samples_per_pixel waveform.render(output=image) @@ -113,7 +114,7 @@ if __name__ == '__main__': timeside-waveforms : TimeSide simple batch waveform generator usage : timeside-waveforms /path/to/media_dir /path/to/img_dir - infos : https://github.com/yomguy/TimeSide/ + infos : https://github.com/Parisson/TimeSide/ version : %s """ % version else: diff --git a/tests/test_scripts.sh b/tests/test_scripts.sh new file mode 100755 index 0000000..cfab53f --- /dev/null +++ b/tests/test_scripts.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +export TEMPDIR=$(mktemp -d) +export WAVFILE=$(python -c"from timeside.core.tools.test_samples import samples; print samples['C4_scale.wav']") +export WAVDIR=$(python -c"from timeside.core.tools.test_samples import samples; import os;print os.path.dirname(samples['C4_scale.wav'])") + +echo '-----------------------------------------------------' +echo ' timeside-launch ' +echo '-----------------------------------------------------' + +timeside-launch -h +timeside-launch -C examples/presets/draw_waveform_contour_white.ts $WAVFILE -o $TEMPDIR -R 'json','yaml','xml','hdf5' -v +timeside-launch -C examples/presets/transcode_media.ts $WAVFILE -o $TEMPDIR -R 'json','yaml','xml','hdf5' -v +timeside-launch -C examples/presets/extract_aubio_bpm.ts $WAVFILE -o $TEMPDIR -R 'json','yaml','xml','hdf5' -v + +echo '-----------------------------------------------------' +echo ' timeside-waveforms ' +echo '-----------------------------------------------------' + +timeside-waveforms $WAVDIR $TEMPDIR +ls $TEMPDIR \ No newline at end of file