Missed 'open' statements
From: Dale Athanasias <dalegrind@hotmail.com> Mon, 25 Apr 2016 13:41:18 +1000 Subject: Missed 'open' statements Hi Sam, Here's a few files with missed 'open' statements: gramps/gen/filters/_filterlist.py gramps/plugins/export/exportftree.py gramps/plugins/database/bsddb_support/write.py And some older files which you probably left alone for a reason? windows/nonAIO/builder/build_GrampsWin32.py windows/nonAIO/check_gtk_install.py windows/nonAIO/builder/make_launcher.py windows/nonAIO/builder/check_gtk_install.py windows/nonAIO/nsis/gcheck.py Regards - Dale Re: Prefer with to open files https://github.com/gramps-project/gramps/pull/113
This commit is contained in:
parent
344f953c0b
commit
a9685a64ff
@ -118,7 +118,7 @@ class FilterList(object):
|
||||
return l.replace('"', '"')
|
||||
|
||||
def save(self):
|
||||
f = open(self.file, 'w', encoding='utf8')
|
||||
with open(self.file, 'w', encoding='utf8') as f:
|
||||
f.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")
|
||||
f.write('<filters>\n')
|
||||
for namespace in self.filter_namespaces:
|
||||
@ -142,4 +142,3 @@ class FilterList(object):
|
||||
f.write(' </filter>\n')
|
||||
f.write('</object>\n')
|
||||
f.write('</filters>\n')
|
||||
f.close()
|
||||
|
@ -458,8 +458,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
|
||||
|
||||
def __log_error(self):
|
||||
mypath = os.path.join(self.get_save_path(),DBRECOVFN)
|
||||
ofile = open(mypath, "w")
|
||||
ofile.close()
|
||||
with open(mypath, "w") as ofile:
|
||||
pass
|
||||
try:
|
||||
clear_lock_file(self.get_save_path())
|
||||
except:
|
||||
@ -2591,7 +2591,7 @@ def do_export(database):
|
||||
try:
|
||||
for (base, tbl) in build_tbl_map(database):
|
||||
backup_name = mk_tmp_name(database, base)
|
||||
backup_table = open(backup_name, 'wb')
|
||||
with open(backup_name, 'wb') as backup_table:
|
||||
|
||||
cursor = tbl.cursor()
|
||||
data = cursor.first()
|
||||
@ -2599,7 +2599,6 @@ def do_export(database):
|
||||
pickle.dump(data, backup_table, 2)
|
||||
data = cursor.next()
|
||||
cursor.close()
|
||||
backup_table.close()
|
||||
except (IOError,OSError):
|
||||
return
|
||||
|
||||
@ -2678,7 +2677,7 @@ def clear_lock_file(name):
|
||||
def write_lock_file(name):
|
||||
if not os.path.isdir(name):
|
||||
os.mkdir(name)
|
||||
f = open(os.path.join(name, DBLOCKFN), "w", encoding='utf8')
|
||||
with open(os.path.join(name, DBLOCKFN), "w", encoding='utf8') as f:
|
||||
if win():
|
||||
user = get_env_var('USERNAME')
|
||||
host = get_env_var('USERDOMAIN')
|
||||
@ -2700,7 +2699,6 @@ def write_lock_file(name):
|
||||
# Save only the username and host, so the massage can be
|
||||
# printed with correct locale in DbManager.py when a lock is found
|
||||
f.write(text)
|
||||
f.close()
|
||||
|
||||
def upgrade_researcher(owner_data):
|
||||
"""
|
||||
|
@ -121,7 +121,7 @@ class FtreeWriter(object):
|
||||
id_map[key] = n
|
||||
id_name[key] = get_name(pn, sn, count)
|
||||
|
||||
f = open(self.filename,"w")
|
||||
with open(self.filename,"w") as f:
|
||||
|
||||
for key in self.plist:
|
||||
self.update()
|
||||
@ -174,7 +174,6 @@ class FtreeWriter(object):
|
||||
f.write('%s;%s;%s;%s;%s;%s\n' % (name, father, mother, email, web,
|
||||
dates))
|
||||
|
||||
f.close()
|
||||
return True
|
||||
|
||||
def fdate(val):
|
||||
|
Loading…
x
Reference in New Issue
Block a user