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


Python FileHelper.get_file_content方法代码示例

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


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

示例1: test_xml_upgrade_not_migrate

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 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,代码行数:27,代码来源:test_xml.py

示例2: test_add_pkg_to_kickstart

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 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,代码行数:10,代码来源:test_api.py

示例3: _update_check_description

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
    def _update_check_description(self, filename):
        new_text = []
        lines = FileHelper.get_file_content(os.path.join(self.module_dir,
                                                         filename), "rb", True)

        bold = '<xhtml:b>{0}</xhtml:b>'
        br = '<xhtml:br/>'
        table_begin = '<xhtml:table>'
        table_end = '</xhtml:table>'
        table_header = '<xhtml:tr><xhtml:th>Result</xhtml:th><xhtml:th>' \
                       'Description</xhtml:th></xhtml:tr>'
        table_row = '<xhtml:tr><xhtml:td>{0}</xhtml:td><xhtml:td>{1}' \
                    '</xhtml:td></xhtml:tr>'
        new_text.append(br + br + '\n' + bold.format('Details:') + br)
        results = False
        for line in lines:
            if '=' in line:
                if not results:
                    new_text.append(bold.format('Expected results:') + br)
                    new_text.append(table_begin + '\n' + table_header)
                    results = True
                try:
                    exp_results = line.strip().split('=')
                    new_text.append(table_row.format(exp_results[0],
                                                     exp_results[1]) + '\n')
                except IndexError:
                    pass
            else:
                new_text.append(line.rstrip() + br)
        if results:
            new_text.append(table_end + '\n')

        return '\n'.join(new_text)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:35,代码来源:xml_utils.py

示例4: get_kickstart_users

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def get_kickstart_users(filename, groups=None, splitter=":"):
     """
     returns dictionary with names and uid, gid, etc.
     :param filename: filename with Users in /root/preupgrade/kickstart directory
     :param groups: dictionary with groups
     :param splitter: delimiter for parsing files
     :return: dictionary with users
     """
     try:
         lines = FileHelper.get_file_content(os.path.join(settings.KS_DIR, filename), 'rb', method=True)
     except IOError:
         return None
     lines = [x for x in lines if not x.startswith('#') and not x.startswith(' ')]
     user_dict = {}
     for line in lines:
         fields = line.strip().split(splitter)
         try:
             user_group = []
             if groups:
                 for key, value in six.iteritems(groups):
                     found = [x for x in six.itervalues(value) if fields[0] in x]
                     if found:
                         user_group.append(key)
             user_dict[fields[0]] = {}
             user_dict[fields[0]] = {'homedir': fields[5],
                                     'shell': fields[6],
                                     'uid': int(fields[2]),
                                     'gid': int(fields[3]),
                                     'groups': user_group}
         except IndexError:
             pass
     return user_dict
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:34,代码来源:users_groups.py

示例5: update_check_script

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 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,代码行数:27,代码来源:script_utils.py

示例6: test_check_script_author

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def test_check_script_author(self):
     settings.autocomplete = True
     self.rule = self.xml_utils.prepare_sections()
     lines = FileHelper.get_file_content(os.path.join(
         self.dirname, settings.check_script), "rb", method=True)
     author = [x for x in lines if "test <[email protected]>" in x]
     self.assertTrue(author)
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:9,代码来源:test_xml.py

示例7: load_file

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
def load_file(filename):
    try:
        lines = FileHelper.get_file_content(filename, "rb", True)
        lines = [x.strip() for x in lines]
    except IOError:
        assert False
    return lines
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:9,代码来源:test_creator.py

示例8: update_check_script

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 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,代码行数:35,代码来源:script_utils.py

示例9: update_values_list

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
    def update_values_list(self, section, search_exp, replace_exp):
        """
        The function replaces tags taken from INI files.
        Tags are mentioned in xml_tags.py
        """
        forbidden_empty = ["{scap_name}", "{main_dir}"]
        if search_exp == "{content_description}":
            replace_exp = replace_exp.rstrip()
        elif search_exp == "{check_description}":
            replace_exp = '\n' + replace_exp + '\n'
        elif search_exp == "{config_file}":
            new_text = ""
            for lines in replace_exp.split(','):
                new_text = new_text+"<xhtml:li>"+lines.strip()+"</xhtml:li>"
            replace_exp = new_text.rstrip()
        elif search_exp == "{solution}":
            new_text = FileHelper.get_file_content(os.path.join(self.dirname, replace_exp), "rb", True)
            # we does not need interpreter for fix script
            # in XML therefore skip first line
            replace_exp = ''.join(new_text[1:])
        elif search_exp == "{solution_text}":
            new_text = "_" + '_'.join(get_full_xml_tag(self.dirname))\
                       + "_SOLUTION_MSG_" + replace_exp.upper()
            replace_exp = new_text
        if replace_exp == '' and search_exp in forbidden_empty:
            MessageHelper.print_error_msg(title="Disapproved empty replacement for tag '%s'" % search_exp)
            raise EmptyTagIniFileError

        for cnt, line in enumerate(section):
            if search_exp in line:
                section[cnt] = line.replace(search_exp, replace_exp)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:33,代码来源:xml_utils.py

