55# SPDX-FileContributor: Michael Meinel
66
77import argparse
8- import json
9- import sys
108
119from pydantic import BaseModel
1210
1311from hermes .commands .base import HermesCommand , HermesPlugin
14- from hermes .model .context import HermesHarvestContext , CodeMetaContext
12+ from hermes .model .api import SoftwareMetadata
13+ from hermes .model .context_manager import HermesContext
14+ from hermes .model .error import HermesContextError
15+ from hermes .model .merge .container import ld_merge_dict
1516
1617
1718class HermesProcessPlugin (HermesPlugin ):
@@ -33,42 +34,27 @@ class HermesProcessCommand(HermesCommand):
3334
3435 def __call__ (self , args : argparse .Namespace ) -> None :
3536 self .args = args
36- ctx = CodeMetaContext ()
37-
38- if not (ctx .hermes_dir / "harvest" ).exists ():
39- self .log .error ("You must run the harvest command before process" )
40- sys .exit (1 )
37+ ctx = HermesContext ()
38+ merged_doc = ld_merge_dict ([{}])
4139
4240 # Get all harvesters
4341 harvester_names = self .root_settings .harvest .sources
44- harvester_names .reverse () # Switch order for priority handling
4542
43+ ctx .prepare_step ('harvest' )
4644 for harvester in harvester_names :
4745 self .log .info ("## Process data from %s" , harvester )
48-
49- harvest_context = HermesHarvestContext (ctx , harvester , {})
5046 try :
51- harvest_context . load_cache ( )
52- # when the harvest step ran, but there is no cache file, this is a serious flaw
53- except FileNotFoundError :
54- self .log . warning ( "No output data from harvester %s found, skipping" , harvester )
47+ metadata = SoftwareMetadata . load_from_cache ( ctx , harvester )
48+ except HermesContextError as e :
49+ self . log . error ( "Error while trying to load data from harvest plugin '%s': %s" , harvester , e )
50+ self .errors . append ( e )
5551 continue
56-
57- ctx .merge_from (harvest_context )
58- ctx .merge_contexts_from (harvest_context )
59-
60- if ctx ._errors :
61- self .log .error ('Errors during merge' )
62- self .errors .extend (ctx ._errors )
63-
64- for ep , error in ctx ._errors :
65- self .log .info (" - %s: %s" , ep .name , error )
66-
67- tags_path = ctx .get_cache ('process' , 'tags' , create = True )
68- with tags_path .open ('w' ) as tags_file :
69- json .dump (ctx .tags , tags_file , indent = 2 )
70-
71- ctx .prepare_codemeta ()
72-
73- with open (ctx .get_cache ("process" , ctx .hermes_name , create = True ), 'w' ) as codemeta_file :
74- json .dump (ctx ._data , codemeta_file , indent = 2 )
52+ merged_doc .update (metadata )
53+ ctx .finalize_step ("harvest" )
54+
55+ ctx .prepare_step ("process" )
56+ with ctx ["result" ] as result_ctx :
57+ result_ctx ["codemeta" ] = merged_doc .compact ()
58+ result_ctx ["context" ] = {"@context" : merged_doc .full_context }
59+ result_ctx ["expanded" ] = merged_doc .ld_value
60+ ctx .finalize_step ("process" )
0 commit comments