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