Esempio n. 1
0
def store_upload(upload):
    """Store the file uploaded
    """
    oggname = None
    newpath = move_file(upload.path, upload.filename)
    try:
        mime = Mime.objects.get(name=upload.content_type)
        logger.info("will use %s() to convert %s" % (mime.function,
                                                     mime.name))
    except ObjectDoesNotExist:
        logger.error("(%s) wrong mime/type for %s %s" % ('store_upload',
                                                         newpath,
                                                         upload.content_type))
        upload.status = 'bad format'
        upload.save()
        return 1

    convert = getattr(calorine.caro.converters, mime.function)
    oggname = convert(newpath, upload)

    if oggname is None:
        return 2
    else:
        importsong(oggname)
        upload.status = 'done'
        upload.save()
        mail_uploader.delay(upload)
        return 0
Esempio n. 2
0
    def handle(self, *args, **options):

        exists = 0
        errors = 0
        update = 0
        insert = 0

        if len(args) > 0:
            dirpath = abspath(args[0])
        else:
            return "missing path, please add path to lookup\n"

        if not isdir(dirpath):
            return "path %s does not exists\n" % dirpath

        for fpath in importdir(dirpath):
            result = importsong(fpath)
            if result.startswith('[I]'):
                insert += 1
            elif result.startswith('[U]'):
                update += 1
            elif result.startswith('[X]'):
                exists += 1
            else:
                errors += 1

            self.stdout.write(result)

        self.stdout.write("%d songs already present db\n" % exists)
        self.stdout.write("%d songs path updated in db\n" % update)
        self.stdout.write("%d songs inserted in db\n" % insert)
        self.stdout.write("%d songs in error\n" % errors)