def test_tiddler_racing():
    def race_tiddlers(bag_name, count=2, intitles=['x', 'z'], outtitles=['y']):
        bag = Bag(bag_name)
        store.put(bag)
        tiddlers = Tiddlers(store=store)

        for title in ['x', 'y', 'z']:
            tiddler = Tiddler(title, 'foo')
            store.put(tiddler)
            tiddlers.add(tiddler)

        tiddler = Tiddler('y', 'foo')
        store.delete(tiddler)

        tids = list(tiddlers)
        assert len(tids) == count
        for title in intitles:
            assert title in [tiddler.title for tiddler in tids]
        for title in outtitles:
            assert title not in [tiddler.title for tiddler in tids]
    stored_config = config.get('collections.use_memory')
    config['collections.use_memory'] = False
    race_tiddlers('foo')
    config['collections.use_memory'] = True
    race_tiddlers('bar', count=3, intitles=['x', 'y', 'z'], outtitles=[])
    store.delete(Bag('foo'))
    store.delete(Bag('bar'))
Example #2
0
def test_tiddler_racing():

    def race_tiddlers(bag_name, count=2, intitles=['x', 'z'],
            outtitles=['y']):
        bag = Bag(bag_name)
        store.put(bag)
        tiddlers = Tiddlers(store=store)

        for title in ['x', 'y', 'z']:
            tiddler = Tiddler(title, 'foo')
            store.put(tiddler)
            tiddlers.add(tiddler)

        tiddler = Tiddler('y', 'foo')
        store.delete(tiddler)

        tids = list(tiddlers)
        assert len(tids) == count
        for title in intitles:
            assert title in [tid.title for tid in tids]
        for title in outtitles:
            assert title not in [tid.title for tid in tids]

    stored_config = config.get('collections.use_memory')
    config['collections.use_memory'] = False
    race_tiddlers('foo')
    config['collections.use_memory'] = True
    race_tiddlers('bar', count=3, intitles=['x', 'y', 'z'], outtitles=[])
    store.delete(Bag('foo'))
    store.delete(Bag('bar'))
    config['collections.use_memory'] = stored_config
Example #3
0
def handle(args):
    """
    Dispatch to the proper function for the command given in ``args[1]``.
    """
    from tiddlyweb.config import config

    options = _extract_options(args, ['load'])
    if 'load' in options:
        _external_load(options['load'], config)
    if 'tb' in options:
        config['twanager.tracebacks'] = True

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            LOGGER.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    args = [unicode(arg) for arg in args]
    if candidate_command and candidate_command in COMMANDS:
        try:
            LOGGER.debug('running command %s with %s',
                    candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError:
            usage('Incorect number of arguments')
        except Exception as exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            LOGGER.error('twanager error with command "%s %s"\n%s',
                    candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args[0]))
    else:
        usage('No matching command found')
Example #4
0
def handle(args):
    """
    Dispatch to the proper function for the command given in ``args[1]``.
    """
    from tiddlyweb.config import config

    options = _extract_options(args, ['load'])
    if 'load' in options:
        _external_load(options['load'], config)
    if 'tb' in options:
        config['twanager.tracebacks'] = True

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            LOGGER.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    args = [unicode(arg) for arg in args]
    if candidate_command and candidate_command in COMMANDS:
        try:
            LOGGER.debug('running command %s with %s', candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError:
            usage('Incorect number of arguments')
        except Exception as exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            LOGGER.error('twanager error with command "%s %s"\n%s',
                         candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args[0]))
    else:
        usage('No matching command found')
Example #5
0
def handle(args):
    """
    Dispatch to the proper function for the command
    given in a args[1].
    """
    from tiddlyweb.config import config

    try:
        if args[1] == "--load":
            args = _external_load(args, config)
    except IndexError:
        args = []

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config["twanager_plugins"])
        for plugin in plugins:
            logging.debug("attempting to import twanager plugin %s", plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ["init"])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage("Missing command")

    try:
        args = args[2:]
    except IndexError:
        args = []

    if candidate_command and candidate_command in COMMANDS:
        try:
            logging.debug("running command %s with %s", candidate_command, args)
            COMMANDS[candidate_command](args)
        except IndexError, exc:
            usage("Incorect number of arguments")
        except Exception, exc:
            if config.get("twanager.tracebacks", False):
                raise
            import traceback

            logging.error('twanager error with command "%s %s"\n%s', candidate_command, args, traceback.format_exc())
            usage("%s: %s" % (exc.__class__.__name__, exc.args))
