python-tldp/tldp/doctypes/common.py

59 lines
1.6 KiB
Python
Raw Normal View History

2016-02-11 03:22:23 +00:00
#! /usr/bin/python
2016-02-18 21:25:02 +00:00
# -*- coding: utf8 -*-
2016-02-11 03:22:23 +00:00
from __future__ import absolute_import, division, print_function
2016-02-11 03:22:23 +00:00
import os
2016-02-11 03:22:23 +00:00
from ..utils import logger
class SignatureChecker(object):
@classmethod
def signatureLocation(cls, f):
f.seek(0)
buf = f.read(1024).lower()
2016-02-11 03:22:23 +00:00
for sig in cls.signatures:
try:
sindex = buf.index(sig.lower())
logger.debug("Found signature %s in %s at %s; doctype %s.",
sig, f.name, sindex, cls)
2016-02-11 03:22:23 +00:00
return sindex
except ValueError:
logger.debug("Signature %s not found in %s for type %s",
sig, f.name, cls.__name__)
2016-02-11 03:22:23 +00:00
return None
class BaseDoctype(object):
def __init__(self, *args, **kwargs):
self.source = kwargs.get('source', None)
self.output = kwargs.get('output', None)
2016-02-23 17:43:27 +00:00
self.config = kwargs.get('config', None)
assert None not in (self.source, self.output, self.config)
def generate(self):
2016-02-23 19:08:04 +00:00
def last(l):
return l[-1]
self.output.prebuild_hook()
os.chdir(self.output.dirname)
2016-02-23 19:08:04 +00:00
command = list()
command.append(self.build_precheck())
if not last(command):
return False
command.append(self.create_htmls())
command.append(self.create_pdf())
command.append(self.create_txt())
command.append(self.create_html())
result = all(command)
if result:
self.output.build_success_hook()
else:
self.output.build_failure_hook()
2016-02-23 19:08:04 +00:00
return result
2016-02-11 03:22:23 +00:00
#
# -- end of file