@@ -0,0 +1,2130 @@
+#!/usr/bin/python%0A#%0A# Copyright (C) 2008 Parisson%0A# All rights reserved.%0A#%0A# This software is licensed as described in the file COPYING, which%0A# you should have received as part of this distribution. The terms%0A# are also available at http://svn.parisson.org/telemeta/TelemetaLicense.%0A#%0A# Author: Guillaume Pellerin %3Cyomguy@parisson.com%3E%0A#%0A# usage example :%0A#%0A# $ python manage.py shell%0A# %3E%3E%3E from wav_import import TelemetaWavImport%0A# %3E%3E%3E id_string = 'BM.2006.002.001--25__01-0'%0A# %3E%3E%3E source_dir = '/home/momo/music/wav/CNRSMH_2006_002_GUYANE'%0A# %3E%3E%3E t = TelemetaWavImport(id_string, source_dir)%0A# %3E%3E%3E t.main()%0A%0A%0Aimport os%0Aimport sys%0Aimport shutil%0Aimport datetime%0Afrom telemeta.models import MediaItem%0Afrom django.conf import settings%0A%0Aclass TelemetaWavImport:%0A%0A    def __init__(self, id_string, source_dir):%0A        self.item_media_root_dir = settings.MEDIA_ROOT + os.sep + 'items' + os.sep%0A        self.source_dir = source_dir%0A        self.source_files = os.listdir(self.source_dir)%0A        self.item_list = MediaItem.objects.filter(id__startswith=id_string)%0A        self.collection_id = self.item_list%5B0%5D.collection_id%0A        self.year = datetime.datetime.now().strftime(%22%25Y%22)%0A        self.dest_dir = self.item_media_root_dir + self.year + os.sep + self.collection_id%0A  %0A    def copy_files(self):%0A        if not os.path.exists(self.dest_dir):%0A            os.makedirs(self.dest_dir)%0A        for file in self.source_files:%0A            shutil.copy(self.source_dir + os.sep + file, self.dest_dir)%0A        %0A    def wav_import(self):%0A        self.files = os.listdir(self.dest_dir)%0A        self.files.sort()%0A        #print self.files%0A        i = 0%0A        if len(self.files) %3E len(self.item_list):%0A            for item in self.item_list:%0A                #item = MediaItem.objects.get(id=object.id)%0A                print item.id + %22 : %22 + item.title + %22 : %22%0A                item.file._name = unicode(self.dest_dir + os.sep + self.files%5Bi%5D)%0A                item.save()%0A                print item.file._name%0A                i += 1%0A                %0A    def main(self):%0A        self.copy_files()%0A        self.wav_import()%0A        %0A        

add wav_import tool