Skip to content

Commit

Permalink
Merge branch 'release/v0.5.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Feb 16, 2016
2 parents d892bcb + 41747b8 commit 391f71d
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: python
python:
- '2.6'
- '2.7'
- '3.2'
- '3.3'
- '3.4'
- '3.5'
- 'pypy'
- 'pypy3'

Expand Down
11 changes: 8 additions & 3 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
install:
- echo "Installed Python versions:"
- dir c:\Python*

- C:\Python35\python -m pip install tox

build: false # Not a C# project, build stuff at the test step instead.

test_script:
- 'set TESTENVS=
py26,
py27,
py33,
py34
'
- C:\Python35\python -m tox -e "%TESTENVS%"
3 changes: 2 additions & 1 deletion portalocker/__init__.py
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -10,5 +10,6 @@
'LockException',
'Lock',
'AlreadyLocked',
'open_atomic',
]

4 changes: 2 additions & 2 deletions portalocker/portalocker.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
'''

import os


__all__ = [
'lock',
Expand All @@ -59,8 +61,6 @@
'LockException',
]

import os


class LockException(Exception):
# Error codes:
Expand Down
44 changes: 43 additions & 1 deletion portalocker/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@

import os
import time
import tempfile
import contextlib

from . import portalocker

DEFAULT_TIMEOUT = 5
Expand All @@ -9,13 +12,52 @@
__all__ = [
'Lock',
'AlreadyLocked',
'open_atomic',
]


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)
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__(
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
__package_name__ = 'portalocker'
__author__ = 'Rick van Hattem'
__email__ = 'wolph@wol.ph'
__version__ = '0.5.5'
__version__ = '0.5.6'
__description__ = '''Wraps the portalocker recipe for easy usage'''
__url__ = 'https://github.com/WoLpH/portalocker'

Expand All @@ -15,6 +15,7 @@


class PyTest(TestCommand):

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = ['tests']
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pypy,pypy3,py32,py33,py34
envlist = py26,py27,pypy,pypy3,py33,py34,py35
skip_missing_interpreters = True

[testenv]
Expand Down

0 comments on commit 391f71d

Please sign in to comment.