# Path: tiddlywebplugins/tiddlyspace/instance.py

# 
# Path: tiddlywebplugins/tiddlyspace/config.py
# PACKAGE_NAME = 'tiddlywebplugins.tiddlyspace'
# TIDDLYWIKI_BETA = resource_filename(PACKAGE_NAME, 'resources/beta.html')
# TIDDLYWIKI_EXTERNAL_BETA = resource_filename(PACKAGE_NAME,
#         'resources/external_beta.html')
# TIDDLYWIKI_EXTERNAL = resource_filename(PACKAGE_NAME,
#         'resources/external.html')
# 
# Path: tiddlywebplugins/tiddlyspace/spaces.py
# def make_space(space_name, store, member):
#     """
#     The details of creating the bags and recipes that make up a space.
#     """
#     space = Space(space_name)
# 
#     for bag_name in space.list_bags():
#         bag = Bag(bag_name)
#         bag.policy = _make_policy(member)
#         if Space.bag_is_public(bag_name):
#             bag.policy.read = []
#         store.put(bag)
# 
#     info_tiddler = Tiddler('SiteInfo', space.public_bag())
#     info_tiddler.text = 'Space %s' % space_name
#     info_tiddler.modifier = store.environ.get('tiddlyweb.usersign',
#             {}).get('name', 'GUEST')
#     store.put(info_tiddler)
# 
#     # Duplicate GettingStarted into public bag.
#     getting_started_tiddler = Tiddler(GETTING_STARTED_TIDDLER['title'],
#             GETTING_STARTED_TIDDLER['bag'])
#     try:
#         getting_started_tiddler = store.get(getting_started_tiddler)
#         getting_started_tiddler.bag = space.public_bag()
#         store.put(getting_started_tiddler)
#     except StoreError:
#         pass
# 
#     public_recipe = Recipe(space.public_recipe())
#     public_recipe.set_recipe(space.public_recipe_list())
#     private_recipe = Recipe(space.private_recipe())
#     private_recipe.set_recipe(space.private_recipe_list())
#     private_recipe.policy = _make_policy(member)
#     public_recipe.policy = _make_policy(member)
#     public_recipe.policy.read = []
#     store.put(public_recipe)
#     store.put(private_recipe)


import os
import sys
import shutil
import httplib2
import Cookie
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
from tiddlyweb.model.bag import Bag
from tiddlyweb.model.recipe import Recipe
from tiddlyweb.config import config
from tiddlyweb.store import HOOKS
from tiddlywebplugins.utils import get_store
from tiddlywebplugins.imaker import spawn
from tiddlywebplugins.tiddlyspace import instance as instance_module
from tiddlywebplugins.tiddlyspace.config import config as init_config
from tiddlywebplugins.tiddlyspace.spaces import make_space
    from tiddlyweb.web import serve
        from tiddlywebplugins.whoosher import _tiddler_change_handler


def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config

# Path: tiddlywebplugins/tiddlyspace/instance.py

# 
# Path: tiddlywebplugins/tiddlyspace/config.py
# PACKAGE_NAME = 'tiddlywebplugins.tiddlyspace'
# TIDDLYWIKI_BETA = resource_filename(PACKAGE_NAME, 'resources/beta.html')
# TIDDLYWIKI_EXTERNAL_BETA = resource_filename(PACKAGE_NAME,
#         'resources/external_beta.html')
# TIDDLYWIKI_EXTERNAL = resource_filename(PACKAGE_NAME,
#         'resources/external.html')
# 
# Path: tiddlywebplugins/tiddlyspace/spaces.py
# def make_space(space_name, store, member):
#     """
#     The details of creating the bags and recipes that make up a space.
#     """
#     space = Space(space_name)
# 
#     for bag_name in space.list_bags():
#         bag = Bag(bag_name)
#         bag.policy = _make_policy(member)
#         if Space.bag_is_public(bag_name):
#             bag.policy.read = []
#         store.put(bag)
# 
#     info_tiddler = Tiddler('SiteInfo', space.public_bag())
#     info_tiddler.text = 'Space %s' % space_name
#     info_tiddler.modifier = store.environ.get('tiddlyweb.usersign',
#             {}).get('name', 'GUEST')
#     store.put(info_tiddler)
# 
#     # Duplicate GettingStarted into public bag.
#     getting_started_tiddler = Tiddler(GETTING_STARTED_TIDDLER['title'],
#             GETTING_STARTED_TIDDLER['bag'])
#     try:
#         getting_started_tiddler = store.get(getting_started_tiddler)
#         getting_started_tiddler.bag = space.public_bag()
#         store.put(getting_started_tiddler)
#     except StoreError:
#         pass
# 
#     public_recipe = Recipe(space.public_recipe())
#     public_recipe.set_recipe(space.public_recipe_list())
#     private_recipe = Recipe(space.private_recipe())
#     private_recipe.set_recipe(space.private_recipe_list())
#     private_recipe.policy = _make_policy(member)
#     public_recipe.policy = _make_policy(member)
#     public_recipe.policy.read = []
#     store.put(public_recipe)
#     store.put(private_recipe)


# Path: test/fixtures.py
import os
import sys
import shutil
import httplib2
import Cookie
        import tiddlywebplugins.tiddlyspace.store
        import tiddlywebplugins.mysql3
        import tiddlywebplugins.sqlalchemy3
from tiddlyweb.model.bag import Bag
from tiddlyweb.model.recipe import Recipe
from tiddlyweb.config import config
from tiddlyweb.store import HOOKS
from tiddlywebplugins.utils import get_store
from tiddlywebplugins.imaker import spawn
from tiddlywebplugins.tiddlyspace import instance as instance_module
from tiddlywebplugins.tiddlyspace.config import config as init_config
from tiddlywebplugins.tiddlyspace.spaces import make_space
    from tiddlyweb.web import serve
        from tiddlywebplugins.whoosher import _tiddler_change_handler



def make_test_env(module, hsearch=False):
    """
    If hsearch is False, don't bother updating the whoosh index
    for this test instance. We do this by removing the store HOOK
    used by whoosh.
    """
    global SESSION_COUNT

    # bump up a level if we're already in the test instance
    if os.getcwd().endswith('test_instance'):
        os.chdir('..')

    try:
        shutil.rmtree('test_instance')
    except:
        pass

    os.system('echo "drop database if exists tiddlyspacetest; create database tiddlyspacetest character set = utf8mb4 collate = utf8mb4_bin;" | mysql')
    if SESSION_COUNT > 1:
        del sys.modules['tiddlywebplugins.tiddlyspace.store']
        del sys.modules['tiddlywebplugins.mysql3']
        del sys.modules['tiddlywebplugins.sqlalchemy3']
        tiddlywebplugins.mysql3.Session.remove()
        clear_hooks(HOOKS)
    SESSION_COUNT += 1
    db_config = init_config['server_store'][1]['db_config']
    db_config = db_config.replace('///tiddlyspace?', '///tiddlyspacetest?')
    init_config['server_store'][1]['db_config'] = db_config

    init_config['log_level'] = 'DEBUG'