import argparse import sys import trygvis.eda.cli as cli class CliCommand(object): def __init__(self, key, description): self.key = key self.description = description 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() class KicadBomToTtl(CliCommand): def __init__(self): super().__init__("kicad-bom-to-ttl", "Create RDF triples from a KiCAD BOM.xml file") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("-o", "--output", required=False) p.add_argument("-i", "--input", required=False) args = p.parse_args(argv) from trygvis.eda.cli import kicad_bom_to_ttl kicad_bom_to_ttl.run(args) class DigikeyDownloadForSchematic(CliCommand): def __init__(self): super().__init__("digikey-download-for-schematic", "Download missing data from digikey.com") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("--schematic", required=True) args = p.parse_args(argv) from trygvis.eda.cli import digikey_download_for_schematic digikey_download_for_schematic.run(args.schematic, 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) class MakeBom(CliCommand): def __init__(self): super().__init__("make-bom", "Create a BOM for a project with all info for each part.") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("--schematic", required=True) args = p.parse_args(argv) from trygvis.eda.cli import make_bom make_bom.run(args.schematic) class Init(CliCommand): def __init__(self): super().__init__("init", "Initialize a EDA-RFD database") def run(self, argv): p = argparse.ArgumentParser(prog=self.key, description=self.description) p.add_argument("--database-url", dest="database_url") args = p.parse_args(argv) from trygvis.eda.cli import init init.run(args) def main(): cli.initialize() commands = [ AddToDb(), Init(), DbStats(), MakeBom(), KicadBomToTtl(), DigikeyDownloadForSchematic(), 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)