-
-
Save cdent/232010 to your computer and use it in GitHub Desktop.
This file contains 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
*.pyc |
This file contains 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
This file contains 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
__version__ = "0.1.0" |
This file contains 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
A sample TiddlyWebWiki vertical. |
This file contains 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
from tiddlyweb.config import config, merge_config | |
from tiddlywebwiki.config import config as twwconfig | |
merge_config(config, twwconfig) |
This file contains 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 | |
""" | |
creates a preconfigured TiddlyWeb instance | |
""" | |
import sys, os | |
from tiddlyweb.model.bag import Bag | |
from tiddlyweb.model.recipe import Recipe | |
from tiddlyweb.model.user import User | |
from tiddlyweb.model.tiddler import Tiddler | |
from twp.instancer import Instance | |
from tiddlywebplugins.utils import get_store | |
from twebical.config import config | |
def main(args=None): | |
# XXX: duplication; cf. twinstance | |
args = [unicode(arg, "UTF-8") for arg in args] | |
try: | |
instance_path = args[1] | |
except IndexError: | |
prompt = "Please enter instance name or path:\n" | |
instance_path = raw_input(prompt) | |
default_instance_config = { | |
"system_plugins": ["tiddlywebwiki", "tiddlywebplugins.status", "differ"], | |
"twanager_plugins": ["tiddlywebwiki"] | |
} # XXX: duplication; cf. tiddlywebwiki.instancer.instance | |
instance = Instance(instance_path, config, default_instance_config) | |
instance.spawn() | |
init_store_structure(instance) # XXX: does not need to precede update_store | |
instance.update_store() | |
return True | |
def init_store_structure(instance): | |
from instanceconfig import instance_struct | |
for bag in instance_struct.get('bags', []): | |
_make_bag(bag) | |
for recipe in instance_struct.get('recipes', []): | |
_make_recipe(recipe) | |
for user in instance_struct.get('users', []): | |
_make_user(user) | |
for tiddler in instance_struct.get('tiddlers', []): | |
_make_tiddler(tiddler) | |
def _make_bag(bag_data): | |
store = get_store(config) | |
bag = Bag(bag_data['name']) | |
policy = bag_data.get('policy', {}) | |
for constraint in policy: | |
setattr(bag.policy, constraint, policy[constraint]) | |
bag.desc = bag_data.get('desc', '') | |
store.put(bag) | |
def _make_recipe(recipe_data): | |
store = get_store(config) | |
recipe = Recipe(recipe_data['name']) | |
policy = recipe_data.get('policy', {}) | |
for constraint in policy: | |
setattr(recipe.policy, constraint, policy[constraint]) | |
recipe.desc = recipe_data.get('desc', '') | |
store.put(recipe) | |
def _make_user(user_data): | |
store = get_store(config) | |
user = User(user_data['name']) | |
for role in user_data.get('roles', []): | |
user.add_role(role) | |
try: | |
user.set_password(user_data['password']) | |
except KeyError: | |
pass | |
store.put(user) | |
def _make_tiddler(tiddler_data): | |
store = get_store(config) | |
tiddler = Tiddler(tiddler_data['title'], tiddler_data['bag']) | |
del tiddler_data['title'] | |
del tiddler_data['bag'] | |
for key in tiddler_data: | |
try: | |
setattr(tiddler, key, tiddler_data[key]) | |
except AttributeError: | |
tiddler.fields[key] = tiddler_data[key] | |
store.put(tiddler) | |
if __name__ == "__main__": | |
status = not main(sys.argv) | |
sys.exit(status) |
This file contains 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
../../TiddlyWiki/svn.tiddlywiki.org/Trunk/verticals/TiddlyWebWiki/index.recipe |
This file contains 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
http://svn.tiddlywiki.org/Trunk/verticals/TiddlyWebWiki/index.recipe |
This file contains 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
root_username = 'admin' | |
admin_policy = { | |
'read': ["ANY"], | |
'write': ["R:ADMIN"], | |
'create': ["R:ADMIN"], | |
'delete': ["R:ADMIN"], | |
'manage': ["R:ADMIN"], | |
'owner': root_username, | |
} | |
authed_policy = { | |
'read': ["ANY"], | |
'write': ["ANY"], | |
'create': ["ANY"], | |
'delete': ["R:ADMIN"], | |
'manage': ["R:ADMIN"], | |
'owner': root_username, | |
} | |
instance_struct = { | |
'bags': [ | |
{'name': 'bag one', | |
'policy': admin_policy, | |
'desc': 'this is an admin bag'}, | |
{'name': 'bag two', | |
'policy': authed_policy, | |
'desc': 'this is an authed bag'}, | |
], | |
'recipes': [ | |
{'name': 'recipe one', | |
'policy': admin_policy, | |
'desc': 'this is recipe one'}, | |
{'name': 'recipe two', | |
'policy': admin_policy, | |
'desc': 'this is recipe two'} | |
], | |
'users': [ | |
{'name': root_username, | |
'roles': ['ADMIN']}, | |
{'name': 'demouser'} | |
], | |
# probably don't want tiddlers in here. They are much better served by | |
# instance tiddlers, but including for completeness. | |
'tiddlers': [ | |
{'title': 'tiddler_one', | |
'bag': 'bag one', | |
'text': '!Hello', | |
'field1': 'field 1 value', | |
'modifier': root_username | |
}, | |
{'title': 'tiddler_one', | |
'bag': 'bag two', | |
'text': '!Goodbye', | |
'field1': 'field 1 value', | |
'modifier': root_username | |
}, | |
], | |
} |
This file contains 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
# configuration for development environment | |
config = { | |
'system_plugins': ['tiddlywebwiki', 'status', 'differ'], | |
'twanager_plugins': ['tiddlywebwiki'], | |
'server_store': ['devstore', { 'store_root': 'store' }], | |
'instance_tiddlers': [ | |
('system', ['../index.dev.recipe']), | |
('common', []) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment