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 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 config(): """ Process config files and commandline params. """ ap = argparse.ArgumentParser(prog='EbookMaker') CommonCode.add_common_options(ap, CONFIG_FILES[1]) add_local_options(ap) options = CommonCode.parse_config_and_args( ap, CONFIG_FILES[0], { 'proxies': None, 'xelatex': 'xelatex', 'mobigen': 'kindlegen', 'groff': 'groff', 'rhyming_dict': None, 'timestamp': datetime.datetime.today().isoformat()[:19], }) builtins.options = options builtins._ = CommonCode.null_translation if '://' not in options.url: options.url = os.path.abspath(options.url)
def config(): """ Process config files and commandline params. """ ap = argparse.ArgumentParser(prog='EbookMaker') CommonCode.add_common_options(ap, CONFIG_FILES[1]) add_local_options(ap) CommonCode.set_arg_defaults(ap, CONFIG_FILES[1]) global options options.update( vars( CommonCode.parse_config_and_args( ap, CONFIG_FILES[0], { 'proxies': None, 'xelatex': 'xelatex', 'mobigen': 'kindlegen', 'mobilang': '', 'groff': 'groff', 'rhyming_dict': None, 'timestamp': datetime.datetime.today().isoformat()[:19], }))) if not re.search(r'^(https?|file):', options.url): options.url = os.path.abspath(options.url)
def add_local_options(ap): """ Add local options to commandline. """ ap.add_argument('--version', action='version', version="%%(prog)s %s" % VERSION) ap.add_argument("--make", dest="types", choices=CommonCode.add_dependencies(['all', 'test'], DEPENDENCIES), default=[], action='append', help="output type (default: all)") ap.add_argument( "--max-depth", metavar="LEVELS", dest="max_depth", type=int, default=1, help="go how many levels deep while recursively retrieving pages. " "(0 == infinite) (default: %(default)s)") ap.add_argument("--strip_links", dest="strip_links", action="store_true", help="strip <a href='external address' /> links") ap.add_argument( "--include", metavar="GLOB", dest="include_urls", default=[], action="append", help= "include urls (repeat for more) (default: urls under the same directory)" ) ap.add_argument( "--exclude", metavar="GLOB", dest="exclude_urls", default=[], action="append", help="exclude urls from included urls (repeat for more) (default: none)" ) ap.add_argument( "--include-mediatype", metavar="GLOB/GLOB", dest="include_mediatypes", default=mt.TEXT_MEDIATYPES | mt.AUX_MEDIATYPES, action="append", help="include mediatypes (repeat for more) (eg. 'image/*') " "(default: most common text mediatypes)") ap.add_argument("--exclude-mediatype", metavar="GLOB/GLOB", dest="exclude_mediatypes", default=[], action="append", help="exclude this mediatype from included mediatypes " "(repeat for more)") ap.add_argument( "--input-mediatype", metavar="MEDIATYPE", dest="input_mediatype", default=None, help= "mediatype of input url (default: http response else file extension)") ap.add_argument( "--mediatype-from-extension", dest="mediatype_from_extension", action="store_true", default=False, help="guess all mediatypes from file extension, overrides http response" ) ap.add_argument( "--rewrite", metavar="from>to", dest="rewrite", default=[], action="append", help= "rewrite url eg. 'http://www.example.org/>http://www.example.org/index.html'" ) ap.add_argument("--title", dest="title", default=None, help="ebook title (default: from meta)") ap.add_argument("--author", dest="author", default=None, help="author (default: from meta)") ap.add_argument("--ebook", dest="ebook", type=int, default=0, help="ebook no. (default: from meta)") ap.add_argument("--output-dir", metavar="OUTPUT_DIR", dest="outputdir", default="./", help="output directory (default: ./)") ap.add_argument("--output-file", metavar="OUTPUT_FILE", dest="outputfile", default=None, help="output file (default: <title>.epub)") ap.add_argument("--validate", dest="validate", action="count", help="validate epub through epubcheck") ap.add_argument("--section", metavar="TAG.CLASS", dest="section_tags", default=[], action="append", help="split epub on TAG.CLASS") ap.add_argument( "--packager", dest="packager", choices=['ww', 'gzip'], default=None, help="PG internal use only: which packager to use (default: none)") ap.add_argument("--cover", dest="coverpage_url", default=None, help="use the cover specified by an absolute url") ap.add_argument( "--generate_cover", dest="generate_cover", action="store_true", help= "if no cover is specified by the source, or as an argument, generate a cover" ) ap.add_argument( "--jobs", dest="is_job_queue", action="store_true", help="PG internal use only: read pickled job queue from stdin") ap.add_argument("--extension-package", metavar="PYTHON_PACKAGE", dest="extension_packages", default=[], action="append", help="PG internal use only: load extensions from package") ap.add_argument("url", help="url of file to convert")