当前位置: 首页>>代码示例>>Python>>正文


Python utils.FileHelper类代码示例

本文整理汇总了Python中preupg.utils.FileHelper的典型用法代码示例。如果您正苦于以下问题:Python FileHelper类的具体用法?Python FileHelper怎么用?Python FileHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FileHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: write_xml

 def write_xml(self):
     """Function writes XML document to file"""
     self.target_tree.set('xmlns:xhtml', 'http://www.w3.org/1999/xhtml/')
     # we really must set encoding here! and suppress it in write_to_file
     data = ElementTree.tostring(self.target_tree, "utf-8")
     FileHelper.write_to_file(self.path, 'wb', data, False)
     self.target_tree = ElementTree.parse(self.path).getroot()
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:7,代码来源:report_parser.py

示例2: test_xml_upgrade_not_migrate

 def test_xml_upgrade_not_migrate(self):
     test_ini = {'content_title': 'Testing only migrate title',
                 'content_description': ' some content description',
                 'author': 'test <[email protected]>',
                 'config_file': '/etc/named.conf',
                 'applies_to': 'test',
                 'requires': 'bash',
                 'binary_req': 'sed',
                 'mode': 'upgrade'}
     ini = {}
     old_settings = settings.UPGRADE_PATH
     migrate, upgrade = self._create_temporary_dir()
     ini[self.filename] = test_ini
     xml_utils = XmlUtils(self.root_dir_name, self.dirname, ini)
     xml_utils.prepare_sections()
     upgrade_file = FileHelper.get_file_content(upgrade, 'rb', method=True)
     tag = [x.strip() for x in upgrade_file if 'xccdf_preupg_rule_test_check_script' in x.strip()]
     self.assertIsNotNone(tag)
     try:
         migrate_file = FileHelper.get_file_content(migrate, 'rb', method=True)
     except IOError:
         migrate_file = None
     self.assertIsNone(migrate_file)
     self._delete_temporary_dir(migrate, upgrade)
     settings.UPGRADE_PATH = old_settings
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:25,代码来源:test_xml.py

示例3: update_check_script

 def update_check_script(self, updates, author=None):
     """
     The function updates check script with license file
     and with API functions like check_rpm_to and check_applies_to
     """
     script_type = FileHelper.get_script_type(self.full_path_name)
     if author is None:
         author = "<empty_line>"
     generated_section, functions = ModuleHelper.generate_common_stuff(settings.license % author,
                                                                       updates,
                                                                       script_type)
     lines = FileHelper.get_file_content(self.full_path_name, "rb", method=True)
     if not [x for x in lines if re.search(r'#END GENERATED SECTION', x)]:
         MessageHelper.print_error_msg("#END GENERATED SECTION is missing in check_script %s" % self.full_path_name)
         raise MissingHeaderCheckScriptError
     for func in functions:
         lines = [x for x in lines if func not in x.strip()]
     output_text = ""
     for line in lines:
         if '#END GENERATED SECTION' in line:
             new_line = '\n'.join(generated_section)
             new_line = new_line.replace('<empty_line>', '').replace('<new_line>', '')
             output_text += new_line+'\n'
             if 'check_applies' in updates:
                 component = updates['check_applies']
             else:
                 component = "distribution"
             if script_type == "sh":
                 output_text += 'COMPONENT="'+component+'"\n'
             else:
                 output_text += 'set_component("'+component+'")\n'
         output_text += line
     FileHelper.write_to_file(self.full_path_name, "wb", output_text)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:33,代码来源:script_utils.py

