Commit 1bb75bdf authored by Pierre Paleo's avatar Pierre Paleo
Browse files

Add validator CLI took

parent e182a53f
...@@ -43,11 +43,20 @@ def nabu_validate(fname): ...@@ -43,11 +43,20 @@ def nabu_validate(fname):
validator.remove_unused_radios() validator.remove_unused_radios()
if __name__ == "__main__":
def main():
args = parse_params_values( args = parse_params_values(
ValidateConfig, ValidateConfig,
parser_description="Validate a Nabu configuration file." parser_description="Validate a Nabu configuration file."
) )
fname = args["input_file"] fname = args["input_file"]
nabu_validate(fname) try:
nabu_validate(fname)
except Exception as exc:
print("Error while checking %s:" % fname)
print(exc)
exit(-1)
print("Configuration file %s is valid" % fname) print("Configuration file %s is valid" % fname)
if __name__ == "__main__":
main()
...@@ -14,7 +14,7 @@ nabu_config = { ...@@ -14,7 +14,7 @@ nabu_config = {
"default": "/path/to/my/dataset", "default": "/path/to/my/dataset",
"help": "Dataset folder location", "help": "Dataset folder location",
"hst_key": None, "hst_key": None,
"validator": directory_location_validator, "validator": dataset_location_validator,
}, },
"file_prefix": { "file_prefix": {
"default": "my_dataset_", "default": "my_dataset_",
...@@ -105,10 +105,10 @@ nabu_config = { ...@@ -105,10 +105,10 @@ nabu_config = {
"validator": float_validator, "validator": float_validator,
}, },
"paganin_lmicron": { "paganin_lmicron": {
"default": "1", "default": "",
"help": "Alternatively to delta/beta, the parameter 'Lmicron' of PyHST can be specified.\nL^2 = pi * wavelength * distance * delta/beta", "help": "Alternatively to delta/beta, the parameter 'Lmicron' of PyHST can be specified.\nL^2 = pi * wavelength * distance * delta/beta",
"hst_key": "paganin_lmicron", "hst_key": "paganin_lmicron",
"validator": float_validator, "validator": optional_float_validator,
}, },
"paganin_marge": { "paganin_marge": {
"default": "50", "default": "50",
...@@ -174,12 +174,12 @@ nabu_config = { ...@@ -174,12 +174,12 @@ nabu_config = {
}, },
"padding_type": { "padding_type": {
"default": "zeros", "default": "zeros",
"help": "Padding type for FBP. Available are: zeros, edge, mirror", "help": "Padding type for FBP. Available are: zeros, edge",
"hst_key": None, "hst_key": None,
"validator": padding_mode_validator, "validator": padding_mode_validator,
}, },
"enable_halftomo": { "enable_halftomo": {
"default": "1", "default": "0",
"help": "\nParameters related to half-acquisition tomography\n-------------------------------------------------\nWhether to enable half-acquisition", "help": "\nParameters related to half-acquisition tomography\n-------------------------------------------------\nWhether to enable half-acquisition",
"hst_key": None, "hst_key": None,
"validator": boolean_validator, "validator": boolean_validator,
......
...@@ -111,6 +111,13 @@ def directory_location_validator(location): ...@@ -111,6 +111,13 @@ def directory_location_validator(location):
assert path.isdir(location), "location must be a directory" assert path.isdir(location), "location must be a directory"
return location return location
@validator
def dataset_location_validator(location):
if not(path.isdir(location)):
assert path.isfile(location) and path.splitext(location)[-1] in [".h5", ".hdf5"], "Dataset location must be a directory or a HDF5 file"
return location
@validator @validator
def directory_writeable_validator(location): def directory_writeable_validator(location):
assert os.access(location, os.W_OK), "Directory must be writeable" assert os.access(location, os.W_OK), "Directory must be writeable"
......
...@@ -108,6 +108,7 @@ def setup_package(): ...@@ -108,6 +108,7 @@ def setup_package():
'console_scripts': [ 'console_scripts': [
"nabu-test=nabu.tests:nabu_test", "nabu-test=nabu.tests:nabu_test",
"nabu-config=nabu.resources.cli.bootstrap:bootstrap", "nabu-config=nabu.resources.cli.bootstrap:bootstrap",
"nabu-validate=nabu.resources.cli.validate:main",
], ],
}, },
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment