11import os
22import json
33import hashlib
4+ from adk .manifest .classes import FileData
45
56
6- class ManifestData (object ):
7+ class Manifest (object ):
78 def __init__ (self , client , model_manifest_path ):
89 self .manifest_lock_path = model_manifest_path
910 self .manifest_data = get_manifest (self .manifest_lock_path )
@@ -19,51 +20,48 @@ def available(self):
1920 def initialize (self ):
2021 if self .client is None :
2122 raise Exception ("Client was not defined, please define a Client when using Model Manifests." )
22- for required_file in self .manifest_data ['required_models ' ]:
23+ for required_file in self .manifest_data ['required_files ' ]:
2324 name = required_file ['name' ]
2425 if name in self .models :
2526 raise Exception ("Duplicate 'name' detected. \n "
2627 + name + " was found to be used by more than one data file, please rename." )
27- self .models [name ] = {}
2828 expected_hash = required_file ['md5_checksum' ]
29- with self .client .file (required_file ['data_api_path ' ]).getFile () as f :
29+ with self .client .file (required_file ['source_uri ' ]).getFile () as f :
3030 local_data_path = f .name
3131 real_hash = md5_for_file (local_data_path )
3232 if real_hash != expected_hash and required_file ['fail_on_tamper' ]:
3333 raise Exception ("Model File Mismatch for " + name +
3434 "\n expected hash: " + expected_hash + "\n real hash: " + real_hash )
3535 else :
36- self .models [name ]["md5_checksum" ] = real_hash
37- self .models [name ]['model_path' ] = local_data_path
36+ self .models [name ] = FileData (real_hash , local_data_path )
3837
3938 def get_model (self , model_name ):
4039 if model_name in self .models :
41- return self .models [model_name ][ 'model_path' ]
42- elif len ([optional for optional in self .manifest_data ['optional_models ' ] if
40+ return self .models [model_name ]. file_path
41+ elif len ([optional for optional in self .manifest_data ['optional_files ' ] if
4342 optional ['name' ] == model_name ]) > 0 :
4443 self .find_optional_model (model_name )
45- return self .models [model_name ][ 'model_path' ]
44+ return self .models [model_name ]. file_path
4645 else :
4746 raise Exception ("model name " + model_name + " not found in manifest" )
4847
49- def find_optional_model (self , model_name ):
48+ def find_optional_model (self , file_name ):
5049
51- found_models = [optional for optional in self .manifest_data ['optional_models ' ] if
52- optional ['name' ] == model_name ]
50+ found_models = [optional for optional in self .manifest_data ['optional_files ' ] if
51+ optional ['name' ] == file_name ]
5352 if len (found_models ) == 0 :
54- raise Exception ("model with name '" + model_name + "' not found in model manifest." )
53+ raise Exception ("file with name '" + file_name + "' not found in model manifest." )
5554 model_info = found_models [0 ]
56- self .models [model_name ] = {}
55+ self .models [file_name ] = {}
5756 expected_hash = model_info ['md5_checksum' ]
58- with self .client .file (model_info ['data_api_path ' ]).getFile () as f :
57+ with self .client .file (model_info ['source_uri ' ]).getFile () as f :
5958 local_data_path = f .name
6059 real_hash = md5_for_file (local_data_path )
6160 if real_hash != expected_hash and model_info ['fail_on_tamper' ]:
62- raise Exception ("Model File Mismatch for " + model_name +
61+ raise Exception ("Model File Mismatch for " + file_name +
6362 "\n expected hash: " + expected_hash + "\n real hash: " + real_hash )
6463 else :
65- self .models [model_name ]["md5_checksum" ] = real_hash
66- self .models [model_name ]['model_path' ] = local_data_path
64+ self .models [file_name ] = FileData (real_hash , local_data_path )
6765
6866
6967def get_manifest (manifest_path ):
0 commit comments