|
6 | 6 |
|
7 | 7 | class ModelData(object):
|
8 | 8 | def __init__(self, client, model_manifest_path):
|
9 |
| - self.manifest_path = model_manifest_path |
10 |
| - self.manifest_freeze_path = "{}.freeze".format(self.manifest_path) |
11 |
| - self.manifest_data = get_manifest(self.manifest_freeze_path, self.manifest_path) |
| 9 | + self.manifest_reg_path = model_manifest_path |
| 10 | + self.manifest_frozen_path = "{}.freeze".format(self.manifest_reg_path) |
| 11 | + self.manifest_data = self.get_manifest() |
12 | 12 | self.client = client
|
13 | 13 | self.models = {}
|
14 | 14 | self.usr_key = "__user__"
|
| 15 | + self.using_frozen = True |
15 | 16 |
|
16 | 17 | def __getitem__(self, key):
|
17 | 18 | return getattr(self, self.usr_key + key)
|
@@ -78,28 +79,32 @@ def find_optional_model(self, file_name):
|
78 | 79 | with self.client.file(source_uri).getFile() as f:
|
79 | 80 | local_data_path = f.name
|
80 | 81 | real_hash = md5_for_file(local_data_path)
|
81 |
| - if real_hash != expected_hash and fail_on_tamper: |
82 |
| - raise Exception("Model File Mismatch for " + file_name + |
83 |
| - "\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash) |
| 82 | + if self.using_frozen: |
| 83 | + if real_hash != expected_hash and fail_on_tamper: |
| 84 | + raise Exception("Model File Mismatch for " + file_name + |
| 85 | + "\nexpected hash: " + expected_hash + "\nreal hash: " + real_hash) |
| 86 | + else: |
| 87 | + self.models[file_name] = FileData(real_hash, local_data_path) |
84 | 88 | else:
|
85 | 89 | self.models[file_name] = FileData(real_hash, local_data_path)
|
86 | 90 |
|
87 | 91 |
|
88 |
| -def get_manifest(manifest_frozen_path, manifest_reg_path): |
89 |
| - if os.path.exists(manifest_frozen_path): |
90 |
| - with open(manifest_frozen_path) as f: |
91 |
| - manifest_data = json.load(f) |
92 |
| - if check_lock(manifest_data): |
| 92 | + def get_manifest(self): |
| 93 | + if os.path.exists(self.manifest_frozen_path): |
| 94 | + with open(self.manifest_frozen_path) as f: |
| 95 | + manifest_data = json.load(f) |
| 96 | + if check_lock(manifest_data): |
| 97 | + return manifest_data |
| 98 | + else: |
| 99 | + raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your " |
| 100 | + "algorithm's freeze file.") |
| 101 | + elif os.path.exists(self.manifest_reg_path): |
| 102 | + with open(self.manifest_reg_path) as f: |
| 103 | + manifest_data = json.load(f) |
| 104 | + self.using_frozen = False |
93 | 105 | return manifest_data
|
94 | 106 | else:
|
95 |
| - raise Exception("Manifest FreezeFile Tamper Detected; please use the CLI and 'algo freeze' to rebuild your " |
96 |
| - "algorithm's freeze file.") |
97 |
| - elif os.path.exists(manifest_reg_path): |
98 |
| - with open(manifest_reg_path) as f: |
99 |
| - manifest_data = json.load(f) |
100 |
| - return manifest_data |
101 |
| - else: |
102 |
| - return None |
| 107 | + return None |
103 | 108 |
|
104 | 109 |
|
105 | 110 | def check_lock(manifest_data):
|
|
0 commit comments