Exemple #1
0
def test_create_ebook():
    book_dir = os.path.join(BASE_DIR, 'resources/civil_disobedience/')
    if not os.path.exists(os.path.join(book_dir, 'audio')):
        download_files.download_files(
            'https://librivox.org/civil-disobedience-by-henry-david-thoreau/',
            book_dir,
            skip_text=True)
    create.create_ebook(book_dir)
    res = EpubCheck(
        os.path.join(book_dir, 'out/on_the_duty_of_civil_disobedience.epub'))
    assert res.valid is True
Exemple #2
0
    def run_epubcheck(self, epub):
        """ Runs epubcheck and stores the output. """
        result = EpubCheck(epub)
        self.results['epubcheck'] = result

        if result.valid:
            self.logger.info("EpubCheck passed")
        else:
            self.logger.info("EpubCheck failed")
            print("EpubCheck result: {}\n{}".format(
                result.valid,
                pformat(result.messages),
            ))

        return result
def test_create_ebook():
    book_dir = os.path.join(BASE_DIR, 'resources/civil_disobedience/')
    if not os.path.exists(os.path.join(book_dir, 'audio')):
        download_files.download_files(
            'https://librivox.org/civil-disobedience-by-henry-david-thoreau/',
            book_dir,
            skip_text=True)
    smil_dir = os.path.join(book_dir, 'smil')

    try:
        create.create_ebook(book_dir)
    finally:
        # Remove smil dir so that the next time the test performs a sync again
        if os.path.exists(smil_dir):
            shutil.rmtree(smil_dir)

    res = EpubCheck(
        os.path.join(book_dir, 'out/on_the_duty_of_civil_disobedience.epub'))
    assert res.valid is True
Exemple #4
0
import pandas as pd
from epubcheck import EpubCheck

# Check to see if the epub file can be accessed by others in the same package.
dataframe = pd.read_csv(
    filepath_or_buffer='Neuronal_circuits_of_fear_extinction.epub')
# Good! The IDE did detect the epub file and auto-complete the remaining file name input.

result = EpubCheck(infile='Neuronal_circuits_of_fear_extinction.epub',
                   lang='EN')
print(result.valid)
print('=' * 30)
print(result.messages)
from epubcheck import EpubCheck

result = EpubCheck('Neuronal_circuits_of_fear_extinction.epub', lang='en')

print(result.valid)
print('=' * 30)
print(result.messages)
Exemple #6
0
def validate(epub):
    """Validate file with Epubcheck"""
    ecOut = EpubCheck(epub)
    ecOutMeta = ecOut.meta
    ecOutMessages = ecOut.messages

    # Dictionary for Epubcheck results
    ecResults = {}

    ecResults['file'] = epub
    ecResults['valid'] = ecOut.valid

    # Metadata
    meta = {}

    meta['publisher'] = ecOutMeta.publisher
    meta['title'] = ecOutMeta.title
    meta['creator'] = ecOutMeta.creator
    meta['date'] = ecOutMeta.date
    meta['subject'] = ecOutMeta.subject
    meta['description'] = ecOutMeta.description
    meta['rights'] = ecOutMeta.rights
    meta['identifier'] = ecOutMeta.identifier
    meta['language'] = ecOutMeta.language
    meta['nSpines'] = ecOutMeta.nSpines
    meta['checkSum'] = ecOutMeta.checkSum
    meta['renditionLayout'] = ecOutMeta.renditionLayout
    meta['renditionOrientation'] = ecOutMeta.renditionOrientation
    meta['renditionSpread'] = ecOutMeta.renditionSpread
    meta['ePubVersion'] = ecOutMeta.ePubVersion
    meta['isScripted'] = ecOutMeta.isScripted
    meta['hasFixedFormat'] = ecOutMeta.hasFixedFormat
    meta['isBackwardCompatible'] = ecOutMeta.isBackwardCompatible
    meta['hasAudio'] = ecOutMeta.hasAudio
    meta['hasVideo'] = ecOutMeta.hasVideo
    meta['charsCount'] = ecOutMeta.charsCount
    meta['embeddedFonts'] = ecOutMeta.embeddedFonts
    meta['refFonts'] = ecOutMeta.refFonts
    meta['hasEncryption'] = ecOutMeta.hasEncryption
    meta['hasSignatures'] = ecOutMeta.hasSignatures
    meta['contributors'] = ecOutMeta.contributors

    # Validation errors and warnings
    errors = []
    warnings = []
    infos = []
    for ecOutMessage in ecOutMessages:
        message = {}
        message['id'] = ecOutMessage.id
        message['level'] = ecOutMessage.level
        message['location'] = ecOutMessage.location
        message['message'] = ecOutMessage.message
        if ecOutMessage.level in ['ERROR', 'FATAL']:
            errors.append(message)
        elif ecOutMessage.level == 'WARNING':
            warnings.append(message)
        else:
            infos.append(message)

    ecResults['valid'] = ecOut.valid
    ecResults['meta'] = meta
    ecResults['errors'] = errors
    ecResults['warnings'] = warnings
    ecResults['infos'] = infos

    return ecResults
Exemple #7
0
def test_epubcheck_valid():
    check = EpubCheck(samples.EPUB3_VALID)
    assert check.valid is True
    assert check.checker.nError == 0
Exemple #8
0
def test_epubcheck_invalid():
    check = EpubCheck(samples.EPUB3_INVALID)
    assert check.valid is False
    assert check.checker.nError == 2