def test_bag_get(): store = Store("tiddlywebplugins.mappingsql", {"db_config": "sqlite:///test.db"}, {"tiddlyweb.config": config}) bag = Bag("avox") assert len(list(store.list_bag_tiddlers(bag))) == 1 bag = store.get(bag) assert len(list(store.list_bag_tiddlers(bag))) == 1 assert "NONE" in bag.policy.write
def test_bag_get(): store = Store('tiddlywebplugins.mappingsql', {'db_config': 'sqlite:///test.db'}, {'tiddlyweb.config': config}) bag = Bag('avox') assert len(list(store.list_bag_tiddlers(bag))) == 1 bag = store.get(bag) assert len(list(store.list_bag_tiddlers(bag))) == 1 assert "NONE" in bag.policy.write
def profile_listing_tiddlers(): store = Store('text', environ['tiddlyweb.config']['server_store'][1], environ) environ['tiddlyweb.store'] = store bag = Bag('profiler') print 'filter', time() filter_string = 'select=tag:1' filters, leftovers = parse_for_filters(filter_string, environ) tiddlers = control.filter_tiddlers(store.list_bag_tiddlers(bag), filters, environ=environ) print 'output', time() print [tiddler.title for tiddler in tiddlers]
def update_store(self): """ prepopulates/updates store contents by (re)importing instance_tiddlers """ cwd = os.getcwd() os.chdir(self.root) store = get_store(self.init_config) for package_name in self.init_config['instance_pkgstores']: source_store = Store('tiddlywebplugins.pkgstore', {'package': package_name, 'read_only': True}, {'tiddlyweb.config': self.init_config}) for bag in source_store.list_bags(): for tiddler in source_store.list_bag_tiddlers(bag): tiddler = source_store.get(tiddler) store.put(tiddler) os.chdir(cwd)
def test_put_tiddler_to_store(): _cleanup() config = { "server_store": ["tiddlywebplugins.devstore", { "store_root": STORE_DIR }], "instance_tiddlers": { "myBag": ["%s/alpha/index.recipe" % REPO_DIR] }, "root_dir": "" } env = { "tiddlyweb.config": config } store = Store(config["server_store"][0], config["server_store"][1], env) tiddler = Tiddler("lorem") tiddler.bag = "myBag" store.put(tiddler) tiddler_path = os.path.join(STORE_DIR, tiddler.bag, "%s.tid" % tiddler.title) assert os.path.exists(tiddler_path) tiddler = Tiddler("foo bar") tiddler.bag = "myBag" store.put(tiddler) tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%20bar.tid") assert os.path.exists(tiddler_path) assert store.get(tiddler).title == "foo bar" # XXX: testing get operation here for convenience bag = Bag("myBag") try: assert "foo bar" in [t.title for t in store.list_bag_tiddlers(bag)] except AttributeError: # TiddlyWeb 1.0 has no list_bag_tiddlers method pass tiddler = Tiddler("foo/bar") tiddler.bag = "myBag" store.put(tiddler) tiddler_path = os.path.join(STORE_DIR, "myBag", "foo%2Fbar.tid") assert os.path.exists(tiddler_path) assert store.get(tiddler).title == "foo/bar"
def profile_listing_tiddlers(): store = Store('text', environ['tiddlyweb.config']['server_store'][1], environ) environ['tiddlyweb.store'] = store bag = Bag('profiler') print 'filter', time() filter_string = 'select=tag:1' filters, leftovers = parse_for_filters(filter_string, environ) tiddlers = control.filter_tiddlers(store.list_bag_tiddlers(bag), filters, environ=environ) print 'output', time() print[tiddler.title for tiddler in tiddlers] #print 'serializer', time() #serializer = Serializer('wiki', environ) #print 'wikify', time() #output = serializer.list_tiddlers(tmp_bag) print 'done', time()
class Store(StorageInterface): def __init__(self, store_config=None, environ=None): super(Store, self).__init__(store_config, environ) self.config = environ.get('tiddlyweb.config') self.binary_store = StoreBoss('text', { 'store_root': 'binarystore' }, environ=environ).storage self.core_store = StoreBoss(self.config['binarystore.child'][0], self.config['binarystore.child'][1], environ=environ).storage def bag_put(self, bag): self.core_store.bag_put(bag) def bag_get(self, bag): return self.core_store.bag_get(bag) def bag_delete(self, bag): try: self.binary_store.bag_delete(bag) except NoBagError: pass return self.core_store.bag_delete(bag) def recipe_put(self, recipe): self.core_store.recipe_put(recipe) def recipe_get(self, recipe): return self.core_store.recipe_get(recipe) def recipe_delete(self, recipe): return self.core_store.recipe_delete(recipe) def user_put(self, user): self.core_store.user_put(user) def user_get(self, user): return self.core_store.user_get(user) def user_delete(self, user): return self.core_store.user_delete(user) def tiddler_delete(self, tiddler): self.core_store.tiddler_delete(tiddler) if binary_tiddler(tiddler): self.binary_store.tiddler_delete(tiddler) def tiddler_put(self, tiddler): if binary_tiddler(tiddler): try: self.binary_store.tiddler_put(tiddler) except NoBagError: self.binary_store.bag_put(Bag(tiddler.bag)) self.binary_store.tiddler_put(tiddler) tiddler.text = '' self.core_store.tiddler_put(tiddler) def tiddler_get(self, tiddler): found_tiddler = self.core_store.tiddler_get(tiddler) if binary_tiddler(found_tiddler): found_tiddler.__class__ = BinaryTiddler found_tiddler._text = None return found_tiddler def list_recipes(self): return self.core_store.list_recipes() def list_bags(self): return self.core_store.list_bags() def list_users(self): return self.core_store.list_users() def list_bag_tiddlers(self, bag): return self.core_store.list_bag_tiddlers(bag) def list_tiddler_revisions(self, tiddler): return self.core_store.list_tiddler_revisions(tiddler) def search(self, search_query): return self.core_store.search(search_query)
class Store(StorageInterface): def __init__(self, store_config=None, environ=None): super(Store, self).__init__(store_config, environ) self.config = environ.get('tiddlyweb.config') self.binary_store = StoreBoss('text', {'store_root': 'binarystore'}, environ=environ).storage self.core_store = StoreBoss(self.config['binarystore.child'][0], self.config['binarystore.child'][1], environ=environ).storage def bag_put(self, bag): self.core_store.bag_put(bag) def bag_get(self, bag): return self.core_store.bag_get(bag) def bag_delete(self, bag): try: self.binary_store.bag_delete(bag) except NoBagError: pass return self.core_store.bag_delete(bag) def recipe_put(self, recipe): self.core_store.recipe_put(recipe) def recipe_get(self, recipe): return self.core_store.recipe_get(recipe) def recipe_delete(self, recipe): return self.core_store.recipe_delete(recipe) def user_put(self, user): self.core_store.user_put(user) def user_get(self, user): return self.core_store.user_get(user) def user_delete(self, user): return self.core_store.user_delete(user) def tiddler_delete(self, tiddler): self.core_store.tiddler_delete(tiddler) if binary_tiddler(tiddler): self.binary_store.tiddler_delete(tiddler) def tiddler_put(self, tiddler): if binary_tiddler(tiddler): try: self.binary_store.tiddler_put(tiddler) except NoBagError: self.binary_store.bag_put(Bag(tiddler.bag)) self.binary_store.tiddler_put(tiddler) tiddler.text = '' self.core_store.tiddler_put(tiddler) def tiddler_get(self, tiddler): found_tiddler = self.core_store.tiddler_get(tiddler) if binary_tiddler(found_tiddler): found_tiddler.__class__ = BinaryTiddler found_tiddler._text = None return found_tiddler def list_recipes(self): return self.core_store.list_recipes() def list_bags(self): return self.core_store.list_bags() def list_users(self): return self.core_store.list_users() def list_bag_tiddlers(self, bag): return self.core_store.list_bag_tiddlers(bag) def list_tiddler_revisions(self, tiddler): return self.core_store.list_tiddler_revisions(tiddler) def search(self, search_query): return self.core_store.search(search_query)