Convert a few more opens to use the with CM
This commit is contained in:
parent
05dcde4c8e
commit
1e81d9d11f
@ -555,7 +555,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
|
||||
def __make_zip_backup(self, dirname):
|
||||
import zipfile
|
||||
# In Windows resrved characters is "<>:"/\|?*"
|
||||
# In Windows reserved characters is "<>:"/\|?*"
|
||||
reserved_char = r':,<>"/\|?* '
|
||||
replace_char = "-__________"
|
||||
title = self.get_dbname()
|
||||
@ -569,11 +569,10 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
dotgramps_path = os.path.dirname(grampsdb_path)
|
||||
zipname = title + time.strftime("_%Y-%m-%d_%H-%M-%S") + ".zip"
|
||||
zippath = os.path.join(dotgramps_path, zipname)
|
||||
myzip = zipfile.ZipFile(zippath, 'w')
|
||||
for filename in os.listdir(dirname):
|
||||
pathname = os.path.join(dirname, filename)
|
||||
myzip.write(pathname, os.path.join(db_code, filename))
|
||||
myzip.close()
|
||||
with zipfile.ZipFile(zippath, 'w') as myzip:
|
||||
for filename in os.listdir(dirname):
|
||||
pathname = os.path.join(dirname, filename)
|
||||
myzip.write(pathname, os.path.join(db_code, filename))
|
||||
_LOG.warning("If upgrade and loading the Family Tree works, you can "
|
||||
"delete the zip file at %s" %
|
||||
zippath)
|
||||
|
@ -339,9 +339,8 @@ class LineParser:
|
||||
if GZIP_OK:
|
||||
use_gzip = 1
|
||||
try:
|
||||
f = gzip.open(filename, "r")
|
||||
f.read(1)
|
||||
f.close()
|
||||
with gzip.open(filename, "r") as f:
|
||||
f.read(1)
|
||||
except IOError as msg:
|
||||
use_gzip = 0
|
||||
except ValueError as msg:
|
||||
@ -419,9 +418,8 @@ class ImportOpenFileContextManager:
|
||||
if GZIP_OK:
|
||||
use_gzip = True
|
||||
try:
|
||||
ofile = gzip.open(filename, "r")
|
||||
ofile.read(1)
|
||||
ofile.close()
|
||||
with gzip.open(filename, "r") as ofile:
|
||||
ofile.read(1)
|
||||
except IOError as msg:
|
||||
use_gzip = False
|
||||
except ValueError as msg:
|
||||
|
Loading…
Reference in New Issue
Block a user