Changeset 96ec45c in rattail
- Timestamp:
- 08/01/2022 09:23:26 PM (6 months ago)
- Branches:
- master
- Children:
- 5812923
- Parents:
- d006a6d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rattail/commands/core.py
rd006a6d r96ec45c 593 593 594 594 595 class Dump(Subcommand):596 """597 Do a simple data dump.598 """599 600 name = 'dump'601 description = "Dump data to file."602 603 def add_parser_args(self, parser):604 parser.add_argument(605 '--output', '-o', metavar='FILE',606 help="Optional path to output file. If none is specified, "607 "data will be written to standard output.")608 parser.add_argument(609 'model', help="Model whose data will be dumped.")610 611 def get_model(self):612 """613 Returns the module which contains all relevant data models.614 615 By default this returns ``rattail.db.model``, but this method may be616 overridden in derived commands to add support for extra data models.617 """618 from rattail.db import model619 return model620 621 def run(self, args):622 from rattail.db import Session623 from rattail.db.dump import dump_data624 625 model = self.get_model()626 if hasattr(model, args.model):627 cls = getattr(model, args.model)628 else:629 self.stderr.write("Unknown model: {0}\n".format(args.model))630 sys.exit(1)631 632 progress = None633 if self.show_progress: # pragma no cover634 progress = ConsoleProgress635 636 if args.output:637 output = open(args.output, 'wb')638 else:639 output = self.stdout640 641 session = Session()642 dump_data(session, cls, output, progress=progress)643 session.close()644 645 if output is not self.stdout:646 output.close()647 648 649 595 class FileMonitorCommand(Subcommand): 650 596 """
Note: See TracChangeset
for help on using the changeset viewer.