示例4: update_check_script

 def update_check_script(self, updates, author=None):
     """
     The function updates check script with license file
     and with API functions like check_rpm_to and check_applies_to
     """
     script_type = FileHelper.get_script_type(self.check_script_path)
     if author is None:
         author = "<empty_line>"
     generated_section, functions = ModuleHelper.generate_common_stuff(
         settings.license % author, updates, script_type)
     lines = FileHelper.get_file_content(self.check_script_path, "rb",
                                         method=True)
     if not [x for x in lines if re.search(r'#END GENERATED SECTION', x)]:
         raise MissingHeaderCheckScriptError(self.check_script_path)
     for func in functions:
         lines = [x for x in lines if func not in x.strip()]
     output_text = ""
     for line in lines:
         if '#END GENERATED SECTION' in line:
             new_line = '\n'.join(generated_section)
             new_line = new_line.replace('<empty_line>',
                                         '').replace('<new_line>', '')
             output_text += new_line + '\n'
         output_text += line
     FileHelper.write_to_file(self.check_script_path, "wb", output_text)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:25,代码来源:script_utils.py

示例5: setUp

    def setUp(self):
        self.root_dir_name = "tests/FOOBAR6_7" + settings.results_postfix
        self.dirname = os.path.join(self.root_dir_name, "test")
        if os.path.exists(self.dirname):
            shutil.rmtree(self.dirname)
        os.makedirs(self.dirname)
        self.filename = os.path.join(self.dirname, 'test.ini')
        self.rule = []
        self.loaded_ini = {}
        self.test_ini = {'content_title': 'Testing content title',
                         'content_description': ' some content description',
                         'author': 'test <[email protected]>',
                         'config_file': '/etc/named.conf'
                         }
        self.check_sh = """#!/bin/bash

#END GENERATED SECTION

#This is testing check script
 """
        check_name = os.path.join(self.dirname, settings.check_script)
        FileHelper.write_to_file(check_name, "wb", self.check_sh)
        os.chmod(check_name, stat.S_IEXEC | stat.S_IRWXG | stat.S_IRWXU)

        self.solution_text = """
A solution text for test suite"
"""
        test_solution_name = os.path.join(self.dirname, settings.solution_txt)
        FileHelper.write_to_file(test_solution_name, "wb", self.solution_text)
        os.chmod(check_name, stat.S_IEXEC | stat.S_IRWXG | stat.S_IRWXU)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:30,代码来源:test_xml.py

示例6: test_secret_check_script

 def test_secret_check_script(self):
     """Check occurrence of secret file for check script"""
     self.test_ini['check_script'] = '.minicheck'
     text = """#!/usr/bin/sh\necho 'ahojky'\n"""
     FileHelper.write_to_file(os.path.join(self.dir_name, self.check_script), "wb", text)
     self.loaded_ini[self.filename].append(self.test_ini)
     self.xml_utils = XmlUtils(self.dir_name, self.loaded_ini)
     self.assertRaises(MissingFileInContentError, lambda: list(self.xml_utils.prepare_sections()))
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:8,代码来源:test_xml.py

示例7: test_add_pkg_to_kickstart

 def test_add_pkg_to_kickstart(self):
     expected_list = ['my_foo_pkg', 'my_bar_pkg']
     script_api.add_pkg_to_kickstart(['my_foo_pkg', 'my_bar_pkg'])
     for pkg in FileHelper.get_file_content(script_api.SPECIAL_PKG_LIST, 'rb', method=True):
         self.assertTrue(pkg.strip() in expected_list)
     script_api.add_pkg_to_kickstart('my_foo_pkg my_bar_pkg')
     for pkg in FileHelper.get_file_content(script_api.SPECIAL_PKG_LIST,'rb', method=True):
         self.assertTrue(pkg.strip() in expected_list)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:8,代码来源:test_api.py

示例8: test_hashes

 def test_hashes(self):
     text_to_hash="""
         This is preupgrade assistant test has string"
     """
     self.dir_name = "tests/hashes"
     os.mkdir(self.dir_name)
     FileHelper.write_to_file(os.path.join(self.dir_name, "post_script"), 'wb', text_to_hash)
     PostupgradeHelper.hash_postupgrade_file(False, self.dir_name)
     return_value = PostupgradeHelper.hash_postupgrade_file(False, self.dir_name, check=True)
     self.assertTrue(return_value)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:10,代码来源:test_preupg.py

