|
1 | | -import os, json |
| 1 | +import os |
| 2 | +import json |
| 3 | +from pathlib import Path |
2 | 4 | from .utils import start_server, stop_server, lgr |
3 | 5 | from .jsonldutils import load_file, validate_data |
4 | 6 | from pathlib import Path |
|
7 | 9 | def validate_dir(directory, started=False, http_kwargs={}): |
8 | 10 | """Validate a directory containing JSONLD documents against the ReproSchema pydantic model. |
9 | 11 |
|
10 | | - .. warning:: This assumes every file in the directory can be read by a json parser. |
11 | | -
|
12 | 12 | Parameters |
13 | 13 | ---------- |
14 | 14 | directory: str |
@@ -36,17 +36,16 @@ def validate_dir(directory, started=False, http_kwargs={}): |
36 | 36 | else: |
37 | 37 | if "port" not in http_kwargs: |
38 | 38 | raise KeyError(f"HTTP server started, but port key is missing") |
39 | | - for full_file_name in Path(directory).rglob("*"): |
40 | | - # Skip files that should not be validated |
41 | | - if full_file_name.name in [".DS_Store"]: |
42 | | - continue |
43 | | - # checking if the path is a file and if the file can be a jsonld file |
44 | | - if full_file_name.is_file() and full_file_name.suffix in [ |
45 | | - "", |
46 | | - "js", |
47 | | - "json", |
48 | | - "jsonld", |
49 | | - ]: |
| 39 | + |
| 40 | + for root, _, files in os.walk(directory): |
| 41 | + for name in files: |
| 42 | + full_file_name = os.path.join(root, name) |
| 43 | + |
| 44 | + if Path(full_file_name).suffix not in [".jsonld", "json", "js", ""]: |
| 45 | + lgr.info(f"Skipping file {full_file_name}") |
| 46 | + continue |
| 47 | + |
| 48 | + lgr.debug(f"Validating file {full_file_name}") |
50 | 49 | try: |
51 | 50 | data = load_file(full_file_name, started=True, http_kwargs=http_kwargs) |
52 | 51 | if len(data) == 0: |
|
0 commit comments