Extension:Collection/Source/Documentation

MW Render
mw-render is a wrapper script that uses the function load_entry_point to call the Extension:Collection/Source/render mwlib/apps/render.py module. The entry point is Main which firsts builds an environment. Extension:Collection/Source/render/get_environment

env = self.get_environment

This called the creation of a meta book from the zipfile that is passed, env = wiki.makewiki(self.zip_filename)

Which again calls the internal makewiki function res = _makewiki(config, metabook=metabook, **kw)

Which then usese the nuwiki class to read in the zipfile res.images = res.wiki = nuwiki.adapt(zf)

The nuwiki reads in the metabook.json data from the zipfile self.metabook = self.nuwiki.get_data("metabook") return self._loadjson(name+".json")

and that reads the file and loads it as a json object return json.load(open(path, "rb"))

Thus the object of the type metabook collection is created from the load routine in json.

= Adding of articles to the metabook =

Arguments from the command line
in the file mwlib/mwlib/apps/render.py the parser is set to self.parse_options this method parse_options calles args = parser.parse_args and in the file "mwlib/mwlib/options.py" the articles are append to the last unnamed articles of mwrender which are considered to be titles self.metabook.append_article(title)

In this case, the self.metabook is created in the OptionParser as the member variable self.metabook = metabook.collection. This is not the same as the metabook created and loaded in nuwiki.

Appending Found Articles In test code
env = self.get_environment(options.metabook) # we will pass the args to reuse the metabook self.zip_filename = make_zip(output=self.options.keep_zip, options=self.options, metabook=env.metabook, status=self.status) in apps/buildzip.py   make_nuwiki(fsdir, metabook=metabook, options=options, podclient=podclient, status=status) apps/make_nuwiki.py in make_nuwiki reactor.run in twisted/internet/base.py", in run   self.mainLoop in base.py", mainLoop self.doIteration(t)

in twisted/internet/selectreactor.py in doSelect _logrun(selectable, _drdw, selectable, method, dict) in twisted/python/log.py in callWithLogger return callWithContext({"system": lp}, func, *args, **kw) in twisted/python/log.py in callWithContext return context.call({ILogContext: newCtx}, func, *args, **kw) return self.currentContext.callWithContext(ctx, func, *args, **kw) in twisted/python/context.py", in callWithContext   return func(*args,**kw) in twisted/internet/selectreactor.py", in _doReadOrWrite why = getattr(selectable, method)
 * 1) then enters into the twisted stack


 * 1) the data is received from the network

in twisted/internet/tcp.py", line 460, in doRead   return self.protocol.dataReceived(data) in twisted/protocols/basic.py",  in dataReceived return self.rawDataReceived(data) in twisted/web/http.py", in rawDataReceived    self.handleResponseEnd in twisted/web/http.py",  in handleResponseEnd self.handleResponse(b) in twisted/web/client.py", in handleResponse   self.factory.page(response) in twisted/web/client.py", in page self.deferred.callback(page) in twisted/internet/defer.py", in callback   self._startRunCallbacks(result) in twisted/internet/defer.py", in _startRunCallbacks self._runCallbacks

in twisted/internet/defer.py",in _runCallbacks   self.result = callback(self.result, *args, **kw) twisted call back int our routine :


 * 1) in the done routine after we fetch a page, we are passed a callback

called from client.getPage(url, cookies=self.cookies).addCallbacks(done, done)

in "mwlib/mwlib/net/mwapi.py", line 250, in done(val), in class mwapi method _fetch(url) d.callback(val),
 * 1) d is a defered object that is returned.

in twisted/internet/defer.py", line 318, in callback   self._startRunCallbacks(result)

LOOP 3 x   self._runCallbacks # in _startRunCallbacks self.result = callback(self.result, *args, **kw) # in _runCallbacks self._startRunCallbacks(result) # in callback

Back in mwlib/net/fetch.py in got_cats self.mb.append_article(x["title"])

and this calls metabook.py append_article