]> git.parisson.com Git - timeside.git/commitdiff
Fix timeside scripts and add tests
authorThomas Fillon <thomas@parisson.com>
Thu, 15 Jan 2015 17:55:06 +0000 (18:55 +0100)
committerThomas Fillon <thomas@parisson.com>
Thu, 15 Jan 2015 18:43:00 +0000 (19:43 +0100)
Fix #66

.travis.yml
scripts/timeside-launch
scripts/timeside-waveforms
tests/test_scripts.sh [new file with mode: 0755]

index f76bbbbbec416a9b1d8146aaa56ac49c6697078a..99439e0a40b964021ec6e644a32f5f3a59125458 100644 (file)
@@ -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
index fa081ce0caf759b3a6f613223b22969e6957009d..0bebac0db84626be5d3c860c63e48c073a21f63d 100755 (executable)
@@ -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):
index 4799f7783497cd15fb9ee452be65a494f7d62cc0..9be45184c00af9eb5035408b7790251518881f2d 100755 (executable)
@@ -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 (executable)
index 0000000..cfab53f
--- /dev/null
@@ -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