def create_driver(self): self._check_and_create_common_config() template_str = hdf_utils.get_template('hdf_driver_config.template') config_content = Template(template_str).safe_substitute({}) hdf_utils.write_file(self.drv_config_path, config_content) self.manager_hcs.add_device(self.module, self.driver) self.hdf_hcs.add_driver(self.module, self.driver)
def check_and_create(self): if self.contents: return template_str = \ hdf_utils.get_template('hdf_driver_manager_config.template') self.contents = Template(template_str).safe_substitute({}) if not os.path.exists(self.file_dir): os.makedirs(self.file_dir) hdf_utils.write_file(self.file_path, self.contents)
def add_driver(self, driver): drv_section = self._create_driver_item(driver) old_range = hdf_utils.find_section(self.contents, drv_section) if old_range: hdf_utils.replace_and_save(self.contents, self.file_path, old_range, drv_section) return tail_pattern = r'include\s+\$\(HDF_DRIVER\)' replacement = '%sinclude $(HDF_DRIVER)' % drv_section.to_str() new_content, count = re.subn(tail_pattern, replacement, self.contents) if count != 1: raise HdfToolException( 'Makefile: %s has more than one include' ' $(HDF_DRIVER)' % self.file_path, CommandErrorCode.FILE_FORMAT_WRONG) hdf_utils.write_file(self.file_path, new_content)
def _create_makefile(self): mk_path = os.path.join(self.file_dir, 'Makefile') template_str = hdf_utils.get_template('hdf_hcs_makefile.template') hdf_utils.write_file(mk_path, template_str)
def _save(self): if self.lines: hdf_utils.write_file(self.file_path, ''.join(self.lines))
def rename_vendor(self): pattern = r'vendor/([a-zA-Z0-9_\-]+)/' replacement = 'vendor/%s/' % self.vendor new_content = re.sub(pattern, replacement, self.contents) hdf_utils.write_file(self.file_path, new_content)
def _render(template_path, output_path, data_model): if not os.path.exists(template_path): return raw_content = hdf_utils.read_file(template_path) contents = Template(raw_content).safe_substitute(data_model) hdf_utils.write_file(output_path, contents)