1717 "F" : "debug" ,
1818}
1919
20- FILENAME_RE = re .compile (r"^(?P<name>[^_]+)_(?P<version>[^_]+)_(?P< buildid>[A-Za-z0-9]+)\.magic$" )
20+ FILENAME_RE = re .compile (r"^(?P<name>[^_]+)_(?P<buildid>[A-Za-z0-9]+)\.magic$" )
2121
2222def sha256_file (path : Path ) -> str :
2323 h = hashlib .sha256 ()
@@ -27,20 +27,20 @@ def sha256_file(path: Path) -> str:
2727 return h .hexdigest ()
2828
2929def parse_build_type (build_id : str ) -> str :
30- if len ( build_id ) >= 3 :
31- letter = build_id [2 ].upper ()
30+ if build_id :
31+ letter = build_id [- 1 ].upper ()
3232 return BUILD_MAP .get (letter , "unknown" )
3333 return "unknown"
3434
3535def read_model_infos_from_magic (magic_path : Path ) -> dict :
3636 with zipfile .ZipFile (magic_path , "r" ) as z :
3737 candidate = None
3838 for name in z .namelist ():
39- if name .lower ().endswith ("infos .json" ):
39+ if name .lower ().endswith ("metadata .json" ):
4040 candidate = name
4141 break
4242 if not candidate :
43- raise FileNotFoundError (f"Aucun infos .json dans { magic_path .name } " )
43+ raise FileNotFoundError (f"Aucun metadata .json dans { magic_path .name } " )
4444
4545 with z .open (candidate ) as f :
4646 data = json .loads (f .read ().decode ("utf-8" ))
@@ -100,15 +100,14 @@ def main():
100100 continue
101101
102102 name = m .group ("name" )
103- version = m .group ("version" )
104103 build_id = m .group ("buildid" )
105- build_type = parse_build_type (build_id )
106-
107104 try :
108105 infos = read_model_infos_from_magic (magic_path )
109106 except Exception as e :
110107 print (f"[ERREUR] { magic_path .name } : { e } " )
111108 continue
109+ version = infos .get ("version" , "unknown" )
110+ build_type = parse_build_type (build_id )
112111
113112 if infos .get ("version" ) and infos ["version" ] != version :
114113 print (f"[WARN] version mismatch: filename={ version } / infos.json={ infos ['version' ]} " )
0 commit comments