def cli(arguments): """cli - The main CLI argument parser. :param arguments: command line arguments, as parsed by docopt :type arguments: dict :return: None """ if arguments.get("list", False): if arguments["--project"] is None: pr.view_projects() else: proj_name = arguments.get("--project") dataset_names = pr.get_datasets(proj_name) for name in dataset_names: print name elif arguments.get("add", False): proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("PROJECT_SPECFILE") proj_spec = op.abspath(proj_spec) pr.add_project(proj_name, proj_spec) elif arguments.get("remove", False): proj_name = arguments.get("PROJECT_NAME") if arguments["--dataset"] is None: if not pr.remove_project(proj_name): print "Removing the project {0} failed.".format(proj_name) else: pr.remove_dataset(proj_name, arguments["--dataset"]) elif arguments.get("set-schema", False): try: proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("SCHEMA_FPATH") proj_spec = op.abspath(proj_spec) pr.set_schema_fpath(proj_name, proj_spec) except MissingProject: msg = """Project {} not found in the configuration. Please use $ semantic add to register the project.""".format( arguments.get("PROJECT_NAME") ) print msg elif arguments.get("set-specs", False): proj_name = arguments.get("PROJECT_NAME") dataset_name = arguments.get("--dataset") newspecs = {} if arguments.get("--path", False): newspecs["path"] = arguments.get("--path") if arguments.get("--dlm", False): newspecs["delimiter"] = arguments.get("--dlm") pr.set_schema_specs(proj_name, dataset_name, **newspecs) elif arguments.get("add-dataset", False): proj_name = arguments.get("--project") dataset_name = arguments.get("DATASET_NAME") specs = dict(path=arguments["--path"], delimiter=arguments["--dlm"]) pr.add_dataset(proj_name, dataset_name, specs) elif arguments.get("export", False): project = pr.Project(arguments.get("PROJECT_NAME")) project.export_dataset(arguments.get("--dataset"), outpath=arguments.get("OUTPATH"))
def cli(arguments): """cli - The main CLI argument parser. :param arguments: command line arguments, as parsed by docopt :type arguments: dict :return: None """ if arguments.get("list", False): if arguments['--project'] is None: pr.view_projects() else: proj_name = arguments.get('--project') dataset_names = pr.get_datasets(proj_name) for name in dataset_names: print name elif arguments.get("add", False): proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("PROJECT_SPECFILE") proj_spec = op.abspath(proj_spec) pr.add_project(proj_name, proj_spec) elif arguments.get("remove", False): proj_name = arguments.get("PROJECT_NAME") if arguments['--dataset'] is None: if not pr.remove_project(proj_name): print "The project {0} doesn't exist.".format(proj_name) else: pr.remove_dataset(proj_name, arguments['--dataset']) elif arguments.get("set-schema", False): try: proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("SCHEMA_FPATH") proj_spec = op.abspath(proj_spec) pr.set_schema_fpath(proj_name, proj_spec) except MissingProject: msg = """Project {} not found in the configuration. Please use $ semantic add to register the project.""".format(arguments.get("PROJECT_NAME")) print msg elif arguments.get("set-specs", False): proj_name = arguments.get("PROJECT_NAME") dataset_name = arguments.get("--dataset") newspecs = {} if arguments.get("--path", False): newspecs['path'] = arguments.get("--path") if arguments.get("--dlm", False): newspecs['delimiter'] = arguments.get("--dlm") pr.set_schema_specs(proj_name, dataset_name, **newspecs) elif arguments.get("add-dataset", False): proj_name = arguments.get('--project') dataset_name = arguments.get("DATASET_NAME") specs = dict(path=arguments["--path"], delimiter=arguments["--dlm"]) pr.add_dataset(proj_name, dataset_name, specs) elif arguments.get("export", False): project = pr.Project(arguments.get("PROJECT_NAME")) project.export_dataset(arguments.get("--dataset"), outpath=arguments.get("OUTPATH"))
def test_set_schema_fpath(self): """Test if programmatically setting a schema file to an existing project works.""" old_schempath = pr.get_default_specfile("pysemantic") try: self.assertTrue(pr.set_schema_fpath("pysemantic", "/foo/bar")) self.assertEqual(pr.get_default_specfile("pysemantic"), "/foo/bar") self.assertRaises(MissingProject, pr.set_schema_fpath, "foobar", "/foo/bar") finally: conf_path = pr.locate_config_file() parser = RawConfigParser() parser.read(conf_path) parser.remove_option("pysemantic", "specfile") parser.set("pysemantic", "specfile", old_schempath) with open(TEST_CONFIG_FILE_PATH, "w") as fileobj: parser.write(fileobj)