From 4b565fe7bcbf04484b455244393a63ff70266d64 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 28 Jan 2016 07:50:49 -0500 Subject: [PATCH] Attempt to make Python 3.2 work with fd --- gramps/gen/db/generic.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/gramps/gen/db/generic.py b/gramps/gen/db/generic.py index 6a7b8788a..71111bdd9 100644 --- a/gramps/gen/db/generic.py +++ b/gramps/gen/db/generic.py @@ -34,6 +34,9 @@ import shutil import bisect import ast from operator import itemgetter +import platform + +PYVERSION = platform.python.python_version_tuple() #------------------------------------------------------------------------ # @@ -74,8 +77,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 - 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, + + if PYVERSION >= ("3", "3", "0"): + opened = os.open(fname, flags=flags, mode=mode, dir_fd=dir_fd) + else: + opened = os.open(fname, flags, mode) + + with os.fdopen() as f: + os.utime(f.fileno(opened) if os.utime in os.supports_fd else fname, dir_fd=None if os.supports_fd else dir_fd, **kwargs) class DbGenericUndo(DbUndo):