14th
Tiddlywebweb to App Engine
In the previous posting I showed how to get TiddlyWeb working with Google App Engine but left things a bit hanging: There was no easy way to get some initial content bootstrapped into the hosted TiddlyWeb. It is possible to do direct HTTP calls to the server, using something like curl, but that can be a bit cumbersome. Another option is to use tiddlywebweb, I’ll describe that method here.
tiddlywebweb was first mentioned on this blog in a posting that described how to make a store for TiddlyWeb and ranted a bit about how useful a well described and nicely constrained HTTP API can be. tiddlywebweb uses the TiddlyWeb HTTP API to store and retrieve content to and from a remote TiddlyWeb server. Talking to a TiddlyWeb server is exactly what we need to solve our app engine problem, so let’s do it.
If you’ve followed the instructions in the previous posting you have, running in your local app engine SDK, a TiddlyWeb server at http://localhost:8080/. If you go that URL you’ll see there are links for bags and recipes, but no bags and recipes to be found, and no tiddlers. Leave the server running. In a terminal window do the following:
mkdir gaeproxy
cd gaeproxy
sudo pip install -U tiddlywebplugins.tiddlywebweb
If you don’t want to install all the dependencies (because you already have them) you can add a --no-deps after the -U. If you prefer to work with a virtualenv, go for it, the goals here are:
- Make a directory in which we will create a tiddlyweb instance.
- Install
tiddlywebplugins.tiddlywebweb.
Once the install is done, we need to create, in the gaeproxy directory, a tiddlywebconfig.py file with the following contents:
config = {
'log_level': 'DEBUG',
'server_store': ['tiddlywebplugins.tiddlywebweb', {
'server_base': 'http://localhost:8080',
}],
'system_plugins': ['tiddlywebwiki'],
'twanager_plugins': ['tiddlywebwiki'],
}
You can then run a command to confirm a) that things aren’t going to blow up 2. that there’s nothing in the store:
twanager lbags
This should return nothing but also report no errors. If you get errors you’ll want to confirm that your configuration is correct, you have the required modules installed, and your app engine application is running.
Once you’ve confirmed there’s nothing in the store, we can put some stuff in there:
twanager bag system </dev/null
twanager bag common </dev/null
echo $'/bags/system/tiddlers\n/bags/common/tiddlers' | \
twanager recipe default
twanager update
Those commands create two bags, system and common, create a recipe using those bags and then update the contents of the bags with tiddlers provided by the tiddlywebwiki plugin.
Now go to app engine TiddlyWeb at http://localhost:8080/recipes/default/tiddlers.wiki and see if you have a wiki.
Another useful command that works over tiddlywebweb is imwiki. If you have a TiddlyWiki you’d like to import into your app engine setup, go to your gaeproxy directory, and twanager imwiki common < mywikifile.html.
So there’s the basics of using tiddlywebweb with a TiddlyWeb hosted on google app engine. If you’ve deployed your application to Google’s appspot, update the tiddlywebconfig.py in the gaeproxy directory so that server_base points to the appspot domain instead of localhost.
There are some limitations with this approach:
- User entities are not exposed over the TiddlyWeb HTTP API, so twanager commands for manipulating users (
lusers,adduser,addrole,userpass) will not work. In the app engine setting this doesn’t really matter as Google users are used, not TiddlyWeb users. - If you’re not familiar with directly manipulating
tiddlywebconfig.pyand TiddlyWeb instances, this process may be rather opaque. FND has done some experimenting with creating instances that take out some of the steps. Perhaps he will post the details.
This combination of stuff has so many little happy web bits.
