From 00c4692b282a1143be0bea1bd5ee2e6dbb677bfe Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Wed, 16 Jan 2008 08:49:43 +0000 Subject: [PATCH] 2008-01-16 Benny Malengier * src/GrampsDbUtils/_GrampsDbWriteXML.py: import gzip only once svn: r9838 --- ChangeLog | 3 +++ src/GrampsDbUtils/_GrampsDbWriteXML.py | 31 +++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 592f77922..c9eb0e268 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2008-01-16 Benny Malengier + * src/GrampsDbUtils/_GrampsDbWriteXML.py: import gzip only once + 2008-01-16 Peter Landgren * man/Makefile.am: Swedish added (sv). * man/sv/gramps.1.in: Added Swedish man page (sv). diff --git a/src/GrampsDbUtils/_GrampsDbWriteXML.py b/src/GrampsDbUtils/_GrampsDbWriteXML.py index 967c017cd..74a1bced4 100644 --- a/src/GrampsDbUtils/_GrampsDbWriteXML.py +++ b/src/GrampsDbUtils/_GrampsDbWriteXML.py @@ -54,13 +54,19 @@ log = logging.getLogger(".WriteXML") import gen.lib from BasicUtils import UpdateCallback - -#from gen.db.dbconst import \ -# PERSON_KEY,FAMILY_KEY,SOURCE_KEY,EVENT_KEY,\ -# MEDIA_KEY,PLACE_KEY,REPOSITORY_KEY,NOTE_KEY -# from gen.db.exceptions import GrampsDbWriteFailure -#from gen.utils.longop import LongOpStatus + +#------------------------------------------------------------------------- +# +# Attempt to load the GZIP library. Some version of python do not seem +# to be compiled with this available. +# +#------------------------------------------------------------------------- +try: + import gzip + _gzip_ok = 1 +except: + _gzip_ok = 0 _xml_version = "1.2.0" @@ -103,11 +109,8 @@ class GrampsDbXmlWriter(UpdateCallback): """ UpdateCallback.__init__(self, callback) self.compress = compress - if self.compress: - try: - import gzip - except: - self.compress = False + if not _gzip_ok: + self.compress = False self.db = db self.strip_photos = strip_photos self.version = version @@ -141,8 +144,7 @@ class GrampsDbXmlWriter(UpdateCallback): self.fileroot = os.path.dirname(filename) try: - if self.compress: - import gzip + if self.compress and _gzip_ok: try: g = gzip.open(filename,"wb") except: @@ -166,8 +168,7 @@ class GrampsDbXmlWriter(UpdateCallback): Write the database to the specified file handle. """ - if self.compress: - import gzip + if self.compress and _gzip_ok: try: g = gzip.GzipFile(mode="wb",fileobj=handle) except: