Mercurial > p > roundup > code
comparison roundup/admin.py @ 6818:b5e465646a7c
Try to fix warning about uncosed file descriptor
ResourceWarning: unclosed file <_io.TextIOWrapper
name='_test_export/priority.csv' mode='r' encoding='UTF-8'>
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 04 Aug 2022 17:15:09 -0400 |
| parents | 00fe67eb8a91 |
| children | f924af12ef50 |
comparison
equal
deleted
inserted
replaced
| 6817:38b73f7495f8 | 6818:b5e465646a7c |
|---|---|
| 1467 continue | 1467 continue |
| 1468 | 1468 |
| 1469 cl = self.get_class(classname) | 1469 cl = self.get_class(classname) |
| 1470 | 1470 |
| 1471 # ensure that the properties and the CSV file headings match | 1471 # ensure that the properties and the CSV file headings match |
| 1472 f = open(os.path.join(dir, file), 'r') | 1472 with open(os.path.join(dir, file), 'r') as f: |
| 1473 reader = csv.reader(f, colon_separated) | 1473 reader = csv.reader(f, colon_separated) |
| 1474 file_props = None | 1474 file_props = None |
| 1475 maxid = 1 | 1475 maxid = 1 |
| 1476 # loop through the file and create a node for each entry | 1476 # loop through the file and create a node for each entry |
| 1477 for n, r in enumerate(reader): | 1477 for n, r in enumerate(reader): |
| 1478 if file_props is None: | 1478 if file_props is None: |
| 1479 file_props = r | 1479 file_props = r |
| 1480 continue | 1480 continue |
| 1481 | 1481 |
| 1482 if self.verbose: | 1482 if self.verbose: |
| 1483 sys.stdout.write('\rImporting %s - %s' % (classname, n)) | 1483 sys.stdout.write('\rImporting %s - %s' % (classname, n)) |
| 1484 sys.stdout.flush() | 1484 sys.stdout.flush() |
| 1485 | 1485 |
| 1486 # do the import and figure the current highest nodeid | 1486 # do the import and figure the current highest nodeid |
| 1487 nodeid = cl.import_list(file_props, r) | 1487 nodeid = cl.import_list(file_props, r) |
| 1488 if hasattr(cl, 'import_files') and import_files: | 1488 if hasattr(cl, 'import_files') and import_files: |
| 1489 cl.import_files(dir, nodeid) | 1489 cl.import_files(dir, nodeid) |
| 1490 maxid = max(maxid, int(nodeid)) | 1490 maxid = max(maxid, int(nodeid)) |
| 1491 | 1491 |
| 1492 # (print to sys.stdout here to allow tests to squash it .. ugh) | 1492 # (print to sys.stdout here to allow tests to squash it .. ugh) |
| 1493 print(file=sys.stdout) | 1493 print(file=sys.stdout) |
| 1494 | |
| 1495 f.close() | |
| 1496 | 1494 |
| 1497 # import the journals | 1495 # import the journals |
| 1498 f = open(os.path.join(args[0], classname + '-journals.csv'), 'r') | 1496 with open(os.path.join(args[0], classname + '-journals.csv'), 'r') as f: |
| 1499 reader = csv.reader(f, colon_separated) | 1497 reader = csv.reader(f, colon_separated) |
| 1500 cl.import_journals(reader) | 1498 cl.import_journals(reader) |
| 1501 f.close() | |
| 1502 | 1499 |
| 1503 # (print to sys.stdout here to allow tests to squash it .. ugh) | 1500 # (print to sys.stdout here to allow tests to squash it .. ugh) |
| 1504 print('setting', classname, maxid+1, file=sys.stdout) | 1501 print('setting', classname, maxid+1, file=sys.stdout) |
| 1505 | 1502 |
| 1506 # set the id counter | 1503 # set the id counter |
