本文整理汇总了Python中calibre.utils.logging.Log.error方法的典型用法代码示例。如果您正苦于以下问题:Python Log.error方法的具体用法?Python Log.error怎么用?Python Log.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.utils.logging.Log
的用法示例。
在下文中一共展示了Log.error方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from calibre.utils.logging import Log [as 别名]
# 或者: from calibre.utils.logging.Log import error [as 别名]
def main(args=sys.argv):
log = Log()
parser, plumber = create_option_parser(args, log)
opts, leftover_args = parser.parse_args(args)
if len(leftover_args) > 3:
log.error('Extra arguments not understood:', u', '.join(leftover_args[3:]))
return 1
for x in ('read_metadata_from_opf', 'cover'):
if getattr(opts, x, None) is not None:
setattr(opts, x, abspath(getattr(opts, x)))
if opts.search_replace:
opts.search_replace = read_sr_patterns(opts.search_replace, log)
recommendations = [(n.dest, getattr(opts, n.dest),
OptionRecommendation.HIGH)
for n in parser.options_iter()
if n.dest]
plumber.merge_ui_recommendations(recommendations)
try:
plumber.run()
except ConversionUserFeedBack as e:
ll = {'info': log.info, 'warn': log.warn,
'error':log.error}.get(e.level, log.info)
ll(e.title)
if e.det_msg:
log.debug(e.detmsg)
ll(e.msg)
raise SystemExit(1)
log(_('Output saved to'), ' ', plumber.output)
return 0
示例2: main
# 需要导入模块: from calibre.utils.logging import Log [as 别名]
# 或者: from calibre.utils.logging.Log import error [as 别名]
def main(args=sys.argv):
log = Log()
parser, plumber = create_option_parser(args, log)
opts, leftover_args = parser.parse_args(args)
if len(leftover_args) > 3:
log.error('Extra arguments not understood:', u', '.join(leftover_args[3:]))
return 1
for x in ('read_metadata_from_opf', 'cover'):
if getattr(opts, x, None) is not None:
setattr(opts, x, abspath(getattr(opts, x)))
if opts.search_replace:
opts.search_replace = read_sr_patterns(opts.search_replace, log)
if opts.transform_css_rules:
from calibre.ebooks.css_transform_rules import import_rules, validate_rule
with open(opts.transform_css_rules, 'rb') as tcr:
opts.transform_css_rules = rules = list(import_rules(tcr.read()))
for rule in rules:
title, msg = validate_rule(rule)
if title and msg:
log.error('Failed to parse CSS transform rules')
log.error(title)
log.error(msg)
return 1
recommendations = [(n.dest, getattr(opts, n.dest),
OptionRecommendation.HIGH)
for n in parser.options_iter()
if n.dest]
plumber.merge_ui_recommendations(recommendations)
try:
plumber.run()
except ConversionUserFeedBack as e:
ll = {'info': log.info, 'warn': log.warn,
'error':log.error}.get(e.level, log.info)
ll(e.title)
if e.det_msg:
log.debug(e.detmsg)
ll(e.msg)
raise SystemExit(1)
log(_('Output saved to'), ' ', plumber.output)
return 0
示例3: main
# 需要导入模块: from calibre.utils.logging import Log [as 别名]
# 或者: from calibre.utils.logging.Log import error [as 别名]
def main(args=None):
parser = option_parser()
opts, args = parser.parse_args(args or sys.argv[1:])
log = Log(level=Log.DEBUG if opts.verbose else Log.INFO)
if not args:
parser.print_help()
log.error(_('You must provide the input file to polish'))
raise SystemExit(1)
if len(args) > 2:
parser.print_help()
log.error(_('Unknown extra arguments'))
raise SystemExit(1)
if len(args) == 1:
inbook = args[0]
base, ext = inbook.rpartition('.')[0::2]
outbook = base + '_polished.' + ext
else:
inbook, outbook = args
popts = ALL_OPTS.copy()
for k, v in popts.iteritems():
popts[k] = getattr(opts, k, None)
O = namedtuple('Options', ' '.join(popts.iterkeys()))
popts = O(**popts)
report = []
if not tuple(filter(None, (getattr(popts, name) for name in ALL_OPTS))):
parser.print_help()
log.error(_('You must specify at least one action to perform'))
raise SystemExit(1)
polish({inbook:outbook}, popts, log, report.append)
log('')
log(REPORT)
for msg in report:
log(msg)
log('Output written to:', outbook)
示例4: Container
# 需要导入模块: from calibre.utils.logging import Log [as 别名]
# 或者: from calibre.utils.logging.Log import error [as 别名]
#.........这里部分代码省略.........
def get_html_names(self):
"""A generator function that yields only HTML file names from
the ePub.
"""
for node in self.opf.xpath('//opf:manifest/opf:item[@href and @media-type]', namespaces = self.namespaces):
if node.get("media-type") in HTML_MIMETYPES:
href = os.path.join(os.path.dirname(self.opf_name), node.get("href"))
href = os.path.normpath(href).replace(os.sep, '/')
yield href
@property
def is_drm_encumbered(self):
"""Determine if the ePub container is encumbered with Digital
Restrictions Management.
This method looks for the 'encryption.xml' file which denotes an
ePub encumbered by Digital Restrictions Management. DRM-encumbered
files cannot be edited.
"""
is_encumbered = False
if 'META-INF/encryption.xml' in self.name_map:
try:
xml = self.get('META-INF/encryption.xml')
if xml is None:
return True # If encryption.xml can't be parsed, assume its presence means an encumbered file
for elem in xml.xpath('./enc:EncryptedData/enc:EncryptionMethod[@Algorithm]', namespaces = self.namespaces):
alg = elem.get('Algorithm')
# Anything not in acceptable_encryption_algorithms is a sign of an
# encumbered file.
if alg not in self.acceptable_encryption_algorithms:
is_encumbered = True
except Exception as e:
self.log.error("Could not parse encryption.xml: " + e.message)
raise
return is_encumbered
def manifest_worthy_names(self):
for name in self.name_map:
if name.endswith('.opf'): continue
if name.startswith('META-INF') and os.path.basename(name) in self.META_INF:
continue
yield name
def delete_name(self, name):
self.mime_map.pop(name, None)
path = self.name_map[name]
os.remove(path)
self.name_map.pop(name)
def manifest_item_for_name(self, name):
href = self.name_to_href(name, os.path.dirname(self.opf_name))
q = prepare_string_for_xml(href, attribute = True)
existing = self.opf.xpath('//opf:manifest/opf:item[@href="{0}"]'.format(q), namespaces = self.namespaces)
if not existing:
return None
return existing[0]
def add_name_to_manifest(self, name, mt = None):
item = self.manifest_item_for_name(name)
if item is not None:
return
self.log("Adding '{0}' to the manifest".format(name))
manifest = self.opf.xpath('//opf:manifest', namespaces = self.namespaces)[0]
item = manifest.makeelement('{%s}item' % self.namespaces['opf'], href = self.name_to_href(name, os.path.dirname(self.opf_name)), id = self.generate_manifest_id())
示例5: Container
# 需要导入模块: from calibre.utils.logging import Log [as 别名]
# 或者: from calibre.utils.logging.Log import error [as 别名]
class Container(object):
META_INF = {
'container.xml' : True,
'manifest.xml' : False,
'encryption.xml' : False,
'metadata.xml' : False,
'signatures.xml' : False,
'rights.xml' : False,
}
OCF_NS = 'urn:oasis:names:tc:opendocument:xmlns:container'
OPF_NS = 'http://www.idpf.org/2007/opf'
NCX_NS = "http://www.daisy.org/z3986/2005/ncx/"
DC_NS = "http://purl.org/dc/elements/1.1/"
XHTML_NS = "http://www.w3.org/1999/xhtml"
OPF_MIMETYPE = 'application/oebps-package+xml'
NCX_MIMETYPE = "application/x-dtbncx+xml"
def __init__(self, path):
tmpdir = PersistentTemporaryDirectory("_kobo-driver-extended")
zf = zipfile.ZipFile(path)
zf.extractall(tmpdir)
self.root = os.path.abspath(tmpdir)
self.log = Log()
self.dirtied = set([])
self.cache = {}
self.mime_map = {}
print("Got container path {0}".format(self.root))
if os.path.exists(os.path.join(self.root, 'mimetype')):
os.remove(os.path.join(self.root, 'mimetype'))
container_path = os.path.join(self.root, 'META-INF', 'container.xml')
if not os.path.exists(container_path):
raise InvalidEpub('No META-INF/container.xml in epub')
self.container = etree.fromstring(open(container_path, 'rb').read())
opf_files = self.container.xpath((r'child::ocf:rootfiles/ocf:rootfile[@media-type="{0}" and @full-path]'.format(guess_type('a.opf')[0])), namespaces = {'ocf': self.OCF_NS})
if not opf_files:
raise InvalidEpub('META-INF/container.xml contains no link to OPF file')
opf_path = os.path.join(self.root, *opf_files[0].get('full-path').split('/'))
if not os.path.exists(opf_path):
raise InvalidEpub('OPF file does not exist at location pointed to by META-INF/container.xml')
# Map of relative paths with / separators to absolute
# paths on filesystem with os separators
self.name_map = {}
for dirpath, dirnames, filenames in os.walk(self.root):
for f in filenames:
path = os.path.join(dirpath, f)
name = os.path.relpath(path, self.root).replace(os.sep, '/')
self.name_map[name] = path
if path == opf_path:
self.opf_name = name
self.mime_map[name] = guess_type('a.opf')[0]
for item in self.opf.xpath('//opf:manifest/opf:item[@href and @media-type]', namespaces = {'opf': self.OPF_NS}):
href = item.get('href')
self.mime_map[self.href_to_name(href, posixpath.dirname(self.opf_name))] = item.get('media-type')
def get_html_names(self):
"""A generator function that yields only HTML file names from
the ePub.
"""
for name in self.name_map.keys():
ext = name[name.lower().rfind('.'):].lower()
if ext in HTML_EXTENSIONS:
yield name
def is_drm_encrypted(self):
"""Determine if the ePub container is encumbered with Digital
Restrictions Management.
This method looks for the 'encryption.xml' file which denotes an
ePub encumbered by Digital Restrictions Management. DRM-encumbered
files cannot be edited.
"""
if 'META-INF/encryption.xml' in self.name_map:
try:
xml = self.get('META-INF/encryption.xml')
if not xml:
return True # Even if encryption.xml can't be parsed, assume its presence means an encumbered file
for elem in xml.xpath('.//*[contains(name(), "EncryptionMethod")]'):
alg = elem.get('Algorithm')
return alg != 'http://ns.adobe.com/pdf/enc#RC'
except:
self.log.error("Could not parse encryption.xml")
return True # If encryption.xml is present, assume the file is encumbered
return False
def manifest_worthy_names(self):
for name in self.name_map:
if name.endswith('.opf'): continue
if name.startswith('META-INF') and posixpath.basename(name) in self.META_INF:
continue
yield name
def delete_name(self, name):
self.mime_map.pop(name, None)
#.........这里部分代码省略.........