From: yomguy Date: Wed, 9 Feb 2011 14:01:11 +0000 (+0100) Subject: add collection to media-link script X-Git-Tag: 1.1~458 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=9f2bdee0bf7b2e3a0ad9a7b9046503e107f4c42e;p=telemeta.git add collection to media-link script --- diff --git a/tools/scripts/telemeta-backup b/tools/scripts/telemeta-backup deleted file mode 100755 index 2ccf0094..00000000 --- a/tools/scripts/telemeta-backup +++ /dev/null @@ -1,94 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# -*- coding: utf-8 -*- -# -# Copyright (C) 2007 Samalyse SARL - -# 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. -# -# Author: Olivier Guilyardi - -import os -import sys -import time -from django.core.management import setup_environ - -def print_usage(toolname): - print "Usage: " + toolname + " " - print " project_dir: the directory of the Django project which hosts Telemeta" - print " backup_dir: the destination backup folder (must exist)" - -def write_readme(dest_dir, coll_num): - readme = open(dest_dir + "/" + "README", "w") - timestr = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) - readme.write("Telemeta Backup\n\n") - readme.write("- date: " + timestr + "\n") - readme.write("- number of collections: " + str(coll_num) + "\n\n") - readme.close() - -def backup(dest_dir): - from telemeta.models import MediaCollection - from telemeta.backup import CollectionSerializer - - collections = MediaCollection.objects.order_by('id') - count = collections.count() - - print "Writing README file..", - write_readme(dest_dir, count) - print "Done." - - i = 0 - for collection in collections: - if i % 100 == 0: - set_dir = dest_dir + ("/collections-%d-%d" % (i+1, i+100)) - os.mkdir(set_dir) - i += 1 - print "Processing collection %d/%d (%d%%) with id: %s.. " \ - % (i, count, i*100/count, collection.id), - sys.stdout.flush() - serializer = CollectionSerializer(collection) - serializer.store(set_dir) - print "Done" - -def run(): - if len(sys.argv) != 3: - print_usage(os.path.basename(sys.argv[0])) - sys.exit(1) - else: - project_dir = sys.argv[1] - backup_dir = sys.argv[2] - sys.path.append(project_dir) - import settings - setup_environ(settings) - backup(backup_dir) - -if __name__ == '__main__': - run() diff --git a/tools/scripts/telemeta-backup.py b/tools/scripts/telemeta-backup.py new file mode 100755 index 00000000..2ccf0094 --- /dev/null +++ b/tools/scripts/telemeta-backup.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# -*- coding: utf-8 -*- +# +# Copyright (C) 2007 Samalyse SARL + +# 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. +# +# Author: Olivier Guilyardi + +import os +import sys +import time +from django.core.management import setup_environ + +def print_usage(toolname): + print "Usage: " + toolname + " " + print " project_dir: the directory of the Django project which hosts Telemeta" + print " backup_dir: the destination backup folder (must exist)" + +def write_readme(dest_dir, coll_num): + readme = open(dest_dir + "/" + "README", "w") + timestr = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) + readme.write("Telemeta Backup\n\n") + readme.write("- date: " + timestr + "\n") + readme.write("- number of collections: " + str(coll_num) + "\n\n") + readme.close() + +def backup(dest_dir): + from telemeta.models import MediaCollection + from telemeta.backup import CollectionSerializer + + collections = MediaCollection.objects.order_by('id') + count = collections.count() + + print "Writing README file..", + write_readme(dest_dir, count) + print "Done." + + i = 0 + for collection in collections: + if i % 100 == 0: + set_dir = dest_dir + ("/collections-%d-%d" % (i+1, i+100)) + os.mkdir(set_dir) + i += 1 + print "Processing collection %d/%d (%d%%) with id: %s.. " \ + % (i, count, i*100/count, collection.id), + sys.stdout.flush() + serializer = CollectionSerializer(collection) + serializer.store(set_dir) + print "Done" + +def run(): + if len(sys.argv) != 3: + print_usage(os.path.basename(sys.argv[0])) + sys.exit(1) + else: + project_dir = sys.argv[1] + backup_dir = sys.argv[2] + sys.path.append(project_dir) + import settings + setup_environ(settings) + backup(backup_dir) + +if __name__ == '__main__': + run() diff --git a/tools/scripts/telemeta-crem-import.py b/tools/scripts/telemeta-crem-import.py new file mode 100755 index 00000000..1bdc4430 --- /dev/null +++ b/tools/scripts/telemeta-crem-import.py @@ -0,0 +1,103 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2010 Guillaume Pellerin +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://svn.parisson.org/telemeta/TelemetaLicense. +# +# Author: Guillaume Pellerin +# + +import os +import sys +import csv +import logging +import datetime +from django.core.management import setup_environ +from django.core.files.base import ContentFile + +class Logger: + + def __init__(self, file): + self.logger = logging.getLogger('myapp') + self.hdlr = logging.FileHandler(file) + self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + self.hdlr.setFormatter(self.formatter) + self.logger.addHandler(self.hdlr) + self.logger.setLevel(logging.INFO) + + def write_info(self, prefix, message): + self.logger.info(' ' + prefix + ' : ' + message.decode('utf8')) + + def write_error(self, prefix, message): + self.logger.error(prefix + ' : ' + message.decode('utf8')) + + +class TelemetaWavImport: + + def __init__(self, source_dir, log_file): + self.logger = Logger(log_file) + self.source_dir = source_dir + self.collections = os.listdir(self.source_dir) + self.buffer_size = 0x1000 + + def wav_import(self): + from telemeta.models import media + for collection in self.collections: + self.collection_name = collection.split(os.sep)[-1] + msg = '************************ ' + collection + ' ******************************' + self.logger.write_info(collection, msg[:70]) + + 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, 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 + items = media.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): + print "Usage: "+tool_name+" " + print " project_dir: the directory of the Django project which hosts Telemeta" + print " source_dir: the directory containing the wav files to include" + print " log_file: the log file of the import" + +def run(): + if len(sys.argv) < 4: + print_usage(os.path.basename(sys.argv[0])) + sys.exit(1) + else: + project_dir = sys.argv[-3] + source_dir = sys.argv[-2] + log_file = sys.argv[-1] + sys.path.append(project_dir) + import settings + setup_environ(settings) + t = TelemetaWavImport(source_dir, log_file) + t.wav_import() + +if __name__ == '__main__': + run() diff --git a/tools/scripts/telemeta-import b/tools/scripts/telemeta-import deleted file mode 100755 index 1bdc4430..00000000 --- a/tools/scripts/telemeta-import +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Guillaume Pellerin -# All rights reserved. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. The terms -# are also available at http://svn.parisson.org/telemeta/TelemetaLicense. -# -# Author: Guillaume Pellerin -# - -import os -import sys -import csv -import logging -import datetime -from django.core.management import setup_environ -from django.core.files.base import ContentFile - -class Logger: - - def __init__(self, file): - self.logger = logging.getLogger('myapp') - self.hdlr = logging.FileHandler(file) - self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') - self.hdlr.setFormatter(self.formatter) - self.logger.addHandler(self.hdlr) - self.logger.setLevel(logging.INFO) - - def write_info(self, prefix, message): - self.logger.info(' ' + prefix + ' : ' + message.decode('utf8')) - - def write_error(self, prefix, message): - self.logger.error(prefix + ' : ' + message.decode('utf8')) - - -class TelemetaWavImport: - - def __init__(self, source_dir, log_file): - self.logger = Logger(log_file) - self.source_dir = source_dir - self.collections = os.listdir(self.source_dir) - self.buffer_size = 0x1000 - - def wav_import(self): - from telemeta.models import media - for collection in self.collections: - self.collection_name = collection.split(os.sep)[-1] - msg = '************************ ' + collection + ' ******************************' - self.logger.write_info(collection, msg[:70]) - - 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, 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 - items = media.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): - print "Usage: "+tool_name+" " - print " project_dir: the directory of the Django project which hosts Telemeta" - print " source_dir: the directory containing the wav files to include" - print " log_file: the log file of the import" - -def run(): - if len(sys.argv) < 4: - print_usage(os.path.basename(sys.argv[0])) - sys.exit(1) - else: - project_dir = sys.argv[-3] - source_dir = sys.argv[-2] - log_file = sys.argv[-1] - sys.path.append(project_dir) - import settings - setup_environ(settings) - t = TelemetaWavImport(source_dir, log_file) - t.wav_import() - -if __name__ == '__main__': - run() diff --git a/tools/scripts/telemeta-media-import.py b/tools/scripts/telemeta-media-import.py deleted file mode 100755 index bd998e74..00000000 --- a/tools/scripts/telemeta-media-import.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/usr/bin/python -# -*- coding: utf-8 -*- -# -# Copyright (C) 2010 Guillaume Pellerin -# All rights reserved. -# -# This software is licensed as described in the file COPYING, which -# you should have received as part of this distribution. The terms -# are also available at http://svn.parisson.org/telemeta/TelemetaLicense. -# -# Author: Guillaume Pellerin -# - -import os -import sys -import logging -import datetime -from django.core.management import setup_environ -from django.core.files.base import ContentFile - - -class Logger: - - def __init__(self, file): - self.logger = logging.getLogger('myapp') - self.hdlr = logging.FileHandler(file) - self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') - self.hdlr.setFormatter(self.formatter) - self.logger.addHandler(self.hdlr) - self.logger.setLevel(logging.INFO) - - def write_info(self, prefix, message): - self.logger.info(' ' + prefix + ' : ' + message.decode('utf8')) - - def write_error(self, prefix, message): - self.logger.error(prefix + ' : ' + message.decode('utf8')) - - -class TelemetaMediaImport: - - def __init__(self, media_dir, log_file): - self.logger = Logger(log_file) - self.media_dir = media_dir + os.sep + 'items' - self.medias = self.get_medias() - self.buffer_size = 0x1000 - self.media_item_dir = 'items/' - - def get_medias(self): - medias = [] - list = os.listdir(self.media_dir) - for element in list: - if os.path.isfile(self.media_dir+os.sep+element): - medias.append(element) - return medias - - def set_collection(self, collection_name): - import telemeta.models - collections = telemeta.models.media.MediaCollection.objects.filter(code=collection_name) - if not collections: - c = telemeta.models.media.MediaCollection(code=collection_name) - c.title = collection_name - c.save() - msg = 'added' - self.logger.write_info(collection_name, msg) - collection = c - else: - collection = collections[0] - return collection - - def media_import(self): - import telemeta.models - self.collection_name = 'awdio' - self.collection = self.set_collection(self.collection_name) - - for media in self.medias: - filename, ext = os.path.splitext(media) - item = telemeta.models.media.MediaItem.objects.filter(code=filename) - if not item: - print media - item = telemeta.models.media.MediaItem(collection=self.collection, code=filename) - item.title = filename - item.file = self.media_item_dir + media - item.save() - msg = 'added item : ' + filename - self.logger.write_info(self.collection_name, msg) - - -def run(): - project_dir = sys.argv[-2] - log_file = sys.argv[-1] - sys.path.append(project_dir) - import settings - setup_environ(settings) - media_dir = settings.MEDIA_ROOT - t = TelemetaMediaImport(media_dir, log_file) - t.media_import() - -if __name__ == '__main__': - run() diff --git a/tools/scripts/telemeta-media-link.py b/tools/scripts/telemeta-media-link.py new file mode 100755 index 00000000..8b607e5a --- /dev/null +++ b/tools/scripts/telemeta-media-link.py @@ -0,0 +1,100 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2010 Guillaume Pellerin +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://svn.parisson.org/telemeta/TelemetaLicense. +# +# Author: Guillaume Pellerin +# + +import os +import sys +import logging +import datetime +from django.core.management import setup_environ +from django.core.files.base import ContentFile + + +class Logger: + + def __init__(self, file): + self.logger = logging.getLogger('myapp') + self.hdlr = logging.FileHandler(file) + self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + self.hdlr.setFormatter(self.formatter) + self.logger.addHandler(self.hdlr) + self.logger.setLevel(logging.INFO) + + def write_info(self, prefix, message): + self.logger.info(' ' + prefix + ' : ' + message.decode('utf8')) + + def write_error(self, prefix, message): + self.logger.error(prefix + ' : ' + message.decode('utf8')) + + +class TelemetaMediaImport: + + def __init__(self, collection, media_dir, log_file): + self.logger = Logger(log_file) + self.media_dir = media_dir + os.sep + 'items' + self.medias = self.get_medias() + self.buffer_size = 0x1000 + self.media_item_dir = 'items/' + self.collection_name = collection + self.collection = self.set_collection(self.collection_name) + + + def get_medias(self): + medias = [] + list = os.listdir(self.media_dir) + for element in list: + if os.path.isfile(self.media_dir+os.sep+element): + medias.append(element) + return medias + + def set_collection(self, collection_name): + import telemeta.models + collections = telemeta.models.media.MediaCollection.objects.filter(code=collection_name) + if not collections: + c = telemeta.models.media.MediaCollection(code=collection_name) + c.title = collection_name + c.save() + msg = 'added' + self.logger.write_info(collection_name, msg) + collection = c + else: + collection = collections[0] + return collection + + def media_import(self): + import telemeta.models + for media in self.medias: + filename, ext = os.path.splitext(media) + item = telemeta.models.media.MediaItem.objects.filter(code=filename) + if not item: + print media + item = telemeta.models.media.MediaItem(collection=self.collection, code=filename) + item.title = filename + item.file = self.media_item_dir + media + item.save() + msg = 'added item : ' + filename + self.logger.write_info(self.collection_name, msg) + + +def run(): + collection = sys.argv[-2] + project_dir = sys.argv[-3] + log_file = sys.argv[-1] + sys.path.append(project_dir) + import settings + setup_environ(settings) + media_dir = settings.MEDIA_ROOT + t = TelemetaMediaImport(collection, media_dir, log_file) + t.media_import() + +if __name__ == '__main__': + run()