コード例 #1
0
def test_store_lock():
    """
    Make the sure the locking system throws the proper lock.
    """

    texter = Texter(environ={'tiddlyweb.config': {'server_store': ['text', {'store_root': 'store'}]}})
    write_lock(textstore.bag_store)
    py.test.raises(LockError, 'write_lock(textstore.bag_store)')

    write_lock(textstore.bag_store + '/bagone/tiddlers/foobar')
    tiddler = Tiddler('foobar')
    tiddler.text='hello'
    tiddler.bag = 'bagone'
    py.test.raises(StoreLockError, 'store.put(tiddler)')
コード例 #2
0
ファイル: test_store_tiddler.py プロジェクト: sgml/tiddlyweb
def test_store_lock():
    """
    Make the sure the locking system throws the proper lock.
    """
    if type(store.storage) != Texter:
        py.test.skip('skipping this test for non-text store')

    write_lock('store/bags')
    py.test.raises(LockError, 'write_lock("store/bags")')

    write_lock('store/bags' + '/bagone/tiddlers/foobar')
    tiddler = Tiddler('foobar')
    tiddler.text = 'hello'
    tiddler.bag = u'bagone'
    py.test.raises(StoreLockError, 'store.put(tiddler)')
コード例 #3
0
    def tiddler_put(self, tiddler):
        tiddler_filename = self._tiddler_base_filename(tiddler)

        # the following section is copied almost verbatim from the text store
        # TODO: refactor the text store for granular reusability
        locked = 0
        lock_attempts = 0
        while not locked:
            try:
                lock_attempts = lock_attempts + 1
                write_lock(tiddler_filename)
                locked = 1
            except LockError, exc:
                if lock_attempts > 4:
                    raise StoreLockError(exc)
                time.sleep(.1)
コード例 #4
0
ファイル: text.py プロジェクト: angeluseve/tiddlyweb
 def tiddler_put(self, tiddler):
     """
     Write a tiddler into the store. We only write if
     the bag already exists. Bag creation is a
     separate action from writing to a bag.
     """
     tiddler_base_filename = self._tiddler_base_filename(tiddler)
     if not os.path.exists(tiddler_base_filename):
         os.mkdir(tiddler_base_filename)
     locked = 0
     lock_attempts = 0
     while (not locked):
         try:
             lock_attempts = lock_attempts + 1
             write_lock(tiddler_base_filename)
             locked = 1
         except LockError, exc:
             if lock_attempts > 4:
                 raise StoreLockError(exc)
             time.sleep(.1)
コード例 #5
0
ファイル: text.py プロジェクト: andrey013/tiddlyweb
    def tiddler_put(self, tiddler):
        """
        Write a :py:class:`tiddler <tiddlyweb.model.tiddler.Tiddler>`
        into the store. We only write if the tiddler's :py:class:`bag
        <tiddlyweb.model.bag.Bag>` already exists. Bag creation is a
        separate action.
        """
        tiddler_base_filename = self._tiddler_base_filename(tiddler)
        if not os.path.exists(tiddler_base_filename):
            try:
                os.mkdir(tiddler_base_filename)
            except OSError as exc:
                raise NoTiddlerError('unable to put tiddler: %s' % exc)

        locked = 0
        lock_attempts = 0
        while not locked:
            try:
                lock_attempts = lock_attempts + 1
                write_lock(tiddler_base_filename)
                locked = 1
            except LockError as exc:
                if lock_attempts > 4:
                    raise StoreLockError(exc)
                time.sleep(.1)

        # Protect against incoming tiddlers that have revision
        # set. Since we are putting a new one, we want the system
        # to calculate.
        tiddler.revision = None
        revision = self._tiddler_revision_filename(tiddler) + 1
        tiddler_filename = self._tiddler_full_filename(tiddler, revision)

        representation = self.serializer.serialization.tiddler_as(tiddler,
                omit_empty=True, omit_members=['creator'])
        write_utf8_file(tiddler_filename, representation)
        write_unlock(tiddler_base_filename)

        tiddler.revision = revision
コード例 #6
0
    def tiddler_put(self, tiddler):
        """
        Write a :py:class:`tiddler <tiddlyweb.model.tiddler.Tiddler>`
        into the store. We only write if the tiddler's :py:class:`bag
        <tiddlyweb.model.bag.Bag>` already exists. Bag creation is a
        separate action.
        """
        tiddler_base_filename = self._tiddler_base_filename(tiddler)
        if not os.path.exists(tiddler_base_filename):
            try:
                os.mkdir(tiddler_base_filename)
            except OSError as exc:
                raise NoTiddlerError('unable to put tiddler: %s' % exc)

        locked = 0
        lock_attempts = 0
        while not locked:
            try:
                lock_attempts = lock_attempts + 1
                write_lock(tiddler_base_filename)
                locked = 1
            except LockError as exc:
                if lock_attempts > 4:
                    raise StoreLockError(exc)
                time.sleep(.1)

        # Protect against incoming tiddlers that have revision
        # set. Since we are putting a new one, we want the system
        # to calculate.
        tiddler.revision = None
        revision = self._tiddler_revision_filename(tiddler) + 1
        tiddler_filename = self._tiddler_full_filename(tiddler, revision)

        representation = self.serializer.serialization.tiddler_as(tiddler,
                omit_empty=True, omit_members=['creator'])
        write_utf8_file(tiddler_filename, representation)
        write_unlock(tiddler_base_filename)

        tiddler.revision = revision
コード例 #7
0
ファイル: text.py プロジェクト: JazzDeben/tiddlyweb-xmobile
        the bag already exists. Bag creation is a
        separate action from writing to a bag.
        """
        tiddler_base_filename = self._tiddler_base_filename(tiddler)
        if not os.path.exists(tiddler_base_filename):
            try:
                os.mkdir(tiddler_base_filename)
            except OSError, exc:
                raise NoTiddlerError('unable to put tiddler: %s' % exc)

        locked = 0
        lock_attempts = 0
        while (not locked):
            try:
                lock_attempts = lock_attempts + 1
                write_lock(tiddler_base_filename)
                locked = 1
            except LockError, exc:
                if lock_attempts > 4:
                    raise StoreLockError(exc)
                time.sleep(.1)

        # Protect against incoming tiddlers that have revision
        # set. Since we are putting a new one, we want the system
        # to calculate.
        tiddler.revision = None
        revision = self._tiddler_revision_filename(tiddler) + 1
        tiddler_filename = self._tiddler_full_filename(tiddler, revision)

        self.serializer.object = tiddler
        write_utf8_file(tiddler_filename, self.serializer.to_string())
コード例 #8
0
        the bag already exists. Bag creation is a
        separate action from writing to a bag.
        """
        tiddler_base_filename = self._tiddler_base_filename(tiddler)
        if not os.path.exists(tiddler_base_filename):
            try:
                os.mkdir(tiddler_base_filename)
            except OSError, exc:
                raise NoTiddlerError('unable to put tiddler: %s' % exc)

        locked = 0
        lock_attempts = 0
        while (not locked):
            try:
                lock_attempts = lock_attempts + 1
                write_lock(tiddler_base_filename)
                locked = 1
            except LockError, exc:
                if lock_attempts > 4:
                    raise StoreLockError(exc)
                time.sleep(.1)

        # Protect against incoming tiddlers that have revision
        # set. Since we are putting a new one, we want the system
        # to calculate.
        tiddler.revision = None
        revision = self._tiddler_revision_filename(tiddler) + 1
        tiddler_filename = self._tiddler_full_filename(tiddler, revision)

        self.serializer.object = tiddler
        write_utf8_file(tiddler_filename, self.serializer.to_string())