Commit 2c284cbc authored by Josue Ortega's avatar Josue Ortega

Import portalocker_0.5.7.orig.tar.gz

parent de6ab2fe
......@@ -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
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
......
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
......
......@@ -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
{"is_release": false, "git_version": "12a1dc5"}
\ No newline at end of file
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',
]
......@@ -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:
......
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
@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__(
......
......@@ -5,7 +5,7 @@ from setuptools.command.test import test as TestCommand
__package_name__ = 'portalocker'
__author__ = 'Rick van Hattem'
__email__ = 'wolph@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']
......
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