]> git.parisson.com Git - telemeta-data.git/commitdiff
check item ref existence
authoryomguy <yomguy@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Sun, 4 Apr 2010 09:14:46 +0000 (09:14 +0000)
committeryomguy <yomguy@3bf09e05-f825-4182-b9bc-eedd7160adf0>
Sun, 4 Apr 2010 09:14:46 +0000 (09:14 +0000)
git-svn-id: http://svn.parisson.org/svn/crem@168 3bf09e05-f825-4182-b9bc-eedd7160adf0

trunk/import/audio_import/wav_import.py

index 5dfec85a625489dd18fad3a81a8b4fd1a5a434f9..ebb34c3b03cc3d185d7915255cb5190007168e98 100644 (file)
@@ -54,24 +54,29 @@ class TelemetaWavImport:
             collection_files = os.listdir(self.source_dir + os.sep + collection)
             if not collection + '.csv' in collection_files:
                 msg = 'Le fichier CSV est mal nommé ou inexistant'
-                self.logger.write_error(collection.dir, msg)
+                self.logger.write_error(collection, msg)
             else:
                 c = csv.reader(open(self.source_dir + os.sep + collection + os.sep + collection + '.csv'), delimiter=';')
                 for row in c:
                     old_ref = row[0]
                     new_ref = row[1]
+                    print old_ref + ' : ' + new_ref
                     filename = new_ref + '.wav'
                     wav_file = self.source_dir + os.sep + collection + os.sep + filename
-                    item = MediaItem.objects.filter(old_code=old_ref)[0]
-                    print item.old_code + ' : id = ' + str(item.id) + " : title = " + item.title
-                    print item.file.path + ' : ' + item.file.name
-
-                    f = open(wav_file, 'r')
-                    file_content = ContentFile(f.read())
-                    item.file.save(filename, file_content)
-                    f.close()
-                    item.code = new_ref
-                    item.save()
+                    items = MediaItem.objects.filter(old_code=old_ref)
+                    if len(items) != 0:
+                        item = items[0]
+                        print item.old_code + ' : id = ' + str(item.id) + " : title = " + item.title
+                        f = open(wav_file, 'r')
+                        file_content = ContentFile(f.read())
+                        item.file.save(filename, file_content)
+                        f.close()
+                        item.code = new_ref
+                        item.save()
+                    else:
+                        msg = old_ref + ' : item inexistant dans la base de données !'
+                        print msg
+                        self.logger.write_error(collection, msg)
 
 
 def print_usage(tool_name):