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)
Esempio n. 2
0
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)
     utils.daemonize()
 if options.pid_file:
     open(options.pid_file, 'wb').write('%d\n' % os.getpid())
 
 status = Status(options.status_file, progress_range=(1, 70))
 status(progress=0)
 
 env = None
 try:
     try:
         env = parser.makewiki()            
         if not isinstance(env.wiki, zipwiki.Wiki)\
             or not isinstance(env.images, zipwiki.ImageDB):
             zip_filename = zipcreator.make_zip_file(options.keep_zip, env,
                 status=status,
                 num_threads=options.num_threads,
                 imagesize=options.imagesize,
             )
             if env.images:
                 try:
                     env.images.clear()
                 except OSError, err:
                     if err.errno!=errno.ENOENT:
                         raise
             env.wiki = zipwiki.Wiki(zip_filename)
             env.images = zipwiki.ImageDB(zip_filename)
             status = Status(options.status_file, progress_range=(71, 100))
         else:
             zip_filename = None
             status = Status(options.status_file, progress_range=(0, 100))
             
Esempio n. 4
0
        open(options.pid_file, 'wb').write('%d\n' % os.getpid())

    status = Status(options.status_file, progress_range=(1, 70))
    status(status='parsing', progress=0)

    env = None
    try:
        try:
            env = parser.makewiki()

            if not isinstance(env.wiki, zipwiki.Wiki)\
                or not isinstance(env.images, zipwiki.ImageDB):
                zip_filename = zipcreator.make_zip_file(
                    options.keep_zip,
                    env,
                    status=status,
                    num_threads=options.num_threads,
                    imagesize=options.imagesize,
                )
                if env.images:
                    env.images.clear()
                env.wiki = zipwiki.Wiki(zip_filename)
                env.images = zipwiki.ImageDB(zip_filename)
            else:
                zip_filename = None

            print 'START WITH PROGRESS'
            status = Status(options.status_file, progress_range=(71, 100))
            status(status='rendering', progress=0)

            fd, tmpout = tempfile.mkstemp(dir=os.path.dirname(options.output))