# Licensed under a 3-clause BSD style license - see LICENSE.rstimportosimportrefrom..importutilfrom..benchmarksimportBenchmarksfrom..consoleimportlogfrom..machineimportMachine,MachineCollectionfrom..resultsimportResults,get_filenamefrom.importCommandfrom.runimportRun
[docs]defsetup_arguments(cls,subparsers):parser=subparsers.add_parser("update",help="Update the results and config files to the current version",description="Update the results and config files to the current version",)parser.set_defaults(func=cls.run_from_args)returnparser
[docs]defrun(cls,conf,_machine_file=None):MachineCollection.update(_path=_machine_file)log.info("Updating results data...")forroot,dirs,filesinos.walk(conf.results_dir):forfilenameinfiles:path=os.path.join(root,filename)iffilename=='machine.json':Machine.update(path)eliffilename=="benchmarks.json":passeliffilename.endswith('.json'):try:Results.update(path)exceptutil.UserErroraserr:# Conversion failed: just skip the filelog.warning(f"{path}: {err}")continue# Rename files if necessarym=re.match(r'^([0-9a-f]+)-(.*)\.json$',os.path.basename(path),re.IGNORECASE)ifm:new_path=get_filename(root,m.group(1),m.group(2))ifnew_path!=path:try:ifos.path.exists(new_path):raiseOSError()os.rename(path,new_path)exceptOSError:log.warning(f"{path}: should be renamed to {new_path}")else:log.warning(f"{path}: unrecognized file name")# Check benchmarks.jsonlog.info("Updating benchmarks.json...")ok=Falsetry:Benchmarks.load(conf)ok=Trueexceptutil.UserError:passifnotok:# Regenerating the file is neededwithlog.indent():Run.run(conf,bench=['just-discover'])