X-Git-Url: https://git.mdrn.pl/edumed.git/blobdiff_plain/d0f0e1412cc42d366b234e798dfb68feed05d751..d555d988764995ea1f9f5ece46f453a66f09b334:/catalogue/management/commands/extract_attachments.py diff --git a/catalogue/management/commands/extract_attachments.py b/catalogue/management/commands/extract_attachments.py deleted file mode 100644 index 1735cbf..0000000 --- a/catalogue/management/commands/extract_attachments.py +++ /dev/null @@ -1,41 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of EduMed, licensed under GNU Affero GPLv3 or later. -# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. -# -import errno -from optparse import make_option -import os -import shutil - -from django.core.management.base import BaseCommand - - -def makedir(directory): - try: - os.makedirs(directory) - except OSError as e: - if e.errno != errno.EEXIST: - raise - - -class Command(BaseCommand): - help = 'Extracts attachments from given lessons.' - - option_list = BaseCommand.option_list + ( - make_option('--slugs', dest='slugs_path', metavar="PATH", default=None, - help='PATH to file with lesson slugs.'), - ) - - def handle(self, **options): - from catalogue.models import Lesson - - lessons = Lesson.objects.order_by('slug') - if options.get('slugs_path'): - slugs = [line.strip() for line in open(options.get('slugs_path')) if line.strip()] - lessons = lessons.filter(slug__in=slugs) - - for lesson in lessons: - makedir('materialy/%s' % lesson.slug) - for attachment in lesson.attachment_set.all(): - shutil.copy(attachment.file.path, 'materialy/%s/%s.%s' % (lesson.slug, attachment.slug, attachment.ext)) -