示例9: test_incorrect_tag

 def test_incorrect_tag(self):
     """
     Check occurrence of incorrect tag
     Tests issue #30
     """
     text_ini = '[preupgrade]\n'
     text_ini += '\n'.join([key + " = " + self.test_ini[key] for key in self.test_ini])
     text_ini += '\n[]\neliskk\n'
     FileHelper.write_to_file(self.filename, "wb", text_ini)
     oscap = OscapGroupXml(self.root_dir_name, self.dir_name)
     self.assertRaises(configparser.ParsingError, oscap.find_all_ini)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:11,代码来源:test_xml.py

示例10: write_xml

 def write_xml(self):
     """The function is used for storing a group.xml file"""
     self.find_all_ini()
     self.write_list_rules()
     xml_utils = XmlUtils(self.dirname, self.loaded)
     self.rule = xml_utils.prepare_sections()
     file_name = os.path.join(self.dirname, "group.xml")
     try:
         FileHelper.write_to_file(file_name, "wb", ["%s" % item for item in self.rule])
     except IOError as ior:
         print ('Problem with write data to the file ', file_name, ior.message)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:11,代码来源:oscap_group_xml.py

示例11: write_profile_xml

 def write_profile_xml(self, target_tree):
     """The function stores all-xccdf.xml file into content directory"""
     file_name = os.path.join(self.dirname, "all-xccdf.xml")
     print ('File which can be used by Preupgrade-Assistant is:\n', ''.join(file_name))
     try:
         # encoding must be set! otherwise ElementTree return non-ascii characters
         # as html entities instead, which are unsusable for us
         data = ElementTree.tostring(target_tree, "utf-8")
         FileHelper.write_to_file(file_name, "wb", data, False)
     except IOError as ioe:
         print ('Problem with writing to file ', file_name, ioe.message)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:11,代码来源:oscap_group_xml.py

示例12: write_xccdf_version

 def write_xccdf_version(file_name, direction=False):
     """
     Function updates XCCDF version because
     of separate HTML generation and our own XSL stylesheet
     """
     namespace_1 = 'http://checklists.nist.gov/xccdf/1.1'
     namespace_2 = 'http://checklists.nist.gov/xccdf/1.2'
     content = FileHelper.get_file_content(file_name, "rb")
     if direction:
         content = re.sub(namespace_2, namespace_1, content)
     else:
         content = re.sub(namespace_1, namespace_2, content)
     FileHelper.write_to_file(file_name, 'wb', content)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:13,代码来源:report_parser.py

示例13: _create_check_script

 def _create_check_script(self):
     if self.check_script:
         if self.script_type == "sh":
             content = settings.temp_bash_script
         else:
             content = settings.temp_python_script
         FileHelper.write_to_file(os.path.join(self.get_content_path(),
                                               self.get_check_script()),
                                  'wb',
                                  content)
         os.chmod(os.path.join(self.get_content_path(),
                               self.get_check_script()),
                  0755)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:13,代码来源:ui_helper.py

示例14: update_report

    def update_report(self, report_path):
        """Update XML or HTML report with relevant solution texts."""
        if not self.solution_texts:
            self.load_solution_texts()

        orig_file = os.path.join(self.assessment_result_path, report_path)
        report_content = FileHelper.get_file_content(orig_file, "rb")

        for solution_placeholer, solution_text in self.solution_texts.items():
            report_content = report_content.replace(solution_placeholer,
                                                    solution_text)

        FileHelper.write_to_file(orig_file, "wb", report_content)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:13,代码来源:xml_manager.py

示例15: check_scripts

 def check_scripts(self, type_name):
     """
     The function checks whether script exists in content directory
     If check_script exists then the script checks whether it is executable
     """
     if not os.path.exists(self.full_path_name):
         print ("ERROR: ", self.full_path_name, "Script name does not exists")
         print ("List of directory (", self.dir_name, ") is:")
         for file_name in os.listdir(self.dir_name):
             print (file_name)
         raise MissingFileInContentError
     if type_name != 'solution':
         FileHelper.check_executable(self.full_path_name)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:13,代码来源:script_utils.py


注:本文中的preupg.utils.FileHelper类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。