Mercurial > p > roundup > code
comparison roundup/admin.py @ 6208:74784dd531c8
Add importtables roundup-admin command.
I am surprised this doesn't exist. It's the dual of exporttables.
Output of exporttables can't be imported by import, so I am not sure
why it's useful. I can't find the sourceforge ticket that is
referenced in the creation of exporttables.
I considered trapping the error generated when import can't find file
content, but that's not a great idea as it can mask an
invalid/incorrect export and the loss of data associated with it.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 28 Jun 2020 20:16:26 -0400 |
| parents | 39513b36ca59 |
| children | 95183d73ac64 |
comparison
equal
deleted
inserted
replaced
| 6207:8a21f8ba3065 | 6208:74784dd531c8 |
|---|---|
| 1343 colon-separated-value files that are placed in the nominated | 1343 colon-separated-value files that are placed in the nominated |
| 1344 destination directory. | 1344 destination directory. |
| 1345 """ | 1345 """ |
| 1346 return self.do_export(args, export_files=False) | 1346 return self.do_export(args, export_files=False) |
| 1347 | 1347 |
| 1348 def do_import(self, args): | 1348 def do_import(self, args, import_files=True): |
| 1349 ''"""Usage: import import_dir | 1349 ''"""Usage: import import_dir |
| 1350 Import a database from the directory containing CSV files, | 1350 Import a database from the directory containing CSV files, |
| 1351 two per class to import. | 1351 two per class to import. |
| 1352 | 1352 |
| 1353 The files used in the import are: | 1353 The files used in the import are: |
| 1401 sys.stdout.write('\rImporting %s - %s' % (classname, n)) | 1401 sys.stdout.write('\rImporting %s - %s' % (classname, n)) |
| 1402 sys.stdout.flush() | 1402 sys.stdout.flush() |
| 1403 | 1403 |
| 1404 # do the import and figure the current highest nodeid | 1404 # do the import and figure the current highest nodeid |
| 1405 nodeid = cl.import_list(file_props, r) | 1405 nodeid = cl.import_list(file_props, r) |
| 1406 if hasattr(cl, 'import_files'): | 1406 if hasattr(cl, 'import_files') and import_files: |
| 1407 cl.import_files(dir, nodeid) | 1407 cl.import_files(dir, nodeid) |
| 1408 maxid = max(maxid, int(nodeid)) | 1408 maxid = max(maxid, int(nodeid)) |
| 1409 | 1409 |
| 1410 # (print to sys.stdout here to allow tests to squash it .. ugh) | 1410 # (print to sys.stdout here to allow tests to squash it .. ugh) |
| 1411 print(file=sys.stdout) | 1411 print(file=sys.stdout) |
| 1424 # set the id counter | 1424 # set the id counter |
| 1425 self.db.setid(classname, str(maxid+1)) | 1425 self.db.setid(classname, str(maxid+1)) |
| 1426 | 1426 |
| 1427 self.db_uncommitted = True | 1427 self.db_uncommitted = True |
| 1428 return 0 | 1428 return 0 |
| 1429 | |
| 1430 def do_importtables(self, args): | |
| 1431 ''"""Usage: importtables export_dir | |
| 1432 | |
| 1433 This imports the database tables exported using exporttables. | |
| 1434 """ | |
| 1435 return self.do_import(args, import_files=False) | |
| 1429 | 1436 |
| 1430 def do_pack(self, args): | 1437 def do_pack(self, args): |
| 1431 ''"""Usage: pack period | date | 1438 ''"""Usage: pack period | date |
| 1432 | 1439 |
| 1433 Remove journal entries older than a period of time specified or | 1440 Remove journal entries older than a period of time specified or |
