def main(): global DUMP global WRITE_RAW_DATA global SPLIT_COMBO_MOBIS print "KindleUnpack v0.75" print " Based on initial mobipocket version Copyright © 2009 Charles M. Hannum <*****@*****.**>" print " Extensive Extensions and Improvements Copyright © 2009-2014 " print " by: P. Durrant, K. Hendricks, S. Siebert, fandrieu, DiapDealer, nickredding, tkeo." print " This program is free software: you can redistribute it and/or modify" print " it under the terms of the GNU General Public License as published by" print " the Free Software Foundation, version 3." argv=utf8_argv() progname = os.path.basename(argv[0]) try: opts, args = getopt.getopt(argv[1:], "dhirsp:", ['epub_version=']) except getopt.GetoptError, err: print str(err) usage(progname) sys.exit(2)
def main(): global DUMP global WRITE_RAW_DATA global SPLIT_COMBO_MOBIS print "KindleUnpack v0.77" print " Based on initial mobipocket version Copyright © 2009 Charles M. Hannum <*****@*****.**>" print " Extensive Extensions and Improvements Copyright © 2009-2014 " print " by: P. Durrant, K. Hendricks, S. Siebert, fandrieu, DiapDealer, nickredding, tkeo." print " This program is free software: you can redistribute it and/or modify" print " it under the terms of the GNU General Public License as published by" print " the Free Software Foundation, version 3." argv = utf8_argv() progname = os.path.basename(argv[0]) try: opts, args = getopt.getopt(argv[1:], "dhirsp:", ['epub_version=']) except getopt.GetoptError, err: print str(err) usage(progname) sys.exit(2)
def main(argv=utf8_argv()): if len(argv) != 5: failed( None, msg="Launcher: improper number of arguments passed to launcher.py") return -1 ebook_root = argv[1] outdir = argv[2] script_type = argv[3] target_file = argv[4] script_home = os.path.dirname(target_file) script_module = os.path.splitext(os.path.basename(target_file))[0] # do basic sanity checking anyway if script_type not in SUPPORTED_SCRIPT_TYPES: failed(None, msg="Launcher: script type %s is not supported" % script_type) return -1 ok = path.exists(ebook_root) and path.isdir(ebook_root) ok = ok and path.exists(outdir) and path.isdir(outdir) ok = ok and path.exists(script_home) and path.isdir(script_home) ok = ok and path.exists(target_file) and path.isfile(target_file) if not ok: failed(None, msg="Launcher: missing or incorrect paths passed in") return -1 # update sys with path to target module home directory if pathof(script_home) not in sys.path: sys.path.append(pathof(script_home)) # load and parse opf if present op = None opf_path = os.path.join(ebook_root, 'OEBPS', 'content.opf') if path.exists(opf_path) and path.isfile(opf_path): op = Opf_Parser(opf_path) # create a wrapper for record keeping and safety rk = Wrapper(ebook_root, outdir, op) # get the correct container if script_type == 'edit': bc = BookContainer(rk) elif script_type == "input": bc = InputContainer(rk) else: bc = OutputContainer(rk) # start the target script ps = ProcessScript(script_type, script_module, bc) ps.launch() # get standard error and standard out from the target script successmsg = escapeit("".join(ps.stdouttext)) errorlog = escapeit("".join(ps.stderrtext)) # get the target's script wrapper xml resultxml = "".join(ps.wrapout) resultxml += "<msg>\n" if ps.exitcode == 0: resultxml += successmsg if _DEBUG: resultxml += errorlog else: if _DEBUG: resultxml += successmsg resultxml += errorlog resultxml += '</msg>\n</wrapper>\n' # write it to stdout and exit sys.stdout.write(resultxml) return 0
def main(argv=utf8_argv()): if len(argv) != 5: failed(None, msg="Launcher: improper number of arguments passed to launcher.py") return -1 ebook_root = argv[1] outdir = argv[2] script_type = argv[3] target_file = argv[4] script_home = os.path.dirname(target_file) script_module = os.path.splitext(os.path.basename(target_file))[0] # do basic sanity checking anyway if script_type not in SUPPORTED_SCRIPT_TYPES: failed(None, msg="Launcher: script type %s is not supported" % script_type) return -1 ok = path.exists(ebook_root) and path.isdir(ebook_root) ok = ok and path.exists(outdir) and path.isdir(outdir) ok = ok and path.exists(script_home) and path.isdir(script_home) ok = ok and path.exists(target_file) and path.isfile(target_file) if not ok: failed(None, msg="Launcher: missing or incorrect paths passed in") return -1 # update sys with path to target module home directory if pathof(script_home) not in sys.path: sys.path.append(pathof(script_home)) # load and parse opf if present op = None opf_path = os.path.join(ebook_root,'OEBPS','content.opf') if path.exists(opf_path) and path.isfile(opf_path): op = Opf_Parser(opf_path) # create a wrapper for record keeping and safety rk = Wrapper(ebook_root, outdir, op) # get the correct container if script_type == 'edit': bc = BookContainer(rk) elif script_type == "input": bc = InputContainer(rk) else: bc = OutputContainer(rk) # start the target script ps = ProcessScript(script_type, script_module, bc) ps.launch() # get standard error and standard out from the target script successmsg = escapeit("".join(ps.stdouttext)) errorlog = escapeit("".join(ps.stderrtext)) # get the target's script wrapper xml resultxml = "".join(ps.wrapout) resultxml += "<msg>\n" if ps.exitcode == 0: resultxml += successmsg if _DEBUG: resultxml += errorlog else: if _DEBUG: resultxml += successmsg resultxml += errorlog resultxml +='</msg>\n</wrapper>\n' # write it to stdout and exit sys.stdout.write(resultxml) return 0