]> git.parisson.com Git - telemeta.git/commitdiff
add a TelemetaMediaImport test class, fix description, prepare new CeCILL style headers
authoryomguy <>
Tue, 7 Apr 2009 09:59:36 +0000 (09:59 +0000)
committeryomguy <>
Tue, 7 Apr 2009 09:59:36 +0000 (09:59 +0000)
README
telemeta/export/core.py
tests/media_import.py [new file with mode: 0755]
tests/wav_import.py

diff --git a/README b/README
index 4e84110b4d624e2d9d785ef77e5e6f1cb3f9cf5e..880df2e9310af763835c208b9b7800458273c274 100644 (file)
--- a/README
+++ b/README
@@ -11,8 +11,8 @@ Telemeta: web frontend to backup, analyse, transcode and stream any audio conten
 Telemeta is a web audio archiving program which introduces useful and secure methods to
 backup, index, transcode, analyse and publish any digitalized audio file with its metadata.
 It is dedicated to professionnals who wants to easily backup and publish documented sounds
-from collections of vinyls, magnetic tapes or audio CDs over a strong database, in accordance
-with open standards.
+from collections of vinyls, magnetic tapes or audio CDs over a strong database,
+in accordance with open standards.
 
 Here are the main features of Telemeta: 
 
@@ -92,3 +92,24 @@ Emails:
     Guillaume Pellerin <pellerin@parisson.com>, 
     Olivier Guilyardi <olivier@samalyse.com>
 
+# Support
+# =======
+
+The Telemeta project is developed by Parisson and Samalyse.
+
+It is supported and financed by :
+
+- CNRS : Centre National de la Recherche Scientifique
+    (the french Natianal Research and Scientific Center)
+    http://cnrs.fr
+- CREM : Centre de Recherche en Ethnomusicology
+    (the french Ethnomusicology Research Center)
+    http://www.crem-cnrs.fr
+- LAM : Equipe Lutherie, Acoustique et Musique de l'Université Pierre et Marie Curie de Paris
+    (Instrument design, Acoustic and Music team of the Pierre & Marie Curie University)
+    http://www.lam.jussieu.fr/
+- MuCEM : Musée des Civilisations de l'Europe et de la Méditerranée
+    http://www.musee-europemediterranee.org
+- MMSH : Maison Méditerranéenne des Sciences de l'Homme
+    http://www.mmsh.univ-aix.fr/
+- The Antropponet Project
index 28ffa2eff5c1275c1f3ad2951bde48693be07454..a4d11e39dff64c2104eded40e746ec0f6948bbca 100644 (file)
@@ -1,14 +1,37 @@
+#!/usr/bin/python
 # -*- coding: utf-8 -*-
 #
-# Copyright (C) 2008 Parisson SARL
-# Copyright (c) 2006-2007 Guillaume Pellerin <pellerin@parisson.com>
-# All rights reserved.
-#
-# This software is licensed as described in the file COPYING, which
-# yo"u should have received as part of this distribution. The terms
-# are also available at http://svn.parisson.org/telemeta/TelemetaLicense.
-#
-# Author: Guillaume Pellerin <pellerin@parisson.com>
+# Copyright Guillaume Pellerin, (2006-2009)
+# <yomguy@parisson.com>
+
+# This software is a computer program whose purpose is to backup, analyse,
+# transcode and stream any audio content with its metadata over a web frontend.
+
+# This software is governed by the CeCILL  license under French law and
+# abiding by the rules of distribution of free software.  You can  use,
+# modify and/ or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+
+# As a counterpart to the access to the source code and  rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty  and the software's author,  the holder of the
+# economic rights,  and the successive licensors  have only  limited
+# liability.
+
+# In this respect, the user's attention is drawn to the risks associated
+# with loading,  using,  modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean  that it is complicated to manipulate,  and  that  also
+# therefore means  that it is reserved for developers  and  experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and,  more generally, to use and operate it in the
+# same conditions as regards security.
+
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
 
 import os
 import re
