diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-07 14:00:46 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-01-07 14:00:46 +0100 |
commit | 0958273a71dd19c2a90471a182ccc5b90b14e5b4 (patch) | |
tree | 8e33385ca9df94b80ce9b1f8ba06438b807f137a /trygvis/eda/cli/init.py | |
parent | 5d7fc9c4b14536006f2435b1379887f95937e096 (diff) | |
download | eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.gz eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.bz2 eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.tar.xz eda-rdf-0958273a71dd19c2a90471a182ccc5b90b14e5b4.zip |
Renaming 'schematic' to 'project'.
Renaming 'kicad-bom-to-ttl' to 'kicad-import-project'.
Renaming 'digikey-download-for-schematic' to 'digikey-download-for-project'.
Splitting out the Export xml file code into its own module.
init: putting project.url and project.file in config.ini.
init: putting db.update-url in config.ini if given on the command line.
kicad-import-project: by default, assume that the user want to update local database, optionally write the ttl file to disk.
cli.write_graph: create any missing parent directories.
Diffstat (limited to 'trygvis/eda/cli/init.py')
-rwxr-xr-x | trygvis/eda/cli/init.py | 70 |
1 files changed, 64 insertions, 6 deletions
diff --git a/trygvis/eda/cli/init.py b/trygvis/eda/cli/init.py index 1ea9079..fbc7d04 100755 --- a/trygvis/eda/cli/init.py +++ b/trygvis/eda/cli/init.py @@ -1,23 +1,79 @@ -from os.path import isfile, exists, isdir +import argparse +from os.path import isdir +from os import mkdir +from sys import exit +import glob +import configparser from trygvis.eda import cli -import configparser +from trygvis.eda.cli import CliException, CliCommand +from trygvis.eda.kicad.export import * + + +class InitCommand(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") + p.add_argument("--database-update-url", dest="database_update_url") + p.add_argument("--project-file", dest="project_file", required=False) + p.add_argument("--project-url", dest="project_url", required=False) + args = p.parse_args(argv) + + run(args) + + +def load_from_kicad_project(args, config: configparser.ConfigParser): + project_file = args.project_file + + if project_file is None: + for path in glob.glob('*.pro'): + if project_file is not None: + raise CliException("Found more than one project file in directly, use --project to specify which one " + "you want") + + project_file = path -import os -import sys + if project_file is None: + raise CliException("Could not find any KiCAD projects (.pro files) in the current directly.") + + project_url = args.project_url + + if project_url is None: + project_url = os.path.basename(project_file) + (project_url, _) = os.path.splitext(project_url) + + if not project_url.startswith('http'): + project_url = quote_plus(project_url) + project_url = kicad_rdf.KICAD_BOARD[project_url] + + cli.info("EDA-RDF project initialized with Project url: %s" % project_url) + + config['project']['file'] = project_file + config['project']['url'] = project_url def run(args): try: - os.mkdir('.eda-rdf') + mkdir('.eda-rdf') except FileExistsError: if isdir('.eda-rdf'): cli.info('Already initialized') else: cli.info('.eda-rdf exists, but is not a directory') - sys.exit(1) + exit(1) config = configparser.ConfigParser() + + # KiCAD is all that is supported for now + config['project'] = { + "type": "kicad" + } + + load_from_kicad_project(args, config) + config['db'] = { "type": "local" } @@ -25,5 +81,7 @@ def run(args): if args.database_url is not None: config["db"]["type"] = "sparql" config["db"]["url"] = args.database_url + if args.database_update_url is not None: + config["db"]["update-url"] = args.database_update_url cli.write_config(config) |