From a4a76b185219ed593710b641014f23a3a2b73869 Mon Sep 17 00:00:00 2001 From: yomguy Date: Sun, 4 Apr 2010 09:14:46 +0000 Subject: [PATCH] check item ref existence git-svn-id: http://svn.parisson.org/svn/crem@168 3bf09e05-f825-4182-b9bc-eedd7160adf0 --- trunk/import/audio_import/wav_import.py | 27 +++++++++++++++---------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/trunk/import/audio_import/wav_import.py b/trunk/import/audio_import/wav_import.py index 5dfec85..ebb34c3 100644 --- a/trunk/import/audio_import/wav_import.py +++ b/trunk/import/audio_import/wav_import.py @@ -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): -- 2.39.5