1+ import types
12import json
3+ import subprocess
24from functools import partial
35from collections import defaultdict
46from itertools import chain
79
810import pdal
911
12+ PDAL_DRIVERS_JSON = subprocess .run (["pdal" , "--drivers" , "--showjson" ], capture_output = True ).stdout
13+ PDAL_DRIVERS = json .loads (PDAL_DRIVERS_JSON )
14+ modules = set ([e ["name" ].split ("." )[0 ] for e in PDAL_DRIVERS ])
15+
16+
1017DEFAULT_STAGE_PARAMS = defaultdict (dict )
1118DEFAULT_STAGE_PARAMS .update ({
1219# TODO: add stage specific default configurations
1320})
1421
22+
1523class StageSpec (object ):
1624 def __init__ (self , prefix , ** kwargs ):
1725 self .prefix = prefix
18- key = "." .join ([self .prefix , kwargs .get ("type" , "" )])
19- self .spec = DEFAULT_STAGE_PARAMS [key ].copy ()
26+ self . key = "." .join ([self .prefix , kwargs .get ("type" , "" )])
27+ self .spec = DEFAULT_STAGE_PARAMS [self . key ].copy ()
2028 self .spec .update (kwargs )
21- self .spec ["type" ] = key
29+ self .spec ["type" ] = self . key
2230 # NOTE: special case to support reading files without passing an explicit reader
2331 if (self .prefix == "readers" ) and kwargs .get ("type" ) == "auto" :
2432 del self .spec ["type" ]
@@ -30,6 +38,7 @@ def pipeline(self):
3038 return output
3139
3240 def __getattr__ (self , name ):
41+ assert name in dir (self ), "Invalid or unsupported stage"
3342 return partial (self .__class__ , self .prefix , type = name )
3443
3544 def __str__ (self ):
@@ -38,6 +47,10 @@ def __str__(self):
3847 def __add__ (self , other ):
3948 return self .pipeline + other
4049
50+ def __dir__ (self ):
51+ extra_keys = [e ["name" ][len (self .key ):] for e in PDAL_DRIVERS if e ["name" ].startswith (self .key )]
52+ return super ().__dir__ () + [e for e in extra_keys if len (e ) > 0 ]
53+
4154 def execute (self ):
4255 return self .pipeline .execute ()
4356
0 commit comments