def post(): parser = optparse.OptionParser(usage="%prog OPTIONS") parser.add_option("-i", "--input", help="ZIP file to POST") parser.add_option('-l', '--logfile', help='log output to LOGFILE', ) parser.add_option("-p", "--posturl", help="HTTP POST ZIP file to POSTURL") parser.add_option("-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true', ) parser.add_option("-d", "--daemonize", action="store_true", help='become a daemon process as soon as possible') parser.add_option('--pid-file', help='write PID of daemonized process to this file', ) options, args = parser.parse_args() use_help = 'Use --help for usage information.' if not options.input: parser.error('Specify --input.\n' + use_help) if (options.posturl and options.getposturl)\ or (not options.posturl and not options.getposturl): parser.error('Specify either --posturl or --getposturl.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl('http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) from mwlib import utils from mwlib.status import Status if options.logfile: utils.start_logging(options.logfile) if options.daemonize: utils.daemonize() if options.pid_file: open(options.pid_file, 'wb').write('%d\n' % os.getpid()) status = Status(podclient=podclient) try: try: status(status='uploading', progress=0) podclient.post_zipfile(options.input) status(status='finished', progress=100) except Exception, e: status(status='error') raise finally: if options.pid_file: utils.safe_unlink(options.pid_file)
def uploadfile(ipath, posturl, fh=None): if fh is None: fh = open(ipath, "rb") podclient = PODClient(posturl) status = Status(podclient=podclient) try: status(status='uploading', progress=0) podclient.streaming_post_zipfile(ipath, fh) status(status='finished', progress=100) except Exception, err: status(status='error') raise err
def post(): parser = optparse.OptionParser(usage="%prog OPTIONS") parser.add_option("-i", "--input", help="ZIP file to POST") parser.add_option('-l', '--logfile', help='log output to LOGFILE') parser.add_option("-p", "--posturl", help="HTTP POST ZIP file to POSTURL") parser.add_option( "-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true') options, args = parser.parse_args() use_help = 'Use --help for usage information.' if not options.input: parser.error('Specify --input.\n' + use_help) if (options.posturl and options.getposturl)\ or (not options.posturl and not options.getposturl): parser.error('Specify either --posturl or --getposturl.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl( 'http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) from mwlib import utils from mwlib.status import Status if options.logfile: utils.start_logging(options.logfile) status = Status(podclient=podclient) try: status(status='uploading', progress=0) podclient.post_zipfile(options.input) status(status='finished', progress=100) except Exception as e: status(status='error') raise
def post(): parser = optparse.OptionParser(usage="%prog OPTIONS") parser.add_option("-i", "--input", help="ZIP file to POST") parser.add_option('-l', '--logfile', help='log output to LOGFILE') parser.add_option("-p", "--posturl", help="HTTP POST ZIP file to POSTURL") parser.add_option("-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true') options, args = parser.parse_args() use_help = 'Use --help for usage information.' if not options.input: parser.error('Specify --input.\n' + use_help) if (options.posturl and options.getposturl)\ or (not options.posturl and not options.getposturl): parser.error('Specify either --posturl or --getposturl.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl('http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) from mwlib import utils from mwlib.status import Status if options.logfile: utils.start_logging(options.logfile) status = Status(podclient=podclient) try: status(status='uploading', progress=0) podclient.post_zipfile(options.input) status(status='finished', progress=100) except Exception as e: status(status='error') raise
def report_mwzip_status(posturl, jobid, host, port): podclient = PODClient(posturl) status = Status(podclient=podclient) from mwlib.async import rpcclient sp = rpcclient.serverproxy(host, port) last = {} while 1: res = sp.qinfo(jobid=jobid) or {} done = res.get("done", False) if done: break info = res.get("info", {}) if info!=last: status(status=info.get("status", "fetching"), progress=info.get("progress", 0.0)) last = info else: gevent.sleep(0.5)
def report_upload_status(posturl, fh): podclient = PODClient(posturl) fh.seek(0, 2) size = fh.tell() fh.seek(0, 0) status = Status(podclient=podclient) numdots = 0 last = None while 1: cur = fh.tell() if cur != last: if cur==size: break numdots = (numdots + 1) % 10 status("uploading"+"."*numdots, progress=100.0*cur/size) last = cur else: gevent.sleep(0.1)
done = res.get("done", False) if done: break info = res.get("info", {}) if info!=last: status(status=info.get("status", "fetching"), progress=info.get("progress", 0.0)) last = info else: gevent.sleep(0.5) def report_exception(posturl, (tp, err, tb)): print "reporting error to", posturl, repr(str(err)[:50]) podclient = PODClient(posturl) podclient.post_status(error=str(err)) mailfrom = "%s@%s" % (getpass.getuser(), socket.gethostname()) def report_exception_mail(subject, exc_info): mailto = os.environ.get("MAILTO") if not mailto: print "MAILTO not set. not sending email." return print "sending mail to", mailto f=StringIO.StringIO() traceback.print_exception(*exc_info, file=f)
def main(): from gevent import monkey monkey.patch_all(thread=False) from mwlib.options import OptionParser from mwlib import conf parser = OptionParser() parser.add_option("-o", "--output", help="write output to OUTPUT") parser.add_option("-p", "--posturl", help="http post to POSTURL (directly)") parser.add_option( "-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='count', ) parser.add_option( '--keep-tmpfiles', action='store_true', default=False, help="don't remove temporary files like images", ) parser.add_option("-s", "--status-file", help='write status/progress info to this file') options, args = parser.parse_args() conf.readrc() use_help = 'Use --help for usage information.' if parser.metabook is None and options.collectionpage is None: parser.error( 'Neither --metabook nor, --collectionpage or arguments specified.\n' + use_help) if options.posturl and options.getposturl: parser.error('Specify either --posturl or --getposturl.\n' + use_help) if not options.posturl and not options.getposturl and not options.output: parser.error( 'Neither --output, nor --posturl or --getposturl specified.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: if options.getposturl > 1: serviceurl = 'http://test.pediapress.com/api/collections/' else: serviceurl = 'http://pediapress.com/api/collections/' import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl(serviceurl) pid = os.fork() if not pid: try: webbrowser.open(podclient.redirecturl) finally: os._exit(0) import time time.sleep(1) try: os.kill(pid, 9) except: pass else: podclient = None from mwlib import utils, wiki filename = None status = None try: env = parser.makewiki() assert env.metabook, "no metabook" from mwlib.status import Status status = Status(options.status_file, podclient=podclient, progress_range=(1, 90)) status(progress=0) output = options.output make_zip(output, options, env.metabook, podclient=podclient, status=status) except Exception, e: if status: status(status='error') raise
def buildzip(): from mwlib.options import OptionParser parser = OptionParser() parser.add_option("-o", "--output", help="write output to OUTPUT") parser.add_option("-p", "--posturl", help="http post to POSTURL (directly)") parser.add_option("-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true', ) options, args = parser.parse_args() use_help = 'Use --help for usage information.' if parser.metabook is None and options.collectionpage is None: parser.error('Neither --metabook nor, --collectionpage or arguments specified.\n' + use_help) if options.posturl and options.getposturl: parser.error('Specify either --posturl or --getposturl.\n' + use_help) if not options.posturl and not options.getposturl and not options.output: parser.error('Neither --output, nor --posturl or --getposturl specified.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl('http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) else: podclient = None from mwlib import utils if options.daemonize: utils.daemonize() if options.pid_file: open(options.pid_file, 'wb').write('%d\n' % os.getpid()) filename = None status = None try: try: env = parser.makewiki() from mwlib.status import Status from mwlib import zipcreator status = Status(podclient=podclient, progress_range=(1, 90)) status(progress=0) filename = zipcreator.make_zip_file(options.output, env, status=status, num_threads=options.num_threads, imagesize=options.imagesize, ) status = Status(podclient=podclient, progress_range=(91, 100)) if podclient: status(status='uploading', progress=0) podclient.post_zipfile(filename) status(status='finished', progress=100) except Exception, e: if status: status(status='error') raise finally: if options.output is None and filename is not None: print 'removing %r' % filename utils.safe_unlink(filename) if options.pid_file: utils.safe_unlink(options.pid_file)
def buildzip(): from mwlib.options import OptionParser parser = OptionParser() parser.add_option("-o", "--output", help="write output to OUTPUT") parser.add_option("-p", "--posturl", help="http post to POSTURL (directly)") parser.add_option( "-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true', ) options, args = parser.parse_args() use_help = 'Use --help for usage information.' if parser.metabook is None and options.collectionpage is None: parser.error( 'Neither --metabook nor, --collectionpage or arguments specified.\n' + use_help) if options.posturl and options.getposturl: parser.error('Specify either --posturl or --getposturl.\n' + use_help) if not options.posturl and not options.getposturl and not options.output: parser.error( 'Neither --output, nor --posturl or --getposturl specified.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl( 'http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) else: podclient = None from mwlib import utils if options.daemonize: utils.daemonize() if options.pid_file: open(options.pid_file, 'wb').write('%d\n' % os.getpid()) filename = None status = None try: try: env = parser.makewiki() from mwlib.status import Status from mwlib import zipcreator status = Status(podclient=podclient, progress_range=(1, 90)) status(status='parsing', progress=0) filename = zipcreator.make_zip_file( options.output, env, status=status, num_threads=options.num_threads, imagesize=options.imagesize, ) status = Status(podclient=podclient, progress_range=(91, 100)) if podclient: status(status='uploading', progress=0) podclient.post_zipfile(filename) status(status='finished', progress=100) except Exception, e: if status: status(status='error') raise finally: if options.output is None and filename is not None: print 'removing %r' % filename utils.safe_unlink(filename) if options.pid_file: utils.safe_unlink(options.pid_file)
def post(): parser = optparse.OptionParser(usage="%prog OPTIONS") parser.add_option("-i", "--input", help="ZIP file to POST") parser.add_option( '-l', '--logfile', help='log output to LOGFILE', ) parser.add_option("-p", "--posturl", help="HTTP POST ZIP file to POSTURL") parser.add_option( "-g", "--getposturl", help='get POST URL from PediaPress.com, open upload page in webbrowser', action='store_true', ) parser.add_option("-d", "--daemonize", action="store_true", help='become a daemon process as soon as possible') parser.add_option( '--pid-file', help='write PID of daemonized process to this file', ) options, args = parser.parse_args() use_help = 'Use --help for usage information.' if not options.input: parser.error('Specify --input.\n' + use_help) if (options.posturl and options.getposturl)\ or (not options.posturl and not options.getposturl): parser.error('Specify either --posturl or --getposturl.\n' + use_help) if options.posturl: from mwlib.podclient import PODClient podclient = PODClient(options.posturl) elif options.getposturl: import webbrowser from mwlib.podclient import podclient_from_serviceurl podclient = podclient_from_serviceurl( 'http://pediapress.com/api/collections/') webbrowser.open(podclient.redirecturl) from mwlib import utils from mwlib.status import Status if options.logfile: utils.start_logging(options.logfile) if options.daemonize: utils.daemonize() if options.pid_file: open(options.pid_file, 'wb').write('%d\n' % os.getpid()) status = Status(podclient=podclient) try: try: status(status='uploading', progress=0) podclient.post_zipfile(options.input) status(status='finished', progress=100) except Exception, e: status(status='error') raise finally: if options.pid_file: utils.safe_unlink(options.pid_file)