Beispiel #1
0
def convert(*args):
    '''Create an epub-format zip file given a source XML file.
       Based on the tutorial from: http://www.jedisaber.com/eBooks/tutorial.asp
    '''

    if len(args) < 2:
        print 'Usage: create-epub.py tei-source-file [alternate output path]'
        return 1

    source = args[1]

    if len(args) > 2:
        path = '%s/%s' % (settings.BUILD, args[2])
    else:
        if not '.xml' in source:
            log.error('Source file must have a .xml extension')
            return 1
        path = '%s/%s' % (settings.BUILD, os.path.basename(source).replace(
            '.xml', ''))

    tree = etree.parse(source)

    if not os.path.exists(settings.BUILD):
        os.mkdir(settings.BUILD)

    if not os.path.exists(settings.DIST):
        os.mkdir(settings.DIST)

    if os.path.exists(path):
        log.debug('Removing previous output path %s' % path)
        shutil.rmtree(path)

    log.debug('Creating path %s' % path)
    os.mkdir(path)

    # Create the epub content
    create_folders(path)
    create_mimetype(path)
    create_container(path)
    create_stylesheet(path)
    create_navmap(path, tree)
    create_content(path, tree)
    create_html(path, tree)

    # Create the epub format
    epubtools.find_resources(path)
    epubtools.create_mimetype(path)
    epub_archive = epubtools.create_archive(path)

    # Validate
    if settings.VALIDATE:
        return epub.validate(epub_archive)
    log.warn('Skipping validation step')
    return 0
def convert(*args):
    '''Create an epub-format zip file given a source XML file.
       Based on the tutorial from: http://www.jedisaber.com/eBooks/tutorial.asp
    '''

    if len(args) < 2:
        print 'Usage: create-epub.py tei-source-file [alternate output path]'
        return 1

    source = args[1]

    if len(args) > 2:
        path = '%s/%s' % (settings.BUILD, args[2])
    else:
        if not '.xml' in source:
            log.error('Source file must have a .xml extension')
            return 1
        path = '%s/%s' % (settings.BUILD, os.path.basename(source).replace('.xml', ''))

    tree = etree.parse(source)

    if not os.path.exists(settings.BUILD):
        os.mkdir(settings.BUILD)

    if not os.path.exists(settings.DIST):
        os.mkdir(settings.DIST)

    if os.path.exists(path):
        log.debug('Removing previous output path %s' % path)
        shutil.rmtree(path)

    log.debug('Creating path %s' % path)
    os.mkdir(path)

    # Create the epub content
    create_folders(path)
    create_mimetype(path)
    create_container(path)
    create_stylesheet(path)
    create_navmap(path, tree)
    create_content(path, tree)
    create_html(path, tree)

    # Create the epub format
    epubtools.find_resources(path)
    epubtools.create_mimetype(path)
    epub_archive = epubtools.create_archive(path)

    # Validate
    if settings.VALIDATE:
        return epub.validate(epub_archive)
    log.warn('Skipping validation step')
    return 0
Beispiel #3
0
def convert(docbook_file, xsl, css=None):
    path = convert_docbook(docbook_file, xsl, css)
    epub.find_resources(path)
    epub.create_mimetype(path)
    epub_archive = epub.create_archive(path)

    log.info("Created epub archive as '%s'" % epub_archive)

    # Validate
    if settings.VALIDATE:
        return epub.validate(epub_archive)

    # Clean up the output directory
    shutil.rmtree(path)
def convert(docbook_file, xsl, css=None):
    path = convert_docbook(docbook_file, xsl, css)
    epub.find_resources(path)
    epub.create_mimetype(path)
    epub_archive = epub.create_archive(path)

    log.info("Created epub archive as '%s'" % epub_archive)

    # Validate
    if settings.VALIDATE:
        return epub.validate(epub_archive )

    # Clean up the output directory
    shutil.rmtree(path)