[SCM] morituri/master: * morituri/image/cue.py: * morituri/test/test_image_cue.py: Add dumping of .cue files.

js at users.alioth.debian.org js at users.alioth.debian.org
Sun Oct 19 20:08:54 UTC 2014


The following commit has been merged in the master branch:
commit 6e2e58a373892bd235808e6af2f1fe40f452c5d4
Author: Thomas Vander Stichele <thomas (at) apestaart (dot) org>
Date:   Sun May 3 19:18:26 2009 +0000

    	* morituri/image/cue.py:
    	* morituri/test/test_image_cue.py:
    	  Add dumping of .cue files.

diff --git a/ChangeLog b/ChangeLog
index 198fc41..a7d6baf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-05-03  Thomas Vander Stichele  <thomas at apestaart dot org>
 
+	* morituri/image/cue.py:
+	* morituri/test/test_image_cue.py:
+	  Add dumping of .cue files.
+
+2009-05-03  Thomas Vander Stichele  <thomas at apestaart dot org>
+
 	* morituri/program/cdparanoia.py:
 	  Use a temporary file to rip to.
 
diff --git a/morituri/image/cue.py b/morituri/image/cue.py
index c4162d8..5e1ba7b 100644
--- a/morituri/image/cue.py
+++ b/morituri/image/cue.py
@@ -29,6 +29,8 @@ See http://digitalx.org/cuesheetsyntax.php
 import os
 import re
 
+from morituri.common import common
+
 _REM_RE = re.compile("^REM\s(\w+)\s(.*)$")
 _PERFORMER_RE = re.compile("^PERFORMER\s(.*)$")
 _TITLE_RE = re.compile("^TITLE\s(.*)$")
@@ -122,6 +124,31 @@ class Cue:
                 # print 'index %d, offset %d of track %r' % (indexNumber, frameOffset, currentTrack)
                 continue
 
+    def dump(self):
+        """
+        Dump our internal representation to a .cue file content.
+        """
+        lines = []
+        currentFile = None
+
+        for i, track in enumerate(self.tracks):
+            indexes = track._indexes.keys()
+            indexes.sort()
+            index, file = track._indexes[indexes[0]]
+            if file != currentFile:
+                lines.append('FILE "%s" WAVE' % file.path)
+                currentFile = file
+            lines.append("  TRACK %02d %s" % (i + 1, 'AUDIO'))
+            for index in indexes:
+                (offset, file) = track._indexes[index]
+                if file != currentFile:
+                    lines.append('FILE "%s" WAVE' % file.path)
+                lines.append(
+                    "    INDEX %02d %s" % (index, common.framesToMSF(offset)))
+
+        lines.append("")
+        return "\n".join(lines) 
+
     def message(self, number, message):
         """
         Add a message about a given line in the cue file.
diff --git a/morituri/test/test_image_cue.py b/morituri/test/test_image_cue.py
index d05553f..66598ba 100644
--- a/morituri/test/test_image_cue.py
+++ b/morituri/test/test_image_cue.py
@@ -2,6 +2,7 @@
 # vi:si:et:sw=4:sts=4:ts=4
 
 import os
+import tempfile
 import unittest
 
 from morituri.image import cue
@@ -44,3 +45,25 @@ class KanyeMixedTestCase(unittest.TestCase):
     def testGetTrackLength(self):
         t = self.cue.tracks[0]
         self.assertEquals(self.cue.getTrackLength(t), -1)
+
+
+class WriteCueTestCase(unittest.TestCase):
+    def testWrite(self):
+        fd, path = tempfile.mkstemp(suffix='morituri.test.cue')
+        os.close(fd)
+        c = cue.Cue(path)
+
+        f = cue.File('track01.wav', 'AUDIO')
+        t = cue.Track(1)
+        t.index(1, 0, f)
+        c.tracks.append(t)
+
+        t = cue.Track(2)
+        t.index(0, 1000, f)
+        f = cue.File('track02.wav', 'AUDIO')
+        t.index(1, 1100, f)
+        c.tracks.append(t)
+
+        print c.dump()
+
+        

-- 
morituri packaging



More information about the pkg-multimedia-commits mailing list