[Python-modules-commits] [portalocker] 01/01: Import portalocker_0.5.7.orig.tar.gz

Josué Ortega noahfx-guest at moszumanska.debian.org
Sat Mar 12 18:37:17 UTC 2016


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

noahfx-guest pushed a commit to branch upstream
in repository portalocker.

commit 2c284cbc7438a276c2663c1bfc53b79b3673d270
Author: Josue Ortega <josueortega at debian.org.gt>
Date:   Sat Mar 12 12:30:51 2016 -0600

    Import portalocker_0.5.7.orig.tar.gz
---
 CHANGELOG                        | 11 ++++++---
 PKG-INFO                         |  2 +-
 portalocker.egg-info/PKG-INFO    |  2 +-
 portalocker.egg-info/SOURCES.txt |  1 -
 portalocker.egg-info/pbr.json    |  1 -
 portalocker/__init__.py          |  3 ++-
 portalocker/portalocker.py       |  4 ++--
 portalocker/utils.py             | 49 +++++++++++++++++++++++++++++++++++++++-
 setup.py                         |  3 ++-
 9 files changed, 64 insertions(+), 12 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 59c5a08..221562e 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,13 +12,18 @@
 
 0.4:
 
- * Fixing a few bugs, added coveralls support, switched to py.test and added 100% test coverage.
+ * Fixing a few bugs, added coveralls support, switched to py.test and added
+   100% test coverage.
 
     - Fixing exception thrown when fail_when_locked is true
     - Fixing exception "Lock object has no attribute '_release_lock'" when
-      fail_when_locked is true due to the call to Lock._release_lock() which fails
-      because _release_lock is not defined.
+      fail_when_locked is true due to the call to Lock._release_lock() which
+      fails because _release_lock is not defined.
 
 0.5:
 
  * Python 3 support
+
+0.6:
+
+ * Added msvcrt support for Windows
diff --git a/PKG-INFO b/PKG-INFO
index e23a4ad..f851b96 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: portalocker
-Version: 0.5.5
+Version: 0.5.7
 Summary: Wraps the portalocker recipe for easy usage
 Home-page: https://github.com/WoLpH/portalocker
 Author: Rick van Hattem
diff --git a/portalocker.egg-info/PKG-INFO b/portalocker.egg-info/PKG-INFO
index e23a4ad..f851b96 100644
--- a/portalocker.egg-info/PKG-INFO
+++ b/portalocker.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: portalocker
-Version: 0.5.5
+Version: 0.5.7
 Summary: Wraps the portalocker recipe for easy usage
 Home-page: https://github.com/WoLpH/portalocker
 Author: Rick van Hattem
diff --git a/portalocker.egg-info/SOURCES.txt b/portalocker.egg-info/SOURCES.txt
index f2195af..52a2440 100644
--- a/portalocker.egg-info/SOURCES.txt
+++ b/portalocker.egg-info/SOURCES.txt
@@ -11,5 +11,4 @@ portalocker.egg-info/PKG-INFO
 portalocker.egg-info/SOURCES.txt
 portalocker.egg-info/dependency_links.txt
 portalocker.egg-info/not-zip-safe
-portalocker.egg-info/pbr.json
 portalocker.egg-info/top_level.txt
\ No newline at end of file
diff --git a/portalocker.egg-info/pbr.json b/portalocker.egg-info/pbr.json
deleted file mode 100644
index 750d589..0000000
--- a/portalocker.egg-info/pbr.json
+++ /dev/null
@@ -1 +0,0 @@
-{"is_release": false, "git_version": "12a1dc5"}
\ No newline at end of file
diff --git a/portalocker/__init__.py b/portalocker/__init__.py
index b3bb54b..dae2991 100644
--- a/portalocker/__init__.py
+++ b/portalocker/__init__.py
@@ -1,5 +1,5 @@
 from .portalocker import lock, unlock, LOCK_EX, LOCK_SH, LOCK_NB, LockException
-from .utils import Lock, AlreadyLocked
+from .utils import Lock, AlreadyLocked, open_atomic
 
 __all__ = [
     'lock',
@@ -10,5 +10,6 @@ __all__ = [
     'LockException',
     'Lock',
     'AlreadyLocked',
+    'open_atomic',
 ]
 
diff --git a/portalocker/portalocker.py b/portalocker/portalocker.py
index ddf1662..eff991b 100644
--- a/portalocker/portalocker.py
+++ b/portalocker/portalocker.py
@@ -49,6 +49,8 @@ Version: $Id: portalocker.py 5474 2008-05-16 20:53:50Z lowell $
 
 '''
 
+import os
+
 
 __all__ = [
     'lock',
@@ -59,8 +61,6 @@ __all__ = [
     'LockException',
 ]
 
-import os
-
 
 class LockException(Exception):
     # Error codes:
diff --git a/portalocker/utils.py b/portalocker/utils.py
index e5766ea..825804b 100644
--- a/portalocker/utils.py
+++ b/portalocker/utils.py
@@ -1,5 +1,8 @@
-
+import os
 import time
+import tempfile
+import contextlib
+
 from . import portalocker
 
 DEFAULT_TIMEOUT = 5
@@ -9,6 +12,7 @@ LOCK_METHOD = portalocker.LOCK_EX | portalocker.LOCK_NB
 __all__ = [
     'Lock',
     'AlreadyLocked',
+    'open_atomic',
 ]
 
 
@@ -16,6 +20,49 @@ class AlreadyLocked(Exception):
     pass
 
 
+ at contextlib.contextmanager
+def open_atomic(filename, binary=True):
+    '''Open a file for atomic writing. Instead of locking this method allows
+    you to write the entire file and move it to the actual location. Note that
+    is still not atomic in all cases and won't work on existing files.
+
+    http://docs.python.org/library/os.html#os.rename
+
+    >>> filename = 'test_file.txt'
+    >>> if os.path.exists(filename):
+    ...     os.remove(filename)
+
+    >>> with open_atomic(filename) as fh:
+    ...     fh.write('test')
+    >>> assert os.path.exists(filename)
+    >>> os.remove(filename)
+
+    '''
+    assert not os.path.exists(filename), '%r exists' % filename
+    path, name = os.path.split(filename)
+
+    # Create the parent directory if it doesn't exist
+    if path and not os.path.isdir(path):  # pragma: no cover
+        os.makedirs(path)
+
+    temp_fh = tempfile.NamedTemporaryFile(
+        mode=binary and 'wb' or 'w',
+        dir=path,
+        delete=False,
+    )
+    yield temp_fh
+    temp_fh.flush()
+    os.fsync(temp_fh.fileno())
+    temp_fh.close()
+    try:
+        os.rename(temp_fh.name, filename)
+    finally:
+        try:
+            os.remove(temp_fh.name)
+        except Exception:
+            pass
+
+
 class Lock(object):
 
     def __init__(
diff --git a/setup.py b/setup.py
index 2ec104a..63b377a 100644
--- a/setup.py
+++ b/setup.py
@@ -5,7 +5,7 @@ from setuptools.command.test import test as TestCommand
 __package_name__ = 'portalocker'
 __author__ = 'Rick van Hattem'
 __email__ = 'wolph at wol.ph'
-__version__ = '0.5.5'
+__version__ = '0.5.7'
 __description__ = '''Wraps the portalocker recipe for easy usage'''
 __url__ = 'https://github.com/WoLpH/portalocker'
 
@@ -15,6 +15,7 @@ if sys.version_info >= (3, 0):
 
 
 class PyTest(TestCommand):
+
     def finalize_options(self):
         TestCommand.finalize_options(self)
         self.test_args = ['tests']

-- 
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