Created
October 23, 2009 15:07
-
-
Save FND/216962 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
#!/usr/bin/env python | |
""" | |
creates local cache of instance tiddlers to be included in distribution | |
Usage: | |
cacher.py <package> | |
""" | |
import sys | |
import os | |
# extend module search path for access to local mangler.py | |
sys.path.insert(0, os.getcwd()) | |
import mangler | |
from urllib2 import urlopen, URLError | |
from tiddlyweb.util import write_utf8_file, std_error_message | |
from tiddlywebplugins.instancer.sourcer import _expand_recipe | |
def main(args): | |
args = [unicode(arg, "UTF-8") for arg in args] | |
package = args[1] | |
instance_config = __import__("%s.instance" % package, fromlist=["instance"]) | |
package_path = os.path.join(*package.split(".")) | |
sources = {} | |
for bag, uris in instance_config.store_contents.items(): | |
sources[bag] = [] | |
for uri in uris: | |
if uri.endswith(".recipe"): | |
urls = _expand_recipe(uri) | |
sources[bag].extend(urls) | |
else: | |
sources[bag].append(uri) | |
metas = [] | |
for uri in sources[bag]: | |
if uri.endswith(".js"): | |
metas.append("%s.meta" % uri) | |
sources[bag].extend(metas) | |
resources_path = os.path.join(package_path, "resources") | |
try: | |
os.mkdir(resources_path) | |
except OSError: # directory exists | |
pass | |
for bag, uris in sources.items(): | |
bag_path = os.path.join(resources_path, bag) | |
try: | |
os.mkdir(bag_path) | |
except OSError: # directory exists | |
pass | |
for uri in uris: | |
filepath = os.path.join(bag_path, os.path.basename(uri)) | |
std_error_message("retrieving %s" % uri) | |
try: | |
content = urlopen(uri).read() | |
content = unicode(content, "utf-8") | |
write_utf8_file(filepath, content) | |
except URLError: | |
if uri.endswith(".meta"): | |
std_error_message("no meta file found for %s" % uri[:-5]) | |
else: | |
raise | |
tiddler_index = "tiddlers.index" | |
tiddler_paths = [] | |
for base_dir, dirs, files in os.walk(resources_path): | |
bag = os.path.basename(base_dir) | |
filepaths = (os.path.join(bag, filename) for filename in files | |
if not filename.endswith(".meta") and not filename == tiddler_index) | |
tiddler_paths.extend(filepaths) | |
filepath = "/".join([resources_path, tiddler_index]) | |
std_error_message("creating %s" % filepath) | |
write_utf8_file(filepath, "\n".join(tiddler_paths)) | |
filepath = "MANIFEST.in" | |
std_error_message("creating %s" % filepath) | |
write_utf8_file(filepath, "recursive-include %s/resources *\n" % package_path) | |
return True | |
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
import os | |
from pkg_resources import resource_filename | |
from tiddlyweb.config import config, merge_config | |
from tiddlywebwiki.config import config as twwconfig | |
from tiddlywebplugins.instancer.sourcer import _expand_recipe | |
from tiddlywebplugins.instancer.util import get_tiddler_locations | |
from twebical.instance import store_contents | |
merge_config(config, twwconfig) | |
try: | |
package = __package__ | |
except NameError: # Python 2.5.x | |
package = __name__.rsplit(".", 1)[0] | |
config["instance_tiddlers"] = get_tiddler_locations(store_contents, package) |
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 | |
import os | |
# extend module search path for access to tiddlywebconfig.py | |
sys.path.insert(0, os.getcwd()) | |
from tiddlywebplugins.instancer import Instance | |
from twebical.config import config | |
from twebical.instance import store_structure, instance_config | |
def main(args=None): | |
# XXX: DRY; 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) | |
instance = Instance(instance_path, config, instance_config) | |
instance.spawn(store_structure) | |
instance.update_store() | |
return True | |
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
recipe: ../../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
recipe: 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
store_contents = { | |
"system": [ | |
"http://svn.tiddlywiki.org/Trunk/verticals/TiddlyWebWiki/index.recipe" | |
] | |
} | |
instance_config = { # XXX: DRY; cf. tiddlywebwiki.instancer.instance | |
"system_plugins": ["tiddlywebwiki", "tiddlywebplugins.status", "differ"], | |
"twanager_plugins": ["tiddlywebwiki"] | |
} | |
store_structure = { | |
"bags": { | |
"system": { | |
"desc": "TiddlyWebWiki client", | |
"policy": { | |
"write": ["R:ADMIN"], | |
"create": ["R:ADMIN"], | |
"delete": ["R:ADMIN"], | |
"manage": ["R:ADMIN"], | |
"accept": ["R:ADMIN"], | |
"owner": "administrator" # XXX: meaningless? | |
} | |
}, | |
"common": { | |
"desc": "shared content", | |
"policy": { | |
"delete": ["R:ADMIN"], | |
"manage": ["R:ADMIN"], | |
} | |
} | |
}, | |
"recipes": { | |
"default": { | |
"desc": "", # TODO | |
"recipe": [ | |
("system", ""), | |
("common", "") | |
] | |
}, | |
"blog": { # XXX: DEBUG | |
"desc": "blog entries", | |
"recipe": [ | |
("common", "select=tag:blog") | |
], | |
"policy": { | |
"read": ["R:ADMIN"], | |
"write": ["R:ADMIN"], | |
"create": ["R:ADMIN"], | |
"manage": ["R:ADMIN"], | |
"accept": ["R:ADMIN"], | |
"delete": ["R:ADMIN"], | |
"owner": "administrator" | |
} | |
} | |
}, | |
"users": { | |
"administrator": { | |
"note": "system administrator", | |
"roles": ["ADMIN"] | |
} | |
} | |
} |
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
.PHONY: test dist release | |
clean: | |
find . -name "*.pyc" | xargs rm || true | |
rm -r build dist *.egg-info || true | |
rm -r MANIFEST.in twebical/resources || true | |
test: | |
py.test -x test | |
dist: test | |
python setup.py sdist | |
release: clean pypi | |
pypi: | |
python setup.py sdist upload |
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
import os | |
from setuptools import setup, find_packages | |
from twebical import __version__ | |
setup( | |
name = "twebical", | |
version = __version__, | |
url = "http://pypi.python.org/pypi/twebical", # XXX: ? | |
description = "sample TiddlyWeb vertical", | |
long_description = file(os.path.join(os.path.dirname(__file__), "README")).read(), | |
platforms = "Posix; MacOS X; Windows", | |
author = "FND", | |
author_email = "FNDo@gmx.net", | |
packages = find_packages(exclude=["test"]), | |
py_modules = [], # TODO | |
scripts = ['create_instance'], | |
install_requires = ["setuptools", | |
"tiddlyweb", "tiddlywebwiki", | |
"tiddlywebplugins.instancer"], | |
include_package_data = True | |
) |
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 | |
""" | |
import os | |
import tiddlywebplugins.devstore | |
import twebical.instance | |
# prevent local tiddlers from being created in the devstore | |
tiddlywebplugins.devstore.Store.tiddler_put = lambda self, tiddler: None | |
# add devstore to default instance configuration | |
STORE = ["tiddlywebplugins.devstore", { "store_root": "store" }] | |
twebical.instance.instance_config["server_store"] = STORE | |
# provide access to local packages | |
base_path = os.path.abspath(".") | |
instance_config_head = """ | |
import sys; sys.path.insert(0, "%s") | |
""" % base_path | |
config = { | |
"system_plugins": ["tiddlywebwiki", "status", "differ"], | |
"twanager_plugins": ["tiddlywebwiki"], | |
"server_store": STORE, | |
"instance_tiddlers": { | |
"system": ["../index.dev.recipe"], | |
"common": [] | |
}, | |
"instance_config_head": instance_config_head, | |
"log_level": "DEBUG" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment