Skip to content

Commit edfda1a

Browse files
committed
moved to a plain function rather than a decorator
1 parent 78e3262 commit edfda1a

File tree

3 files changed

+22
-18
lines changed

3 files changed

+22
-18
lines changed

src/natcap/invest/carbon.py

-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@
298298
_CARBON_NODATA = -1.0
299299

300300

301-
@utils.generate_metadata
302301
def execute(args):
303302
"""Carbon.
304303

src/natcap/invest/cli.py

+6
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,12 @@ def main(user_args=None):
468468
# written to stdout if this exception is uncaught. This is by
469469
# design.
470470
model_module.execute(parsed_datastack.args)
471+
suffix = utils.make_suffix_string(
472+
parsed_datastack.args, 'results_suffix')
473+
utils.generate_metadata(
474+
model_module.MODEL_SPEC['outputs'],
475+
parsed_datastack.args['workspace_dir'],
476+
suffix)
471477

472478
if args.subcommand == 'serve':
473479
ui_server.app.run(port=args.port)

src/natcap/invest/utils.py

+16-17
Original file line numberDiff line numberDiff line change
@@ -779,22 +779,22 @@ def write_metadata_file(datasource_path, spec):
779779
# mc.set_lineage(LINEAGE_STATEMENT)
780780

781781
if 'about' in spec:
782-
resource.set_abstract(spec['about'])
782+
resource.set_description(spec['about'])
783783
attr_spec = None
784784
if 'columns' in spec:
785785
attr_spec = spec['columns']
786786
if 'fields' in spec:
787787
attr_spec = spec['fields']
788788
if attr_spec:
789789
for key, value in attr_spec.items():
790-
abstract = value['about'] if 'about' in value else ''
790+
about = value['about'] if 'about' in value else ''
791791
if 'units' in value:
792792
units = spec_utils.format_unit(value['units'])
793793
else:
794794
units = ''
795795
try:
796796
resource.set_field_description(
797-
key, abstract=abstract, units=units)
797+
key, description=about, units=units)
798798
except KeyError as error:
799799
LOGGER.warning(error)
800800
if 'bands' in spec:
@@ -809,23 +809,22 @@ def write_metadata_file(datasource_path, spec):
809809
resource.write()
810810

811811

812-
def generate_metadata(execute_func):
813-
execute_func_args = inspect.getfullargspec(execute_func)
814-
model_module = importlib.import_module(execute_func.__module__)
815-
spec = model_module['MODEL_SPEC']['outputs']
816-
817-
workspace = execute_func_args.args['workspace_dir']
818-
results_suffix = execute_func_args.args.get('results_suffix', '')
819-
for filename, data in spec.items():
812+
def generate_metadata(output_spec, workspace, file_suffix):
813+
for filename, data in output_spec.items():
814+
# print(filename)
820815
if 'type' in data and data['type'] == 'directory':
821816
if 'taskgraph.db' in data['contents']:
822817
continue
818+
print(data['contents'])
823819
generate_metadata(
824-
data['contents'], os.path.join(workspace, filename))
820+
data['contents'], os.path.join(workspace, filename), file_suffix)
825821
else:
826822
pre, post = os.path.splitext(filename)
827-
full_path = os.path.join(workspace, pre+results_suffix+post)
828-
try:
829-
write_metadata_file(full_path, data)
830-
except ValueError as error:
831-
LOGGER.warning(error)
823+
full_path = os.path.join(workspace, pre+file_suffix+post)
824+
print(full_path)
825+
if os.path.exists(full_path):
826+
try:
827+
write_metadata_file(full_path, data)
828+
except ValueError as error:
829+
# Some unsupported file formats, e.g. html
830+
LOGGER.warning(error)

0 commit comments

Comments
 (0)