def setUp(self): config() Logger.set_log_level(options.verbose) options.types = options.types or ['all'] options.types = CommonCode.add_dependencies(options.types, DEPENDENCIES, BUILD_ORDER) debug("Building types: %s" % ' '.join(options.types))
def main(): """ Main program. """ try: config() except configparser.Error as what: error("Error in configuration file: %s", str(what)) return 1 Logger.set_log_level(options.verbose) options.types = options.types or ['all'] options.types = CommonCode.add_dependencies(options.types, DEPENDENCIES, BUILD_ORDER) debug("Building types: %s" % ' '.join(options.types)) ParserFactory.load_parsers() WriterFactory.load_writers() PackagerFactory.load_packagers() if options.is_job_queue: job_queue = cPickle.load(sys.stdin.buffer) # read bytes else: options.dc = get_dc(options.url) job_queue = [] output_files = dict() for type_ in options.types: job = CommonCode.Job(type_) job.url = options.url job.ebook = options.ebook job.dc = options.dc job.outputdir = options.outputdir job.outputfile = options.outputfile or make_output_filename( type_, options.dc) output_files[type_] = job.outputfile if job.type == 'kindle.images': job.url = os.path.join(job.outputdir, output_files['epub.images']) elif job.type == 'kindle.noimages': job.url = os.path.join(job.outputdir, output_files['epub.noimages']) job_queue.append(job) for j in job_queue: do_job(j) packager = PackagerFactory.create(options.packager, 'push') if packager: # HACK: the WWers ever only convert one ebook at a time job = job_queue[0] job.outputfile = '%d-final.zip' % (options.dc.project_gutenberg_id) packager.package(job) return 0
def open_log(path): """ Open a logfile in the output directory. """ handler = logging.FileHandler(path, "a") handler.setFormatter(Logger.CustomFormatter(Logger.LOGFORMAT)) handler.setLevel(logging.DEBUG) logging.getLogger().addHandler(handler) return handler