diff --git a/tests/media_import.py b/tests/media_import.py
new file mode 100755 (executable)
index 0000000..f297099
--- /dev/null
@@ -0,0 +1,136 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# Copyright Guillaume Pellerin (2006-2009)
+# <yomguy@parisson.com>
+
+# This software is a computer program whose purpose is to backup
+# any audio content in a Telemeta instance
+
+# This software is governed by the CeCILL  license under French law and
+# abiding by the rules of distribution of free software.  You can  use,
+# modify and/ or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+
+# As a counterpart to the access to the source code and  rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty  and the software's author,  the holder of the
+# economic rights,  and the successive licensors  have only  limited
+# liability.
+
+# In this respect, the user's attention is drawn to the risks associated
+# with loading,  using,  modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean  that it is complicated to manipulate,  and  that  also
+# therefore means  that it is reserved for developers  and  experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and,  more generally, to use and operate it in the
+# same conditions as regards security.
+
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+
+
+import os
+import sys
+import shutil
+import datetime
+import StringIO
+from django.core.management import setup_environ
+from django.core.files import File
+
+tool_name = "media_import.py"
+
+class TelemetaMediaImportError(Exception):
+    pass
+
+class TelemetaMediaImport:
+
+    def __init__(self, settings, source_dir, source_file=None):
+        self.source_dir = source_dir
+        self.source_file = source_file
+        self.source_files = os.listdir(self.source_dir)
+        self.item_media_root_dir = settings.MEDIA_ROOT
+        self.item_media_full_dir = self.item_media_root_dir + os.sep + 'items'
+        self.collection_id = self.get_collection()
+
+    def get_collection(self):
+        from telemeta.models import MediaItem
+        file_0 = self.source_files[0]
+        id_string = get_media_name(file_0)
+        self.item_list = MediaItem.objects.filter(id__startswith=id_string)
+        return self.item_list[0].collection_id
+
+    def copy_files(self):
+        if not os.path.exists(self.dest_dir):
+            os.makedirs(self.dest_dir)
+        for file in self.source_files:
+            if not os.path.exists(self.dest_dir + os.sep + file):
+                shutil.copy(self.source_dir + os.sep + file, self.dest_dir)
+
+    def media_import_copy(self):
+        from telemeta.models import MediaItem
+        if not self.source_file:
+            self.files = os.listdir(self.source_dir)
+            self.files.sort()
+        else:
+            self.files = [self.source_file]
+        id_list = map(get_media_name, self.files)
+
+        print "Working on collection_id : " + self.collection_id
+        for item_id in id_list:
+            print "item_id : " + item_id
+            it = MediaItem.objects.get(id=item_id)
+            source_full_path = self.source_dir + os.sep + get_item_in_list(self.source_files, item_id)
+            media = open(source_full_path, 'r')
+            f = File(media)
+            print "Adding : " + source_full_path
+            it.file.save(f.name, f, save=True)
+            media.close()
+
+    def main(self):
+        self.media_import_copy()
+
+def get_media_name(media):
+    name = media.split('.')[:-1]
+    return '.'.join(name)
+
+def get_item_in_list(item_list, string):
+    for item in item_list:
+        if string in item:
+            return item
+
+def print_usage():
+    print """
+ Usage: %s <project_dir> <source_dir> [<source_file>]
+
+ project_dir: the directory of the Django project which hosts Telemeta
+ source_dir: the directory containing all media files to include
+ source_file: the media file to include (optional, if only one file)
+
+ IMPORTANT: each file name without its extension has to correspond at least to one existing item id in the database. All media files have also to correspond to only one Collection."
+ """ % tool_name
+
+def run():
+    l = len(sys.argv)
+    if l < 2:
+        print_usage()
+        sys.exit(1)
+    else:
+        project_dir = sys.argv[1]
+        source_dir = sys.argv[2]
+        source_file = None
+        if l == 4:
+            source_file = sys.argv[l-1]
+        sys.path.append(project_dir)
+        #from django.conf import settings
+        import settings
+        setup_environ(settings)
+        t = TelemetaMediaImport(settings, source_dir, source_file)
+        t.main()
+
+if __name__ == '__main__':
+    run()
index 8333b67b6b4e5b20dca560cc6f9a27495513b712..b6556f56a2240db0cda4185abb8708b334a6dcc5 100644 (file)
@@ -1,4 +1,5 @@
 #!/usr/bin/python
+# -*- coding: utf-8 -*-
 #
 # Copyright (C) 2008 Parisson
 # All rights reserved.
@@ -35,38 +36,65 @@ import shutil
 import datetime
 from django.core.management import setup_environ
 
+tool_mane = "wav_import"
+
 class TelemetaWavImport:
 
-    def __init__(self, id_string, source_dir, source_file=None):
+    def __init__(self, source_dir, source_file=None):
         from telemeta.models import MediaItem
