예제 #1
0
def _makewiki(conf):
    res = {}

    # yes, I really don't want to type this everytime
    wc = os.path.join(conf, "wikiconf.txt")
    if os.path.exists(wc):
        conf = wc 

    if conf.startswith("http://") or conf.startswith("https://"):
        res['wiki'] = wiki_mwapi(conf)
        res['images'] = image_mwapi(conf)
        return res
    
            
    if conf.lower().endswith(".zip"):
        from mwlib import zipwiki
        res['wiki'] = zipwiki.Wiki(conf)
        res['images'] = zipwiki.ImageDB(conf)
        return res

    cp=ConfigParser()

    if not cp.read(conf):
        raise RuntimeError("could not read config file %r" % (conf,))

        
    for s in ['images', 'wiki']:
        if not cp.has_section(s):
            continue
        
        args = dict(cp.items(s))
        if "type" not in args:
            raise RuntimeError("section %r does not have key 'type'" % s)
        t = args['type']
        del args['type']
        try:
            m = dispatch[s][t]
        except KeyError:
            raise RuntimeError("cannot handle type %r in section %r" % (t, s))
        
        res[s] = m(**args)

    assert "wiki" in res
    return res
예제 #2
0
def wiki_zip(path=None, url=None, name=None, **kwargs):
    from mwlib import zipwiki
    if kwargs:
        log.warn('Unused parameters: %r' % kwargs)
    return zipwiki.Wiki(path)
예제 #3
0
def _makewiki(
    conf,
    metabook=None,
    username=None,
    password=None,
    domain=None,
    script_extension=None,
):
    res = Environment(metabook)

    url = None
    if conf.startswith(':'):
        url = wpwikis.get(conf[1:])

    if conf.startswith("http://") or conf.startswith("https://"):
        url = conf

    if url:
        res.wiki = wiki_mwapi(
            url,
            username=username,
            password=password,
            domain=domain,
            script_extension=script_extension,
        )
        res.images = image_mwapi(
            url,
            username=username,
            password=password,
            domain=domain,
            script_extension=script_extension,
        )
        return res

    # yes, I really don't want to type this everytime
    wc = os.path.join(conf, "wikiconf.txt")
    if os.path.exists(wc):
        conf = wc

    if conf.lower().endswith(".zip"):
        from mwlib import zipwiki
        res.wiki = zipwiki.Wiki(conf)
        res.images = zipwiki.ImageDB(conf)
        if metabook is None:
            res.metabook = res.wiki.metabook
        return res

    cp = res.configparser

    if not cp.read(conf):
        raise RuntimeError("could not read config file %r" % (conf, ))

    for s in ['images', 'wiki']:
        if not cp.has_section(s):
            continue

        args = dict(cp.items(s))
        if "type" not in args:
            raise RuntimeError("section %r does not have key 'type'" % s)
        t = args['type']
        del args['type']
        try:
            m = dispatch[s][t]
        except KeyError:
            raise RuntimeError("cannot handle type %r in section %r" % (t, s))

        res[s] = m(**args)

    assert res.wiki is not None, '_makewiki should have set wiki attribute'
    return res
예제 #4
0
def wiki_zip(path=None, url=None, name=None):
    from mwlib import zipwiki
    return zipwiki.Wiki(path)
예제 #5
0
    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))
            os.close(fd)
            writer(env,
                   output=tmpout,
                   status_callback=status,
                   **writer_options)
            os.rename(tmpout, options.output)