|
From: Mercurial C. <th...@in...> - 2026-05-12 21:11:57
|
# HG changeset patch
# User John Rouillard <ro...@ie...>
# Date 1778511100 14400
# Mon May 11 10:51:40 2026 -0400
# Node ID ef5c2df157a8395cad8c332f1901d169d99e6ea4
# Parent ac7e280a9783b1d34cdbd01d5000d8f775437cbe
bug: fix ResourceWarning unclosed scandir.
Even though roundup-admin import is not a long running process, fix
the ResourceWarning.
diff -r ac7e280a9783 -r ef5c2df157a8 roundup/admin.py
--- a/roundup/admin.py Mon May 11 10:47:00 2026 -0400
+++ b/roundup/admin.py Mon May 11 10:51:40 2026 -0400
@@ -1280,28 +1280,29 @@
delimiter = ':'
# import all the files
- for dir_entry in os.scandir(import_dir):
- filename = dir_entry.name
- classname, ext = os.path.splitext(filename)
- # we only care about CSV files
- if ext != '.csv' or classname.endswith('-journals'):
- continue
-
- cl = self.get_class(classname)
-
- maxid = self.import_class(dir_entry.path, colon_separated, cl,
- import_dir, import_files)
-
- # import the journals
- with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f:
- reader = csv.reader(f, colon_separated, lineterminator='\n')
- cl.import_journals(reader)
-
- # (print to sys.stdout here to allow tests to squash it .. ugh)
- print('setting', classname, maxid + 1, file=sys.stdout)
-
- # set the id counter
- self.db.setid(classname, str(maxid + 1))
+ with os.scandir(import_dir) as dirs:
+ for dir_entry in dirs:
+ filename = dir_entry.name
+ classname, ext = os.path.splitext(filename)
+ # we only care about CSV files
+ if ext != '.csv' or classname.endswith('-journals'):
+ continue
+
+ cl = self.get_class(classname)
+
+ maxid = self.import_class(dir_entry.path, colon_separated, cl,
+ import_dir, import_files)
+
+ # import the journals
+ with open(os.path.join(import_dir, classname + '-journals.csv'), 'r') as f:
+ reader = csv.reader(f, colon_separated, lineterminator='\n')
+ cl.import_journals(reader)
+
+ # (print to sys.stdout here to allow tests to squash it .. ugh)
+ print('setting', classname, maxid + 1, file=sys.stdout)
+
+ # set the id counter
+ self.db.setid(classname, str(maxid + 1))
self.db_uncommitted = True
return 0
|