def render():
    from mwlib.options import OptionParser
    
    parser = OptionParser(config_optional=True)
    parser.add_option("-o", "--output", help="write output to OUTPUT")
    parser.add_option("-w", "--writer", help='use writer backend WRITER')
    parser.add_option("-W", "--writer-options",
        help='";"-separated list of additional writer-specific options',
    )
    parser.add_option("-e", "--error-file", help='write errors to this file')
    parser.add_option("-s", "--status-file",
        help='write status/progress info to this file',
    )
    parser.add_option("--list-writers",
        action='store_true',
        help='list available writers and exit',
    )
    parser.add_option("--writer-info",
        help='list information about given WRITER and exit',
        metavar='WRITER',
    )
    parser.add_option('--keep-zip',
        help='write ZIP file to FILENAME',
        metavar='FILENAME',
    )
    parser.add_option('--keep-tmpfiles',                  
        action='store_true',
        default=False,
        help="don't remove  temporary files like images",
    )
    parser.add_option('-L', '--language',
        help='use translated strings in LANGUAGE',
    )
    
    options, args = parser.parse_args()
    
    import sys
    import tempfile
    import traceback
    import errno
    import pkg_resources
    from mwlib.mwapidb import MWAPIError
    from mwlib.writerbase import WriterError
    from mwlib import utils, zipwiki, zipcreator
    from mwlib.status import Status
    
    use_help = 'Use --help for usage information.'
    
    def load_writer(name):
        try:
            entry_point = pkg_resources.iter_entry_points('mwlib.writers', name).next()
        except StopIteration:
            sys.exit('No such writer: %r (use --list-writers to list available writers)' % name)
        try:
            return entry_point.load()
        except Exception, e:
            sys.exit('Could not load writer %r: %s' % (name, e))
Beispiel #2
0
    def parse_options(self):
        parser = OptionParser()
        a = parser.add_option

        a("-o", "--output", help="write output to OUTPUT")

        a("-w", "--writer", help='use writer backend WRITER')

        a("-W",
          "--writer-options",
          help='";"-separated list of additional writer-specific options')

        a("-e", "--error-file", help='write errors to this file')

        a("-s",
          "--status-file",
          help='write status/progress info to this file')

        a("--list-writers",
          action='store_true',
          help='list available writers and exit')

        a("--writer-info",
          metavar='WRITER',
          help='list information about given WRITER and exit')

        a('--keep-zip', metavar='FILENAME', help='write ZIP file to FILENAME')

        a('--keep-tmpfiles',
          action='store_true',
          default=False,
          help="don't remove  temporary files like images")

        a('-L', '--language', help='use translated strings in LANGUAGE')

        options, args = parser.parse_args()
        return options, args, parser
Beispiel #3
0
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
Beispiel #4
0
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)
Beispiel #6
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)
Beispiel #7
0
def render():
    from mwlib.options import OptionParser

    parser = OptionParser(config_optional=True)
    parser.add_option("-o", "--output", help="write output to OUTPUT")
    parser.add_option("-w", "--writer", help='use writer backend WRITER')
    parser.add_option(
        "-W",
        "--writer-options",
        help='";"-separated list of additional writer-specific options',
    )
    parser.add_option("-e", "--error-file", help='write errors to this file')
    parser.add_option(
        "-s",
        "--status-file",
        help='write status/progress info to this file',
    )
    parser.add_option(
        "--list-writers",
        action='store_true',
        help='list available writers and exit',
    )
    parser.add_option(
        "--writer-info",
        help='list information about given WRITER and exit',
        metavar='WRITER',
    )
    parser.add_option(
        '--keep-zip',
        help='write ZIP file to FILENAME',
        metavar='FILENAME',
    )
    parser.add_option(
        '--keep-tmpfiles',
        action='store_true',
        default=False,
        help="don't remove  temporary files like images",
    )

    options, args = parser.parse_args()

    import sys
    import tempfile
    import traceback
    import pkg_resources
    from mwlib.mwapidb import MWAPIError
    from mwlib.writerbase import WriterError
    from mwlib import utils, zipwiki, zipcreator
    from mwlib.status import Status

    use_help = 'Use --help for usage information.'

    def load_writer(name):
        try:
            entry_point = pkg_resources.iter_entry_points(
                'mwlib.writers', name).next()
        except StopIteration:
            sys.exit(
                'No such writer: %r (use --list-writers to list available writers)'
                % name)
        try:
            return entry_point.load()
        except Exception, e:
            sys.exit('Could not load writer %r: %s' % (name, e))