Coverage for attribuutit/cli.py: 90.32%
48 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 00:44:25 +00:00
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-08 00:44:25 +00:00
1"""Scan a tree of files and extract attributes of the underlying vector or raster data."""
3import json
4import pathlib
5import sys
7import typer
9import attribuutit.shp as shp
10import attribuutit.tif as tif
11import attribuutit.vpf as vpf
12from attribuutit import VERSION
14app = typer.Typer()
17@app.command()
18def version() -> int:
19 """Report the version."""
20 typer.echo(VERSION)
21 return 0
24@app.command()
25def eject(name: str) -> int:
26 """Eject an example configuration in JSON format with stem equal to name."""
27 typer.echo(f'This will eject an example configuration as {name}.json')
28 return 0
31@app.command()
32def scan(name: str, dry_run: bool = False) -> int:
33 """Scan the file system based on the configuration given in name.json and persist the report eventually."""
34 if not dry_run:
35 typer.echo(f'Real run changing the world following the configuration {name}.json - later ...')
36 return 2
38 typer.echo(f'Dry run exposing the plan of execution when following the configuration {name}.json - later ...')
39 return 0
42@app.command()
43def inspect(path_str: str, dry_run: bool = False) -> int:
44 """Inspect the file at path and persist the report eventually."""
45 if not dry_run:
46 typer.echo(f'Real run inspecting file at {path_str}')
47 path = pathlib.Path(path_str)
48 suffix = path.suffix
49 if suffix == '.shp':
50 error, shape = shp.load(path)
51 if not error: 51 ↛ 54line 51 didn't jump to line 54 because the condition on line 51 was always true
52 print(shp.summary(shape))
53 else:
54 print(error)
55 elif suffix == '.tif':
56 error, bitmap = tif.load(path)
57 if not error: 57 ↛ 60line 57 didn't jump to line 60 because the condition on line 57 was always true
58 print(tif.summary(bitmap))
59 else:
60 print(error)
61 else:
62 with open(path, 'rb') as source:
63 vpf_artifact = vpf.Table(str(path), (b for b in source.read()))
64 print(json.dumps(vpf_artifact.table, indent=2))
65 return 0
67 typer.echo(f'Dry run exposing the plan of execution when inspecting file at {path_str}')
68 return 0
71if __name__ == '__main__': 71 ↛ 72line 71 didn't jump to line 72 because the condition on line 71 was never true
72 sys.exit(app())