# -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 # Written 2009 by j@mailb.org import os from glob import glob import oxlib import oxlib.normalize from django.core.management.base import BaseCommand, CommandError from django.conf import settings from texts.text import models class Command(BaseCommand): """ import texts from media/text. """ help = 'import texts that are not in db.' args = '' def handle(self, **options): for f in glob('%s/*/*/*' % settings.MEDIA_ROOT): if os.path.isfile(f): name = f[len(settings.MEDIA_ROOT)+1:] name = name.decode('utf-8') q = models.Text.objects.filter(file=name) if q.count() == 0: print 'adding', name text = models.Text() text.file.name = name text.parsePath()