Skip to content

Commit

Permalink
Factor out merging logic into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
vodorok committed Nov 15, 2024
1 parent 3f07185 commit e84961b
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions analyzer/codechecker_analyzer/analysis_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ def print_analyzer_statistic_summary(metadata_analyzers, status, msg=None):
LOG.info(" %s: %s", analyzer_type, res)


def merge_plists(results, output_path, plist_file_name):
"""
Merge the plist files generated by the analyzers into a single plist file.
Deletes the original plist files after merging.
"""
LOG.info("Merging plist files into %s", plist_file_name)
plist_data = []
single_plist = Path(output_path, plist_file_name)
for _, _, _, _, original_plist, _ in results:
original_plist = Path(original_plist)
if os.path.exists(original_plist):
with open(original_plist, 'rb') as plist:
LOG.debug(f"Merging original plist {original_plist}")
plist_data.append(plistlib.load(plist))

with open(single_plist, 'wb') as plist:
LOG.debug(f"Dumping merged plist file into {single_plist}")
plistlib.dump(plist_data, plist)

LOG.debug(f"Removing original plist file {original_plist}")
original_plist.unlink()


def worker_result_handler(results,
metadata_tool,
output_path,
Expand All @@ -69,22 +92,7 @@ def worker_result_handler(results,
merge all the plist output files into one, and print the analysis summary.
"""
if plist_file_name:
LOG.info("Merging plist files into %s", plist_file_name)
plist_data = []
single_plist = Path(output_path, plist_file_name)
for _, _, _, _, original_plist, _ in results:
original_plist = Path(original_plist)
if os.path.exists(original_plist):
with open(original_plist, 'rb') as plist:
LOG.debug(f"Merging original plist {original_plist}")
plist_data.append(plistlib.load(plist))

with open(single_plist, 'wb') as plist:
LOG.debug(f"Dumping merged plist file into {single_plist}")
plistlib.dump(plist_data, plist)

LOG.debug(f"Removing original plist file {original_plist}")
original_plist.unlink()
merge_plists(results, output_path, plist_file_name)

skipped_num = 0
reanalyzed_num = 0
Expand Down

0 comments on commit e84961b

Please sign in to comment.