def _main_func(options, work_dir): ############################################################################### """Construct machines html from an XML file.""" # Initialize a variables for the html template mach_dict = dict() model_version = options.version[0] # get the machine config file files = Files() config_file = files.get_value("MACHINES_SPEC_FILE") expect(os.path.isfile(config_file), "Cannot find config_file {} on disk".format(config_file)) # instantiate a machines object and read XML values into a dictionary machines = Machines(config_file, machine="Query") mach_list = machines.list_available_machines() # get all the machine values loaded into the mach_dict mach_dict = machines.return_values() # intialize the support keys for machine in mach_list: mach_dict[(machine, 'support')] = "Unsupported" # loop through the list of supported machines and flag in the dictionary supported = options.supported[0].split(',') for machine in supported: mach_dict[(machine, 'support')] = "Scientific" # loop through the list of tested machines and flag in the dictionary tested = options.tested[0].split(',') for machine in tested: mach_dict[(machine, 'support')] = "Tested" # load up jinja template templateLoader = jinja2.FileSystemLoader( searchpath='{0}/templates'.format(work_dir)) templateEnv = jinja2.Environment(loader=templateLoader) # TODO - get the cesm_version for the CIME root tmplFile = 'machdef2html.tmpl' template = templateEnv.get_template(tmplFile) templateVars = { 'mach_list': mach_list, 'mach_dict': mach_dict, 'today': _now, 'model_version': model_version } # render the template mach_tmpl = template.render(templateVars) # write the output file with open(options.htmlfile[0], 'w') as html: html.write(mach_tmpl) return 0