atomicWrite Py3 support, full stack logging

This commit is contained in:
shortcutme 2019-03-15 23:50:33 +01:00
parent f5bc26e9fe
commit cd9a965057
No known key found for this signature in database
GPG key ID: 5B63BAE6CB9613AE

View file

@ -25,11 +25,11 @@ def atomicWrite(dest, content, mode="wb"):
os.rename(dest + "-tmpnew", dest) os.rename(dest + "-tmpnew", dest)
os.unlink(dest + "-tmpold") # Remove old file os.unlink(dest + "-tmpold") # Remove old file
return True return True
except Exception, err: except Exception as err:
from Debug import Debug from Debug import Debug
logging.error( logging.error(
"File %s write failed: %s, reverting..." % "File %s write failed: %s, (%s) reverting..." %
(dest, Debug.formatException(err)) (dest, Debug.formatException(err), Debug.formatStack())
) )
if os.path.isfile(dest + "-tmpold") and not os.path.isfile(dest): if os.path.isfile(dest + "-tmpold") and not os.path.isfile(dest):
os.rename(dest + "-tmpold", dest) os.rename(dest + "-tmpold", dest)