示例10: reload_xml

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def reload_xml(self, path):
     """Function updates self.target_tree with the new path"""
     self.path = path
     # ElementTree.fromstring can't parse safely unicode string
     content = FileHelper.get_file_content(self.path, 'rb', False, False)
     if not content:
         return None
     self.target_tree = ElementTree.fromstring(content)
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:10,代码来源:report_parser.py

示例11: test_solution_file

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def test_solution_file(self):
     expected_output = ["Testing message"]
     script_api.solution_file('\n'.join(expected_output))
     output = FileHelper.get_file_content(os.path.join(script_api.VALUE_CURRENT_DIRECTORY, self.solution_txt),
                                          "r",
                                          method=True)
     self.assertEqual(expected_output, output)
     os.unlink(os.path.join(script_api.VALUE_CURRENT_DIRECTORY, self.solution_txt))
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:10,代码来源:test_api.py

示例12: __init__

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def __init__(self, report_path):
     self.path = report_path
     self.element_prefix = "{http://checklists.nist.gov/xccdf/1.2}"
     # ElementTree.fromstring can't parse safely unicode string
     content = FileHelper.get_file_content(report_path, 'rb', False, False)
     self.target_tree = ElementTree.fromstring(content)
     self.profile = "Profile"
     self.changed_results = {}
     self.output_data = []
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:11,代码来源:report_parser.py

示例13: update_html

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
    def update_html(self, result_name, solution_files, extension="html"):
        """
         Function updates a XML or HTML file with relevant solution
         texts
        """
        orig_file = os.path.join(self.dirname,
                                 result_name + "." + extension)
        lines = FileHelper.get_file_content(orig_file, "rb", method=True)
        for dir_name, files in six.iteritems(solution_files):
            section = dir_name.replace(os.path.join(self.dirname, self.scenario),
                                       "").replace("/", "_")
            solution_text = section + "_SOLUTION_MSG"

            file_name = self._return_correct_text_file(section, files)
            if not file_name or file_name is None:
                continue
            else:
                logger_report.debug("Solution text '%s' name '%s'", solution_text, file_name)
                text = FileHelper.get_file_content(os.path.join(dir_name, file_name), "rb", method=True)
            for cnt, line in enumerate(lines):
                # If in preupg.risk is a [link] then update them
                # to /root/pre{migrate,upgrade}/...
                if 'preupg.risk.' in line.strip():
                    logger_report.debug(line.strip())
                    lines[cnt] = tag_formating([line], extension)[0]
                    continue
                # Find correct block
                if solution_text not in line.strip():
                    continue

                # Get updated text if it is HTML or TEXT
                lines[cnt] = self.get_updated_text(solution_text,
                                                   text,
                                                   line,
                                                   extension)

        if extension == 'xml':
            for cnt, line in enumerate(lines):
                if 'SOLUTION_MSG' in line.strip():
                    lines[cnt] = re.sub(r'>.*SOLUTION_MSG.*<', '><', line.strip())

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

示例14: get_volume_info

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
 def get_volume_info(filename, first_index, second_index):
     try:
         volume_list = FileHelper.get_file_content(filename, 'rb', method=True, decode_flag=False)
     except IOError:
         log_message("The %s file is missing. The partitioning layout might not be complete." % filename, level=logging.WARNING)
         return None
     volume_info = {}
     for line in volume_list:
         fields = line.strip().split(':')
         volume_info[fields[first_index]] = fields[second_index]
     return volume_info
开发者ID:AloisMahdal,项目名称:preupgrade-assistant,代码行数:13,代码来源:partitioning.py

示例15: is_dist_native

# 需要导入模块: from preupg.utils import FileHelper [as 别名]
# 或者: from preupg.utils.FileHelper import get_file_content [as 别名]
def is_dist_native(pkg):
    """
    return 1 if package is not installed and print warning log.
    is_dist_native function return only True or False
    Case DEVEL_MODE is turn off then return True if package is signed or False if not.
    Case DEVEL_MODE is turn on:
    DIST_NATIVE = sign: return True if is RH_SIGNED else return False
    DIST_NATIVE = all: always return True
    DIST_NATIVE = path_to_file: return True if package is in file else return False
    """

    rpm_qa = FileHelper.get_file_content(VALUE_RPM_QA, "rb", True)
    found = [x for x in rpm_qa if x.split()[0] == pkg]
    if not found:
        log_warning("Package %s is not installed on Red Hat Enterprise Linux system.")
        return False

    rpm_signed = FileHelper.get_file_content(VALUE_RPM_RHSIGNED, "rb", True)
    found = [x for x in rpm_signed if x.split()[0] == pkg]

    if int(DEVEL_MODE) == 0:
        if found:
            return True
        else:
            return False
    else:
        if DIST_NATIVE == "all":
            return True
        if DIST_NATIVE == "sign":
            if found:
                return True
            else:
                return False
        if os.path.exists(DIST_NATIVE):
            list_native = map(
                unicode.strip,
                FileHelper.get_file_content(DIST_NATIVE, "r", method=True)
            )
            if pkg in list_native:
                return True
        return False
开发者ID:upgrades-migrations,项目名称:preupgrade-assistant,代码行数:43,代码来源:script_api.py


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