[Python-modules-commits] [portalocker] 01/03: Import portalocker_1.0.1.orig.tar.gz

Josué Ortega josue at moszumanska.debian.org
Sun Jan 15 15:26:53 UTC 2017


This is an automated email from the git hooks/post-receive script.

josue pushed a commit to branch master
in repository portalocker.

commit 374bc558dbb3d5829422dafdd20fae5c36f5ed0e
Author: Josue Ortega <josue at debian.org>
Date:   Sun Jan 15 09:20:25 2017 -0600

    Import portalocker_1.0.1.orig.tar.gz
---
 PKG-INFO                         | 12 +++++++++---
 README.rst                       | 10 ++++++++--
 portalocker.egg-info/PKG-INFO    | 12 +++++++++---
 portalocker.egg-info/SOURCES.txt |  2 ++
 portalocker/__about__.py         |  2 +-
 portalocker/__init__.py          |  1 +
 portalocker/utils.py             | 23 ++++++++++++++++++++++-
 tests/conftest.py                | 14 ++++++++++++++
 tests/temporary_file_lock.py     | 14 ++++++++++++++
 tests/tests.py                   | 12 ------------
 10 files changed, 80 insertions(+), 22 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index d754298..bb23deb 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 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 at wol.ph>.
         The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
diff --git a/README.rst b/README.rst
index 93c3318..92717e5 100644
--- a/README.rst
+++ b/README.rst
@@ -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 at wol.ph>.
 The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
diff --git a/portalocker.egg-info/PKG-INFO b/portalocker.egg-info/PKG-INFO
index d754298..bb23deb 100644
--- a/portalocker.egg-info/PKG-INFO
+++ b/portalocker.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 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 at wol.ph>.
         The project resides at https://github.com/WoLpH/portalocker . Bugs and feature
diff --git a/portalocker.egg-info/SOURCES.txt b/portalocker.egg-info/SOURCES.txt
index 5d756f3..bc743a6 100644
--- a/portalocker.egg-info/SOURCES.txt
+++ b/portalocker.egg-info/SOURCES.txt
@@ -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
diff --git a/portalocker/__about__.py b/portalocker/__about__.py
index 27bdd4c..61d1a88 100644
--- a/portalocker/__about__.py
+++ b/portalocker/__about__.py
@@ -1,7 +1,7 @@
 __package_name__ = 'portalocker'
 __author__ = 'Rick van Hattem'
 __email__ = 'wolph at wol.ph'
-__version__ = '1.0.0'
+__version__ = '1.0.1'
 __description__ = '''Wraps the portalocker recipe for easy usage'''
 __url__ = 'https://github.com/WoLpH/portalocker'
 
diff --git a/portalocker/__init__.py b/portalocker/__init__.py
index 91c7a8c..e75e32a 100644
--- a/portalocker/__init__.py
+++ b/portalocker/__init__.py
@@ -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__ = [
diff --git a/portalocker/utils.py b/portalocker/utils.py
index cc1f1aa..1007d7f 100644
--- a/portalocker/utils.py
+++ b/portalocker/utils.py
@@ -1,5 +1,6 @@
 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)
diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 0000000..a92117e
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,14 @@
+import py
+import pytest
+
+
+ at 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
+
diff --git a/tests/temporary_file_lock.py b/tests/temporary_file_lock.py
new file mode 100644
index 0000000..b250bad
--- /dev/null
+++ b/tests/temporary_file_lock.py
@@ -0,0 +1,14 @@
+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
+
diff --git a/tests/tests.py b/tests/tests.py
index f5da680..6ac40c1 100644
--- a/tests/tests.py
+++ b/tests/tests.py
@@ -1,22 +1,10 @@
 from __future__ import print_function
 from __future__ import with_statement
 
-import py
 import pytest
 import portalocker
 
 
- at 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')

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/portalocker.git



More information about the Python-modules-commits mailing list