Example #6
0
def handle(args):
    """
    Dispatch to the proper function for the command
    given in a args[1].
    """
    from tiddlyweb.config import config
    try:
        if args[1] == '--load':
            args = _external_load(args, config)
    except IndexError:
        args = []

    initialize_logging(config)

    plugins = INTERNAL_PLUGINS
    try:
        plugins.extend(config['twanager_plugins'])
        for plugin in plugins:
            logging.debug('attempting to import twanager plugin %s', plugin)
            # let the import fail with error if it does
            imported_module = __import__(plugin, {}, {}, ['init'])
            imported_module.init(config)
    except KeyError:
        pass  # no plugins

    candidate_command = None
    try:
        candidate_command = args[1]
    except IndexError:
        usage('Missing command')

    try:
        args = args[2:]
    except IndexError:
        args = []

    if candidate_command and candidate_command in COMMANDS:
        try:
            logging.debug('running command %s with %s', candidate_command,
                          args)
            COMMANDS[candidate_command](args)
        except IndexError, exc:
            usage('Incorect number of arguments')
        except Exception, exc:
            if config.get('twanager.tracebacks', False):
                raise
            import traceback
            logging.error('twanager error with command "%s %s"\n%s',
                          candidate_command, args, traceback.format_exc())
            usage('%s: %s' % (exc.__class__.__name__, exc.args))
def get_bag_retriever(environ, bag):
    """
    Inspect config['special_bag_detectors'] to special
    handlers for bags, like remote uris.
    """
    try:
        config = environ['tiddlyweb.config']
    except KeyError:
        from tiddlyweb.config import config
    testers = config.get('special_bag_detectors', [])
    for bag_tester in testers:
        retriever = bag_tester(environ, bag)
        if retriever:
            return retriever
    return None
Example #8
0
def get_bag_retriever(environ, bag):
    """
    Inspect config['special_bag_detectors'] to special
    handlers for bags, like remote uris.
    """
    try:
        config = environ['tiddlyweb.config']
    except KeyError:
        from tiddlyweb.config import config
    testers = config.get('special_bag_detectors', [])
    for bag_tester in testers:
        retriever = bag_tester(environ, bag)
        if retriever:
            return retriever
    return None
Example #9
0
def get_bag_retriever(environ, bag):
    """
    When loading :py:class:`bag <tiddlyweb.model.bag.Bag>` or
    :py:class:`tiddlers <tiddlyweb.model.tiddler.Tiddler>` within it
    from the :py:class:`store <tiddlyweb.store.Store>`, this method is
    used to inspect ``config['special_bag_detectors']`` to determine
    if there is a special handler. If there is, the handler is returned
    and used for retrieval, otherwise ``None`` is returned and the store
    is used as normal.
    """
    try:
        config = environ['tiddlyweb.config']
    except KeyError:
        from tiddlyweb.config import config
    testers = config.get('special_bag_detectors', [])
    for bag_tester in testers:
        retriever = bag_tester(environ, bag)
        if retriever:
            return retriever
    return None
Example #10
0
def get_bag_retriever(environ, bag):
    """
    When loading :py:class:`bag <tiddlyweb.model.bag.Bag>` or
    :py:class:`tiddlers <tiddlyweb.model.tiddler.Tiddler>` within it
    from the :py:class:`store <tiddlyweb.store.Store>`, this method is
    used to inspect ``config['special_bag_detectors']`` to determine
    if there is a special handler. If there is, the handler is returned
    and used for retrieval, otherwise ``None`` is returned and the store
    is used as normal.
    """
    try:
        config = environ["tiddlyweb.config"]
    except KeyError:
        from tiddlyweb.config import config
    testers = config.get("special_bag_detectors", [])
    for bag_tester in testers:
        retriever = bag_tester(environ, bag)
        if retriever:
            return retriever
    return None