#!/usr/bin/env python import sys import argparse import logging from DataVaultGenerator.Components import ErrorCollection from DataVaultGenerator.Model import Model from DataVaultGenerator import __version__ from rich import print from rich.table import Table from rich.panel import Panel from rich import box MIN_PYTHON = (3, 9) def main(argv=None): if argv is None: argv = sys.argv[1:] if sys.version_info < MIN_PYTHON: sys.exit("Python %s.%s or later is required.\n" % MIN_PYTHON) parser = argparse.ArgumentParser(description='DataVaultGenerator') parser.add_argument('config', help='Path of Config file') parser.add_argument('-l','--loglevel', default='INFO', help='Loglevel: CRITICAL, ERROR, WARNING, INFO, DEBUG (default: %(default)s)') parser.add_argument('-lf','--logfile', default='generator.log', help='Logfilename (default: %(default)s)') parser.add_argument('-v', '--validate', dest='validateonly', help='Switch to run validation only', action='store_true') parser.add_argument('--validateschema', dest='validateschemaonly', help='Switch to run validation of schema only',action='store_true') parser.add_argument('--novalidate', help='Switch to skip validation',action='store_true') parser.add_argument('--synch', help='Synchronize changed files to the target',action='store_true') parser.add_argument('--fullsynch', help='Synchronize all files to the target',action='store_true') parser.add_argument('--runhooks', help='Run pre- and post-hooks',action='store_true') parser.add_argument('--snapshot', help='Create Snapshotfile',action='store_true') args = parser.parse_args() title = """\ _____ _ __ __ _ _ _____ _ | __ \ | | \ \ / / | | | / ____| | | | | | | __ _| |_ __ \ \ / /_ _ _ _| | |_ | | __ ___ _ __ ___ _ __ __ _| |_ ___ _ __ | | | |/ _` | __/ _` \ \/ / _` | | | | | __| | | |_ |/ _ \ '_ \ / _ \ '__/ _` | __/ _ \| '__| | |__| | (_| | || (_| |\ / (_| | |_| | | |_ | |__| | __/ | | | __/ | | (_| | || (_) | | |_____/ \__,_|\__\__,_| \/ \__,_|\__,_|_|\__| \_____|\___|_| |_|\___|_| \__,_|\__\___/|_| """ print(Panel(title, expand=False, box=box.HORIZONTALS)) table = Table(show_header =False, show_edge=False ) table.add_column("Prop", justify="right", style="white", no_wrap=True) table.add_column("Value", style="white") table.add_row("Version", __version__) table.add_row("Config", args.config) print(table) print('') numeric_level = getattr(logging, args.loglevel.upper(), None) logging.basicConfig(filename=args.logfile, filemode='w', level=numeric_level, format='%(asctime)s %(levelname)s: %(message)s', datefmt='%Y-%m-%d %I:%M:%S') logging.info(title) dm = Model() #FIXME: boilerplate nutzen, um objekt per cli zu erstellen: dvgen add hub my_hub /path/tofile #with open('hub_boiler.yaml', 'w') as the_file: # the_file.write(dm.get_boilerplate('hub')) dm.load_config(args.config) if args.runhooks: dm.run_model_hooks('pre_hooks') if args.validateschemaonly: errorcount = dm.validate_entities_schemas() print(errorcount, "Errors found during validation of entity-schemas") exit(0) dm.load_entities() dm.load_mappings() if not args.novalidate: overallerrorcount = 0 errors = dm.validate_entities() if errors.count != 0: overallerrorcount += errors.count print(errors.count, "Errors found during validation of Entities") if overallerrorcount != 0: exit(2) errors = dm.validate_mappings() if errors.count != 0: overallerrorcount += errors.count print(errors.count, "Errors found during validation of Mappings") if overallerrorcount != 0: exit(2) if not args.validateonly: dm.build_dag() dm.capture_changes_before() dm.render_entity_templates() dm.render_model_templates() if args.snapshot: dm.create_snapshot('snapshot.yaml') dm.capture_changes_after() #FIXME: Wenn ein modeltemplate nicht verfügbar ist, erscheint es im Log aber nicht auf der Konsole und die nachfolgenden Zeilen werden nicht ausgeführt if args.synch or args.fullsynch: dm.synch(args.fullsynch) print('') dm.display_changes() print('') if args.runhooks: dm.run_model_hooks('post_hooks') if __name__ == "__main__": main()