from trygvis.eda.cli.digikey_download_for_project import DigikeyDownloadForProjectCommand from trygvis.eda.cli.init import InitCommand from trygvis.eda.cli.kicad_import_project import KicadImportProjectCommand from trygvis.eda.cli.make_bom import MakeBomCommand from . import * # TODO: move all of the command classes to the file they delegate to. class AddToDb(CliCommand): def __init__(self): super().__init__("add-to-db", "Import RDF triplet file to the database") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("files", nargs='*') args = p.parse_args(argv) from trygvis.eda.cli import add_to_db add_to_db.run(args.files, args) class DbStats(CliCommand): def __init__(self): super().__init__("db-stats", "Show some statistics about the data in the database") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) args = p.parse_args(argv) from trygvis.eda.cli import db_stats db_stats.run(args) class DigikeyDownloadMetadata(CliCommand): def __init__(self): super().__init__("digikey-download-metadata", "Download category tree and attribute types and values from digikey.com") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("--output-dir", dest="output_dir", required=True) args = p.parse_args(argv) from trygvis.eda.cli import digikey_download_metadata digikey_download_metadata.run(args) class DigikeyDownloadAttributeTypesForCategory(CliCommand): def __init__(self): super().__init__("digikey-download-attribute-types-for-category", "Download the attribute types for a category from digikey.com") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("-c", "--category", required=True) p.add_argument("-s", "--sub-category", required=True) p.add_argument("-o", "--output", required=False) args = p.parse_args(argv) from trygvis.eda.cli import digikey_download_attribute_types_for_category digikey_download_attribute_types_for_category.run(args.category, args.sub_category, args.output, args) def main(): initialize() commands = [ AddToDb(), InitCommand(), DbStats(), MakeBomCommand(), KicadImportProjectCommand(), DigikeyDownloadForProjectCommand(), DigikeyDownloadAttributeTypesForCategory(), DigikeyDownloadMetadata() ] parser = argparse.ArgumentParser( description='EDA RFD tools', usage="""eda-rdf [] Available commands """ + "\n".join([" %-50s %s" % (cmd.key, cmd.description) for cmd in commands])) parser.add_argument('command', help='Subcommand to run', nargs='?') args = parser.parse_args(sys.argv[1:2]) cmd_args = sys.argv[2:] if args.command is None: print(parser.usage) print() sys.exit(1) for cmd in commands: if cmd.key == args.command: cmd.run(cmd_args) return print("Unknown command: %s" % args.command)