-        self.item_media_root_dir = settings.MEDIA_ROOT + os.sep + 'items' + os.sep
-        #self.item_media_relative_dir = 'items' + os.sep
+        self.item_media_root_dir = settings.MEDIA_ROOT
+        self.item_media_relative_dir = os.sep + 'items' + os.sep
+        self.item_media_full_dir = self.item_media_root_dir + self.item_media_relative_dir
         self.source_dir = source_dir
         self.source_files = os.listdir(self.source_dir)
         self.source_file = source_file
-        self.item_list = MediaItem.objects.filter(id__startswith=id_string)
-        self.collection_id = self.item_list[0].collection_id
+        self.collection_id = self.get_collection(self.source_files)
         self.year = datetime.datetime.now().strftime("%Y")
         self.buffer_size = 0xFFFF
-        #self.dest_relative_dir = self.item_media_relative_dir + self.year + os.sep + self.collection_id + os.sep
-        self.dest_dir = self.item_media_root_dir + self.year + os.sep + self.collection_id + os.sep
-        
-    def copy_files(self)
+        self.dest_dir = self.item_media_full_dir + self.year + os.sep + self.collection_id + os.sep
+
+    def get_collection(file_list):
+        file_0 = file_list[0]
+        id_string = get_file_info(file_0)
+        self.item_list = MediaItem.objects.filter(id__startswith=id_string)
+        return self.item_list[0].collection_id
+
+    def copy_files(self):
         print self.dest_dir
         if not os.path.exists(self.dest_dir):
             os.makedirs(self.dest_dir)
         for file in self.source_files:
-            if not os.path.exists(self.dest_root_dir + file):
-                shutil.copy(self.source_dir + os.sep + file, self.dest_root_dir)
-        
-    def wav_import(self):
+            if not os.path.exists(self.dest_dir + file):
+                shutil.copy(self.source_dir + os.sep + file, self.dest_dir)
+
+    def wav_import_copy(self):
+        self.copy_files()
         if not self.source_file:
             self.files = os.listdir(self.dest_dir)
             self.files.sort()
         else:
             self.files = [self.source_file]
         print self.files
-        
+        id_list = map(get_file_info, self.files)
+        print id_list
+
+        for item_id in id_list:
+            try:
+                it = self.item_list.get(id=item_id)
+                #it.file._name = get_item_in_list(source_files, item_id)
+                print it.file._name
+                #it.save()
+            except:
+                raise "No item id correponding to" + it
+                break
+
+    def wav_import_write(self):
+        if not self.source_file:
+            self.files = os.listdir(self.dest_dir)
+            self.files.sort()
+        else:
+            self.files = [self.source_file]
+
         i = 0
         if len(self.files) >= len(self.item_list):
             for item in self.item_list:
@@ -82,18 +110,30 @@ class TelemetaWavImport:
                 print item.file.name
                 #item.file.write = unicode(self.dest_dir + self.files[i])
                 i += 1
-                
+
     def main(self):
-        #self.copy_files()
-        self.wav_import()
+        self.wav_import_copy()
+
+def get_file_info(media):
+    file_name = media.split(os.sep)[-1]
+    name = file_name.split('.')[-2]
+    ext = file_name.split('.')[-1]
+    return name
 
+def get_item_in_list(item_list, string):
+    for item in item_list:
+        if string in item:
+            return item
 
 def print_usage(tool_name):
-    print "Usage: "+tool_name+" <project_dir> <id_string> <source_dir> [<source_file>]"
-    print "  project_dir: the directory of the Django project which hosts Telemeta"
-    print "  id_string: the string to filter in the id table"
-    print "  source_dir: the directory containing the wav files to include"
-    print "  source_file: the wav file to include (optional)"
+    print """Usage: "+tool_name+" <project_dir> <source_dir> [<source_file>]
+    
+ project_dir: the directory of the Django project which hosts Telemeta
+ source_dir: the directory containing all media files to include
+ source_file: the media file to include (optional, if only one file)
+
+ IMPORTANT: all names without their extension have to correspond to at least one existing item id in the database !
+ """
 
 def run():
     if len(sys.argv) < 3:
@@ -110,9 +150,8 @@ def run():
         import settings
         sys.path.append(project_dir)
         setup_environ(settings)
-        t = TelemetaWavImport(id_string, source_dir, source_file)
+        t = TelemetaWavImport(source_dir, source_file)
         t.main()
-        
+
 if __name__ == '__main__':
     run()
-                
\ No newline at end of file