Skip to content

Commit cb6bc51

Browse files
committed
Try to fix warning about uncosed file descriptor
ResourceWarning: unclosed file <_io.TextIOWrapper name='_test_export/priority.csv' mode='r' encoding='UTF-8'>
1 parent 2c634de commit cb6bc51

File tree

1 file changed

+22
-25
lines changed

1 file changed

+22
-25
lines changed

roundup/admin.py

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,36 +1469,33 @@ class colon_separated(csv.excel):
14691469
cl = self.get_class(classname)
14701470

14711471
# ensure that the properties and the CSV file headings match
1472-
f = open(os.path.join(dir, file), 'r')
1473-
reader = csv.reader(f, colon_separated)
1474-
file_props = None
1475-
maxid = 1
1476-
# loop through the file and create a node for each entry
1477-
for n, r in enumerate(reader):
1478-
if file_props is None:
1479-
file_props = r
1480-
continue
1472+
with open(os.path.join(dir, file), 'r') as f:
1473+
reader = csv.reader(f, colon_separated)
1474+
file_props = None
1475+
maxid = 1
1476+
# loop through the file and create a node for each entry
1477+
for n, r in enumerate(reader):
1478+
if file_props is None:
1479+
file_props = r
1480+
continue
14811481

1482-
if self.verbose:
1483-
sys.stdout.write('\rImporting %s - %s' % (classname, n))
1484-
sys.stdout.flush()
1485-
1486-
# do the import and figure the current highest nodeid
1487-
nodeid = cl.import_list(file_props, r)
1488-
if hasattr(cl, 'import_files') and import_files:
1489-
cl.import_files(dir, nodeid)
1490-
maxid = max(maxid, int(nodeid))
1482+
if self.verbose:
1483+
sys.stdout.write('\rImporting %s - %s' % (classname, n))
1484+
sys.stdout.flush()
14911485

1492-
# (print to sys.stdout here to allow tests to squash it .. ugh)
1493-
print(file=sys.stdout)
1486+
# do the import and figure the current highest nodeid
1487+
nodeid = cl.import_list(file_props, r)
1488+
if hasattr(cl, 'import_files') and import_files:
1489+
cl.import_files(dir, nodeid)
1490+
maxid = max(maxid, int(nodeid))
14941491

1495-
f.close()
1492+
# (print to sys.stdout here to allow tests to squash it .. ugh)
1493+
print(file=sys.stdout)
14961494

14971495
# import the journals
1498-
f = open(os.path.join(args[0], classname + '-journals.csv'), 'r')
1499-
reader = csv.reader(f, colon_separated)
1500-
cl.import_journals(reader)
1501-
f.close()
1496+
with open(os.path.join(args[0], classname + '-journals.csv'), 'r') as f:
1497+
reader = csv.reader(f, colon_separated)
1498+
cl.import_journals(reader)
15021499

15031500
# (print to sys.stdout here to allow tests to squash it .. ugh)
15041501
print('setting', classname, maxid+1, file=sys.stdout)

0 commit comments

Comments
 (0)