def main(args=sys.argv, logger=None): parser = option_parser() opts, args = parser.parse_args(args) if logger is None: level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrs2lrf') setup_cli_handlers(logger, level) if len(args) != 2: parser.print_help() return 1 if not opts.output: ext = '.lrs' if opts.lrs else '.lrf' opts.output = os.path.splitext(os.path.basename(args[1]))[0]+ext opts.output = os.path.abspath(opts.output) if opts.verbose: import warnings warnings.defaultaction = 'error' logger.info('Parsing LRS file...') converter = LrsParser(open(args[1], 'rb'), logger) logger.info('Writing to output file...') converter.render(opts.output, to_lrs=opts.lrs) logger.info('Output written to '+opts.output) return 0
def main(args=sys.argv, logger=None): parser = option_parser() opts, args = parser.parse_args(args) if logger is None: level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrs2lrf') setup_cli_handlers(logger, level) if len(args) != 2: parser.print_help() return 1 if not opts.output: ext = '.lrs' if opts.lrs else '.lrf' opts.output = os.path.splitext(os.path.basename(args[1]))[0] + ext opts.output = os.path.abspath(opts.output) if opts.verbose: import warnings warnings.defaultaction = 'error' logger.info('Parsing LRS file...') converter = LrsParser(open(args[1], 'rb'), logger) logger.info('Writing to output file...') converter.render(opts.output, to_lrs=opts.lrs) logger.info('Output written to ' + opts.output) return 0
def init_cli_logging(is_verbose=True): if is_verbose: calibre_logging.default_log = \ calibre_logging.Log(level=calibre_logging.DEBUG) level = 'DEBUG' if is_verbose else 'INFO' setup_cli_handlers(logging.getLogger('comicvine'), getattr(logging, level)) return calibre_logging.ThreadSafeLog(level=getattr(calibre_logging, level))
def file_renderer(stream, opts, parent=None, logger=None): if logger is None: level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrfviewer') setup_cli_handlers(logger, level) if islinux or isbsd: try: # Set lrfviewer as the default for LRF files for this user from subprocess import call call('xdg-mime default calibre-lrfviewer.desktop application/lrf', shell=True) except: pass m = Main(logger, opts, parent=parent) m.set_ebook(stream) return m
def process_file(lrfpath, opts, logger=None): if logger is None: level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrf2html') setup_cli_handlers(logger, level) if opts.out is None: opts.out = os.getcwdu() else: opts.out = os.path.abspath(opts.out) if not os.path.isdir(opts.out): raise ConversionError(opts.out + ' is not a directory') if not os.path.exists(opts.out): os.makedirs(opts.out) document = LRFDocument(open(lrfpath, 'rb')) LRFConverter(document, opts, logger)
def cli_main(self, args): 'Perform comicvine lookups from the calibre-debug cli' def option_parser(): 'Parse command line options' parser = OptionParser( usage='Comicvine [t:title] [a:authors] [i:id]') parser.add_option('--verbose', '-v', default=False, action='store_true', dest='verbose') parser.add_option('--debug_api', default=False, action='store_true', dest='debug_api') return parser opts, args = option_parser().parse_args(args) if opts.debug_api: calibre_logging.default_log = calibre_logging.Log( level=calibre_logging.DEBUG) if opts.verbose: level = 'DEBUG' else: level = 'INFO' setup_cli_handlers(logging.getLogger('comicvine'), getattr(logging, level)) log = calibre_logging.ThreadSafeLog(level=getattr(calibre_logging, level)) (title, authors, ids) = (None, [], {}) for arg in args: if arg.startswith('t:'): title = arg.split(':', 1)[1] if arg.startswith('a:'): authors.append(arg.split(':', 1)[1]) if arg.startswith('i:'): (idtype, identifier) = arg.split(':', 2)[1:] ids[idtype] = int(identifier) result_queue = Queue() self.identify( log, result_queue, False, title=title, authors=authors, identifiers=ids) ranking = self.identify_results_keygen(title, authors, ids) for result in sorted(result_queue.queue, key=ranking): if result.pubdate: pubdate = str(result.pubdate.date()) else: pubdate = 'Unknown' log.info('(%04d) - %s: %s [%s]' % ( ranking(result), result.identifiers['comicvine'], result.title, pubdate))
def cli_main(self, args): 'Perform comicvine lookups from the calibre-debug cli' def option_parser(): 'Parse command line options' parser = OptionParser( usage='Comicvine [t:title] [a:authors] [i:id]') parser.add_option('--opf', '-o', action='store_true', dest='opf') parser.add_option('--verbose', '-v', default=False, action='store_true', dest='verbose') parser.add_option('--debug_api', default=False, action='store_true', dest='debug_api') return parser opts, args = option_parser().parse_args(args) if opts.debug_api: calibre_logging.default_log = calibre_logging.Log( level=calibre_logging.DEBUG) if opts.verbose: level = 'DEBUG' else: level = 'INFO' setup_cli_handlers(logging.getLogger('comicvine'), getattr(logging, level)) log = calibre_logging.ThreadSafeLog(level=getattr(calibre_logging, level)) (title, authors, ids) = (None, [], {}) for arg in args: if arg.startswith('t:'): title = arg.split(':', 1)[1] if arg.startswith('a:'): authors.append(arg.split(':', 1)[1]) if arg.startswith('i:'): (idtype, identifier) = arg.split(':', 2)[1:] ids[idtype] = int(identifier) result_queue = Queue() self.identify( log, result_queue, False, title=title, authors=authors, identifiers=ids) ranking = self.identify_results_keygen(title, authors, ids) for result in sorted(result_queue.queue, key=ranking): self._print_result(result, ranking, opf=opts.opf) if opts.opf: break
def main(args=sys.argv, logger=None): parser = option_parser() opts, args = parser.parse_args(args) if logger is None: level = logging.DEBUG if opts.verbose else logging.INFO logger = logging.getLogger('lrf2lrs') setup_cli_handlers(logger, level) if len(args) != 2: parser.print_help() return 1 if opts.out is None: opts.out = os.path.join(os.path.dirname(args[1]), os.path.splitext(os.path.basename(args[1]))[0]+".lrs") o = codecs.open(os.path.abspath(os.path.expanduser(opts.out)), 'wb', 'utf-8') o.write(u'<?xml version="1.0" encoding="UTF-8"?>\n') logger.info(_('Parsing LRF...')) d = LRFDocument(open(args[1], 'rb')) d.parse() logger.info(_('Creating XML...')) o.write(d.to_xml(write_files=opts.output_resources)) logger.info(_('LRS written to ')+opts.out) return 0