def collection2pdf(collection_dir, print_style, output_pdf, pdfgen, temp_dir, verbose=False,reduce_quality=False): p = util.Progress() collxml = etree.parse(os.path.join(collection_dir, 'collection.xml')) moduleIds = MODULES_XPATH(collxml) modules = {} # {'m1000': (etree.Element, {'file.jpg':'23947239874'})} allFiles = {} for moduleId in moduleIds: moduleDir = os.path.join(collection_dir, moduleId) if os.path.isdir(moduleDir): cnxml, files = loadModule(moduleDir) for f in files: allFiles[os.path.join(moduleId, f)] = files[f] modules[moduleId] = (cnxml, files) p.start(1, 'Converting collection to Docbook') dbk, newFiles = collection2dbk.convert(p, collxml, modules, temp_dir, svg2png=False, math2svg=True, reduce_quality=reduce_quality) allFiles.update(newFiles) p.tick('Converting Docbook to PDF') stdErr = convert(p, dbk, allFiles, print_style, temp_dir, output_pdf, pdfgen, verbose) p.finish() return stdErr
def main(): try: import argparse except ImportError: print "argparse is needed for commandline" return 1 parser = argparse.ArgumentParser( description="Converts a a collection directory to an xhtml file and additional images" ) parser.add_argument("directory") parser.add_argument("-r", dest="reduce_quality", help="Reduce image quality", action="store_true") # parser.add_argument('-t', dest='temp_dir', help='Path to store temporary files to (default is a temp dir that will be removed)', nargs='?') parser.add_argument("-o", dest="output", nargs="?", type=argparse.FileType("w"), default=sys.stdout) args = parser.parse_args() temp_dir = args.directory p = util.Progress() collxml, modules, allFiles = util.loadCollection(args.directory) dbk, newFiles = collection2dbk.convert( p, collxml, modules, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality ) allFiles.update(newFiles) dbk, files = convert(dbk, allFiles) args.output.write(etree.tostring(dbk)) # Write out all the added files for name in newFiles: f = open(os.path.join(args.directory, name), "w") f.write(newFiles[name]) f.close()
def collection2xhtml(collection_dir, output_xhtml, reduce_quality=False): p = util.Progress() collxml = etree.parse(os.path.join(collection_dir, "collection.xml")) moduleIds = MODULES_XPATH(collxml) modules = {} # {'m1000': (etree.Element, {'file.jpg':'23947239874'})} allFiles = {} for moduleId in moduleIds: moduleDir = os.path.join(collection_dir, moduleId) if os.path.isdir(moduleDir): cnxml, files = loadModule(moduleDir) for f in files: allFiles[os.path.join(moduleId, f)] = files[f] modules[moduleId] = (cnxml, files) p.start(1, "Converting collection to Docbook") dbk, newFiles = collection2dbk.convert( p, collxml, modules, collection_dir, svg2png=True, math2svg=True, reduce_quality=reduce_quality ) # replace temp_dir with collection_dir allFiles.update(newFiles) p.tick("Converting Docbook to MOBI") stdErr = convert(p, dbk, allFiles, collection_dir, output_xhtml) p.finish() return stdErr
def main(): try: import argparse except ImportError: print "argparse is needed for commandline" return 1 parser = argparse.ArgumentParser(description='Converts a a collection directory to an xhtml file and additional images') parser.add_argument('directory') parser.add_argument('-r', dest='reduce_quality', help='Reduce image quality', action='store_true') # parser.add_argument('-t', dest='temp_dir', help='Path to store temporary files to (default is a temp dir that will be removed)', nargs='?') parser.add_argument('-o', dest='output', nargs='?', type=argparse.FileType('w'), default=sys.stdout) args = parser.parse_args() temp_dir = args.directory p = util.Progress() collxml, modules, allFiles = util.loadCollection(args.directory) dbk, newFiles = collection2dbk.convert(p, collxml, modules, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality) allFiles.update(newFiles) dbk, files = convert(dbk, allFiles) args.output.write(etree.tostring(dbk)) # Write out all the added files for name in newFiles: f = open(os.path.join(args.directory, name), 'w') f.write(newFiles[name]) f.close()
def main(): try: import argparse except ImportError: print "argparse is needed for commandline" return 1 parser = argparse.ArgumentParser(description='Converts a module directory to an xhtml file and additional images') parser.add_argument('directory') parser.add_argument('-i', dest='module_id', help='Published Module id') parser.add_argument('-c', dest='css_file', help='CSS File to include')# , type=argparse.FileType('r')) parser.add_argument('-e', dest='epub_script', help='Name of XSL file that generates an epub from a dbk file (should look like "./xsl/dbk2___.xsl")') parser.add_argument('-r', dest='reduce_quality', help='Reduce image quality', action='store_true') parser.add_argument('-t', dest='content_type', help='The type of content being converted. One of ["module", "collection"]') # parser.add_argument('-t', dest='temp_dir', help='Path to store temporary files to (default is a temp dir that will be removed)', nargs='?') parser.add_argument('-o', dest='output', nargs='?') # , type=argparse.FileType('w'), default=sys.stdout) args = parser.parse_args() epubXsl = args.epub_script if not epubXsl: epubXsl = DEFAULT_DOCBOOK2XHTML_XSL temp_dir = args.directory p = util.Progress() if args.content_type == 'module': cnxml, allFiles = util.loadModule(args.directory) dbk, newFiles = module2dbk.convert(args.module_id, cnxml, allFiles, {}, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality) dbk = newFiles['index.standalone.dbk'] allFiles.update(newFiles) cover, newFiles = util.dbk2cover(etree.parse(StringIO(dbk)), allFiles, svg2pngFlag=True) newFiles['cover.png'] = cover elif args.content_type == 'collection': p = util.Progress() collxml, modulesDict, allFiles = util.loadCollection(args.directory) dbk, newFiles = collection2dbk.convert(p, collxml, modulesDict, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality) allFiles.update(newFiles) else: print "Invalid content type. Must be one of ['module', 'collection']" return 1 # Write out all the added files for name in newFiles: f = open(os.path.join(temp_dir, name), 'w') f.write(newFiles[name]) f.close() # Now, run the epub script nothing = convert(etree.parse(StringIO(dbk)), temp_dir, args.css_file, epubXsl, args.output)
def main(): try: import argparse except ImportError: print "argparse is needed for commandline" return 1 parser = argparse.ArgumentParser(description='Converts a module directory to an xhtml file and additional images') parser.add_argument('directory') parser.add_argument('-i', dest='module_id', help='Published Module id') parser.add_argument('-c', dest='css_file', help='CSS File to include')# , type=argparse.FileType('r')) parser.add_argument('-e', dest='epub_script', help='Path to XSL file that generates an epub from a dbk file') parser.add_argument('-r', dest='reduce_quality', help='Reduce image quality', action='store_true') parser.add_argument('-t', dest='content_type', help='The type of content being converted. One of ["module", "collection"]') # parser.add_argument('-t', dest='temp_dir', help='Path to store temporary files to (default is a temp dir that will be removed)', nargs='?') parser.add_argument('-o', dest='output', nargs='?') # , type=argparse.FileType('w'), default=sys.stdout) args = parser.parse_args() temp_dir = args.directory p = util.Progress() if args.content_type == 'module': cnxml, allFiles = util.loadModule(args.directory) dbk, newFiles = module2dbk.convert(args.module_id, cnxml, allFiles, {}, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality) allFiles.update(newFiles) elif args.content_type == 'collection': p = util.Progress() collxml, modulesDict, allFiles = util.loadCollection(args.directory) dbk, newFiles = collection2dbk.convert(p, collxml, modulesDict, temp_dir, svg2png=True, math2svg=True, reduce_quality=args.reduce_quality) allFiles.update(newFiles) else: print "Invalid content type. Must be one of ['module', 'collection']" return 1 nothing = convert(etree.parse(StringIO(dbk)), temp_dir, args.css_file, args.output) # Write out all the added files for name in newFiles: f = open(os.path.join(temp_dir, name), 'w') f.write(newFiles[name]) f.close()
def __doStuff(dir): collxml = etree.parse(os.path.join(dir, 'collection.xml')) moduleIds = MODULES_XPATH(collxml) modules = {} # {'m1000': (etree.Element, {'file.jpg':'23947239874'})} allFiles = {} for moduleId in moduleIds: print >> sys.stderr, "LOG: Starting on %s" % (moduleId) moduleDir = os.path.join(dir, moduleId) if os.path.isdir(moduleDir): cnxml, files = loadModule(moduleDir) for f in files: allFiles[os.path.join(moduleId, f)] = files[f] modules[moduleId] = (cnxml, files) dbk, newFiles = collection2dbk.convert(collxml, modules, svg2png=False, math2svg=True) allFiles.update(newFiles) return convert(dbk, allFiles)