def update_xml(path_name, test): dir_name = os.path.join(os.getcwd(), path_name) full_path = os.path.join(dir_name, settings.content_file) f = open(full_path, mode='r') lines = f.readlines() f.close() lines = [x for x in lines if '<ns0:platform idref="cpe:/o:' not in x] for index, line in enumerate(lines): if 'tmp_preupgrade' in line: lines[index + 1] = lines[index + 1].replace( 'SCENARIO', os.path.join(os.getcwd(), 'tests/FOOBAR6_7-results')) if 'current_directory' in line: lines[index + 1] = lines[index + 1].replace( 'SCENARIO', os.path.join(os.getcwd(), 'tests/FOOBAR6_7-results')) if 'check-content-ref href="' + test in line: lines[index] = line.replace('content-ref href="{0}/'.format(test), 'content-ref href="') try: f = open(full_path, mode='w') f.writelines(lines) finally: f.close() utils.update_platform(full_path)
def update_xml(path_name, test): dir_name = os.path.join(os.getcwd(), path_name) full_path = os.path.join(dir_name, settings.content_file) f = open(full_path, mode='r') lines = f.readlines() f.close() lines = [x for x in lines if '<ns0:platform idref="cpe:/o:' not in x] for index, line in enumerate(lines): if 'tmp_preupgrade' in line: lines[index+1] = lines[index+1].replace('SCENARIO', os.path.join(os.getcwd(), 'tests/FOOBAR6_7-results')) if 'current_directory' in line: lines[index+1] = lines[index+1].replace('SCENARIO', os.path.join(os.getcwd(), 'tests/FOOBAR6_7-results')) if 'check-content-ref href="'+test in line: lines[index] = line.replace('content-ref href="{0}/'.format(test), 'content-ref href="') try: f = open(full_path, mode='w') f.writelines(lines) finally: f.close() utils.update_platform(full_path)
def generate_report(self): """Function generates report""" scenario = self.get_scenario() scenario_path = os.path.join(self.conf.source_dir, scenario) assessment_dir = os.path.join(self.conf.result_dir, self.get_proper_scenario(scenario)) dir_util.copy_tree(scenario_path, assessment_dir) # Try copy directory with contents to /root/preupgrade # Call xccdf_compose API for generating all-xccdf.xml if not self.conf.contents: xccdf_compose = XCCDFCompose(assessment_dir) generated_dir = xccdf_compose.generate_xml(generate_from_ini=False) if os.path.isdir(assessment_dir): shutil.rmtree(assessment_dir) shutil.move(generated_dir, assessment_dir) self.common.prep_symlinks(assessment_dir, scenario=self.get_proper_scenario(scenario)) if not self.conf.contents: utils.update_platform(os.path.join(assessment_dir, settings.content_file)) else: utils.update_platform(self.content) assessment_dir = os.path.dirname(self.content) return assessment_dir