Commit 374bc558 authored by Josué Ortega's avatar Josué Ortega

Import portalocker_1.0.1.orig.tar.gz

parent e4b25c8e
Metadata-Version: 1.1
Name: portalocker
Version: 1.0.0
Version: 1.0.1
Summary: Wraps the portalocker recipe for easy usage
Home-page: https://github.com/WoLpH/portalocker
Author: Rick van Hattem
......@@ -27,8 +27,14 @@ Description: ############################################
Portalocker is a library to provide an easy API to file locking.
Originally created as a Python Recipe by Jonathan Feinberg and Lowell Alleman
http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/
An important detail to note is that on Linux and Unix systems the locks are
advisory by default. By specifying the `-o mand` option to the mount command it
is possible to enable mandatory file locking on Linux. This is generally not
recommended however. For more information about the subject:
- https://en.wikipedia.org/wiki/File_locking
- http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
- https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
The module is currently maintained by Rick van Hattem <Wolph@wol.ph>.
The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
......
......@@ -19,8 +19,14 @@ Overview
Portalocker is a library to provide an easy API to file locking.
Originally created as a Python Recipe by Jonathan Feinberg and Lowell Alleman
http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/
An important detail to note is that on Linux and Unix systems the locks are
advisory by default. By specifying the `-o mand` option to the mount command it
is possible to enable mandatory file locking on Linux. This is generally not
recommended however. For more information about the subject:
- https://en.wikipedia.org/wiki/File_locking
- http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
- https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
The module is currently maintained by Rick van Hattem <Wolph@wol.ph>.
The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
......
Metadata-Version: 1.1
Name: portalocker
Version: 1.0.0
Version: 1.0.1
Summary: Wraps the portalocker recipe for easy usage
Home-page: https://github.com/WoLpH/portalocker
Author: Rick van Hattem
......@@ -27,8 +27,14 @@ Description: ############################################
Portalocker is a library to provide an easy API to file locking.
Originally created as a Python Recipe by Jonathan Feinberg and Lowell Alleman
http://code.activestate.com/recipes/65203-portalocker-cross-platform-posixnt-api-for-flock-s/
An important detail to note is that on Linux and Unix systems the locks are
advisory by default. By specifying the `-o mand` option to the mount command it
is possible to enable mandatory file locking on Linux. This is generally not
recommended however. For more information about the subject:
- https://en.wikipedia.org/wiki/File_locking
- http://stackoverflow.com/questions/39292051/portalocker-does-not-seem-to-lock
- https://stackoverflow.com/questions/12062466/mandatory-file-lock-on-linux
The module is currently maintained by Rick van Hattem <Wolph@wol.ph>.
The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
......
......@@ -13,5 +13,7 @@ portalocker.egg-info/PKG-INFO
portalocker.egg-info/SOURCES.txt
portalocker.egg-info/dependency_links.txt
portalocker.egg-info/top_level.txt
tests/conftest.py
tests/temporary_file_lock.py
tests/test_combined.py
tests/tests.py
\ No newline at end of file
__package_name__ = 'portalocker'
__author__ = 'Rick van Hattem'
__email__ = 'wolph@wol.ph'
__version__ = '1.0.0'
__version__ = '1.0.1'
__description__ = '''Wraps the portalocker recipe for easy usage'''
__url__ = 'https://github.com/WoLpH/portalocker'
......@@ -48,6 +48,7 @@ LOCK_UN = constants.LOCK_UN
#: Locking utility class to automatically handle opening with timeouts and
#: context wrappers
Lock = utils.Lock
TemporaryFileLock = utils.TemporaryFileLock
open_atomic = utils.open_atomic
__all__ = [
......
import os
import time
import atexit
import tempfile
import contextlib
from . import exceptions
......@@ -64,7 +65,7 @@ class Lock(object):
def __init__(
self, filename, mode='a', timeout=DEFAULT_TIMEOUT,
check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=True,
check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=False,
flags=LOCK_METHOD):
'''Lock manager with build-in timeout
......@@ -193,3 +194,23 @@ class Lock(object):
def __exit__(self, type_, value, tb):
self.release()
def __delete__(self, instance): # pragma: no cover
instance.release()
class TemporaryFileLock(Lock):
def __init__(self, filename='.lock', timeout=DEFAULT_TIMEOUT,
check_interval=DEFAULT_CHECK_INTERVAL, fail_when_locked=True,
flags=LOCK_METHOD):
Lock.__init__(self, filename=filename, mode='w', timeout=timeout,
check_interval=check_interval,
fail_when_locked=fail_when_locked, flags=flags)
atexit.register(self.release)
def release(self):
Lock.release(self)
if os.path.isfile(self.filename): # pragma: no branch
os.unlink(self.filename)
import py
import pytest
@pytest.fixture
def tmpfile(tmpdir_factory):
tmpdir = tmpdir_factory.mktemp('temp')
filename = tmpdir.join('tmpfile')
yield str(filename)
try:
filename.remove(ignore_errors=True)
except (py.error.EBUSY, py.error.ENOENT):
pass
import os
import portalocker
def test_temporary_file_lock(tmpfile):
with portalocker.TemporaryFileLock(tmpfile):
pass
assert not os.path.isfile(tmpfile)
lock = portalocker.TemporaryFileLock(tmpfile)
lock.acquire()
del lock
from __future__ import print_function
from __future__ import with_statement
import py
import pytest
import portalocker
@pytest.fixture
def tmpfile(tmpdir_factory):
tmpdir = tmpdir_factory.mktemp('temp')
filename = tmpdir.join('tmpfile')
yield str(filename)
try:
filename.remove(ignore_errors=True)
except py.error.EBUSY:
pass
def test_exceptions(tmpfile):
# Open the file 2 times
a = open(tmpfile, 'a')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment