Beispiel #1
0
    def handle(self, *filenames, **kwargs):
        if filenames:
            for filename in filenames:
                if filename.endswith('.txt'):
                    filename = filename[:-4]
                if filename.endswith('.html'):
                    filename = filename[:-5]
                print converter.convert(filename)
            return

        front = len(settings.CM_IN_DIR)
        for dirname, dirnames, filenames in os.walk(settings.CM_IN_DIR):
            dir = dirname[front:]
            for filename in filter(self.auto_convert.match, filenames):
                self.handle(os.path.join(dir, filename))
Beispiel #2
0
def convert_template(template_name, template_dirs=None):
    if template_name.endswith('.html'):
        lookup_name = template_name[:-5]
    elif template_name.endswith('.txt'):
        lookup_name = template_name[:-4]
    else:
        lookup_name = template_name
    try:
        filename = converter.convert(lookup_name, template_name)
    except (ConversionError, FileNotFound):
        error_msg = 'Tried %s in %s' % (template_name, settings.CM_IN_DIR)
        raise TemplateDoesNotExist(error_msg)
    return (open(filename).read().decode(settings.FILE_CHARSET), filename)