A version of touch() for Python3.2

This commit is contained in:
Doug Blank 2016-01-28 16:53:06 -05:00
parent f144b4c425
commit de07b9d4f1

View File

@ -34,9 +34,7 @@ import shutil
import bisect
import ast
from operator import itemgetter
import platform
PYVERSION = platform.python_version_tuple()
import sys
#------------------------------------------------------------------------
#
@ -76,16 +74,14 @@ SIGBASE = ('person', 'family', 'source', 'event', 'media',
def touch(fname, mode=0o666, dir_fd=None, **kwargs):
## After http://stackoverflow.com/questions/1158076/implement-touch-using-python
flags = os.O_CREAT | os.O_APPEND
if PYVERSION >= ("3", "3", "0"):
opened = os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)
if sys.version_info < (3, 3, 0):
with open(fname, 'a'):
os.utime(fname, times)
else:
opened = os.open(fname, flags, mode)
with os.fdopen(opened) as f:
os.utime(f.fileno() if os.utime in os.supports_fd else fname,
dir_fd=None if os.supports_fd else dir_fd, **kwargs)
flags = os.O_CREAT | os.O_APPEND
with os.fdopen(os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd)) as f:
os.utime(f.fileno() if os.utime in os.supports_fd else fname,
dir_fd=None if os.supports_fd else dir_fd, **kwargs)
class DbGenericUndo(DbUndo):
def __init__(self, grampsdb, path):