Created
December 3, 2009 17:56
-
-
Save FND/248367 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
""" | |
simplewiki instantiation | |
""" | |
import sys | |
import os | |
# extend module search path for access to tiddlywebconfig.py | |
cwd = os.getcwd() | |
sys.path.insert(0, cwd) | |
from tiddlyweb.config import config | |
from tiddlywebplugins.instancer import Instance | |
def main(args): | |
args = [unicode(arg, "UTF-8") for arg in args] | |
instance_path = args[1] | |
store_structure = { | |
"bags": { | |
"wiki": { | |
"desc": "simplewiki contents", | |
"policy": { | |
"write": ["ANY"], # XXX: ? | |
"create": ["R:ADMIN"], | |
"delete": ["R:ADMIN"], | |
"manage": ["R:ADMIN"], | |
"accept": ["R:ADMIN"], | |
"owner": "administrator" # XXX: meaningless? | |
} | |
}, | |
}, | |
"recipes": { | |
"wiki": { | |
"desc": "simplewiki", | |
"recipe": [ | |
("wiki", "") | |
], | |
"policy": { | |
"write": ["R:ADMIN"], | |
"create": ["R:ADMIN"], | |
"manage": ["R:ADMIN"], | |
"accept": ["R:ADMIN"], | |
"delete": ["R:ADMIN"], | |
"owner": "administrator" # XXX: meaningless? | |
} | |
} | |
} | |
} | |
store_contents = { | |
"wiki": ["../tiddlywebplugins/resources/wiki/FrontPage.tid"] | |
} | |
config["instance_tiddlers"] = _get_instance_tiddlers(store_contents, "tiddlywebplugins") | |
instance_config = { | |
"system_plugins": ["tiddlywebplugins.simplewiki"] | |
} | |
instance = Instance(instance_path, config, instance_config) | |
instance.spawn(store_structure) | |
instance.update_store() | |
return True | |
def _get_instance_tiddlers(store_contents, package): # XXX: should be part of instancer? | |
""" | |
returns instance_tiddlers structure using packaged tiddlers if available | |
""" | |
tiddler_index = os.path.join(package, "resources", "tiddlers.index") | |
instance_tiddlers = [] | |
try: | |
filepaths = [] | |
with open(tiddler_index) as f: | |
for line in f: | |
bag, filename = line.rstrip().split("/", 1) | |
filepath = os.path.join("resources", bag, filename) | |
uri = "file:%s" % resource_filename(__package__, filepath) | |
filepaths.append(uri) | |
if filename.endswith(".js"): # unpack meta files into egg cache | |
resource_filename(__package__, "%s.meta" % filepath) | |
instance_tiddlers.append((bag, filepaths)) | |
except IOError: | |
for bag, uris in store_contents.items(): | |
instance_tiddlers.append((bag, uris)) | |
return instance_tiddlers | |
if __name__ == "__main__": | |
status = not main(sys.argv) | |
sys.exit(status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment