6
6
import os
7
7
import re
8
8
import tarfile
9
+ from datetime import timezone
9
10
from sysdiagnose .utils .base import BaseInterface , BaseParserInterface , BaseAnalyserInterface , SysdiagnoseConfig
10
11
from sysdiagnose .utils .logger import set_json_logging , logger
11
12
from io import TextIOWrapper
@@ -178,13 +179,14 @@ def create_case(self, sysdiagnose_file: str, force: bool = False, case_id: bool
178
179
return case
179
180
180
181
@staticmethod
181
- def get_case_metadata (source_file : str ) -> str :
182
+ def get_case_metadata (source_file : str ) -> dict | None :
182
183
"""
183
- Returns the sha256 hash of the sysdiagnose source file/folder.
184
- The hash is calculated by concatenating the contents of the case metadata: udid, serial, ios version and date.
184
+ Returns the metadata related to the given sysdiagnose file/folder.
185
+ This includes serial number, unique device ID, iOS version, model, date of sysdiagnose creation,
186
+ and a case ID based on the serial number and date.
185
187
186
188
:param source_file: Path to the sysdiagnose file/folder
187
- :return: sha256 hash of the file/folder
189
+ :return: dictionary with metadata or None if the file is invalid
188
190
"""
189
191
from sysdiagnose .parsers .remotectl_dumpstate import RemotectlDumpstateParser
190
192
from sysdiagnose .parsers .sys import SystemVersionParser
@@ -239,7 +241,8 @@ def get_case_metadata(source_file: str) -> str:
239
241
return None
240
242
241
243
# Time to obtain the metadata
242
-
244
+ # Turn the sysdiagnose date into UTC
245
+ sysdiagnose_date_utc = sysdiagnose_date .astimezone (timezone .utc )
243
246
if remotectl_dumpstate_json and 'error' not in remotectl_dumpstate_json :
244
247
if 'Local device' in remotectl_dumpstate_json :
245
248
try :
@@ -249,8 +252,8 @@ def get_case_metadata(source_file: str) -> str:
249
252
'unique_device_id' : remotectl_dumpstate_json ['Local device' ]['Properties' ]['UniqueDeviceID' ],
250
253
'ios_version' : remotectl_dumpstate_json ['Local device' ]['Properties' ]['OSVersion' ],
251
254
'model' : remotectl_dumpstate_json ['Local device' ]['Properties' ]['ProductType' ],
252
- 'date' : sysdiagnose_date .isoformat (timespec = 'microseconds' ),
253
- 'case_id' : f"{ serial_number } _{ sysdiagnose_date .strftime ('%Y%m%d_%H%M%S' )} " ,
255
+ 'date' : sysdiagnose_date_utc .isoformat (timespec = 'microseconds' ),
256
+ 'case_id' : f"{ serial_number } _{ sysdiagnose_date_utc .strftime ('%Y%m%d_%H%M%S' )} " ,
254
257
'source_file' : source_file ,
255
258
'source_sha256' : ''
256
259
}
@@ -270,8 +273,8 @@ def get_case_metadata(source_file: str) -> str:
270
273
'unique_device_id' : 'unknown' ,
271
274
'ios_version' : sys_json ['ProductVersion' ],
272
275
'model' : 'unknown' , # FIXME figure out a way to get the model from sysdiagnose
273
- 'date' : sysdiagnose_date .isoformat (timespec = 'microseconds' ),
274
- 'case_id' : f"{ serial_number } _{ sysdiagnose_date .strftime ('%Y%m%d_%H%M%S' )} " ,
276
+ 'date' : sysdiagnose_date_utc .isoformat (timespec = 'microseconds' ),
277
+ 'case_id' : f"{ serial_number } _{ sysdiagnose_date_utc .strftime ('%Y%m%d_%H%M%S' )} " ,
275
278
'source_file' : source_file ,
276
279
'source_sha256' : ''
277
280
}
0 commit comments