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


Python ConfWriter.write_sections方法代码示例

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


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

示例1: delete_row

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def delete_row(self, button, listboxrow):
     del self.sections_dict[self.section_stack_map[listboxrow].get_name()]
     self.section_stack_map[listboxrow].destroy()
     del self.section_stack_map[listboxrow]
     listboxrow.destroy()
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:10,代码来源:WorkspaceWindow.py

示例2: update_section_name

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def update_section_name(self, widget, arg, old_name, section_view):
     section_view.set_name(widget.get_name())
     self.sections_dict[old_name].name = widget.get_name()
     self.sections_dict = update_ordered_dict_key(self.sections_dict,
                                                  old_name,
                                                  widget.get_name())
     widget.connect("edited", self.update_section_name, widget.get_name())
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:12,代码来源:WorkspaceWindow.py

示例3: on_key_changed

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def on_key_changed(self, widget, arg, sensitive_button, value_entry):
     setting = Setting(widget.get_name(), value_entry.get_text())
     self.sections_dict[self.get_name()].append(setting)
     self.add_setting()
     sensitive_button.set_sensitive(True)
     sensitive_button.set_name(setting.key)
     widget.connect("edited", self.update_key, setting, sensitive_button)
     value_entry.connect("focus-out-event", self.update_value, setting)
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:13,代码来源:SectionView.py

示例4: ConfWriterTest

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
class ConfWriterTest(unittest.TestCase):
    example_file = ("to be ignored \n"
                    "    save=true\n"
                    "    a_default, another = val \n"
                    "    TEST = tobeignored  # thats a comment \n"
                    "    test = push \n"
                    "    t = \n"
                    "    [MakeFiles] \n"
                    "     j  , ANother = a \n"
                    "                   multiline \n"
                    "                   value \n"
                    "    ; just a omment \n"
                    "    ; just a omment \n")

    def setUp(self):
        self.file = os.path.join(tempfile.gettempdir(), "ConfParserTestFile")
        with open(self.file, "w", encoding='utf-8') as filehandler:
            filehandler.write(self.example_file)

        self.conf_parser = ConfParser()
        self.write_file_name = os.path.join(tempfile.gettempdir(),
                                            "ConfWriterTestFile")
        self.uut = ConfWriter(self.write_file_name)

    def tearDown(self):
        self.uut.close()
        os.remove(self.file)
        os.remove(self.write_file_name)

    def test_exceptions(self):
        self.assertRaises(TypeError, self.uut.write_section, 5)

    def test_write(self):
        result_file = ["[Default]\n",
                       "save = true\n",
                       "a_default, another = val\n",
                       "# thats a comment\n",
                       "test = push\n",
                       "t = \n",
                       "\n",
                       "[MakeFiles]\n",
                       "j, ANother = a\n",
                       "multiline\n",
                       "value\n",
                       "; just a omment\n",
                       "; just a omment\n"]
        self.uut.write_sections(self.conf_parser.parse(self.file))
        self.uut.close()

        with open(self.write_file_name, "r") as f:
            lines = f.readlines()

        self.assertEqual(result_file, lines)
开发者ID:gaurav-kispotta,项目名称:coala,代码行数:55,代码来源:ConfWriterTest.py

示例5: save_sections

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
def save_sections(sections):
    """
    Saves the given sections if they are to be saved.

    :param sections: A section dict.
    """
    default_section = sections["default"]
    try:
        if bool(default_section.get("save", "false")):
            conf_writer = ConfWriter(str(default_section.get("config", ".coafile")))
        else:
            return
    except ValueError:
        conf_writer = ConfWriter(str(default_section.get("save", ".coafile")))

    conf_writer.write_sections(sections)
    conf_writer.close()
开发者ID:Tanmay28,项目名称:coala,代码行数:19,代码来源:ConfigurationGathering.py

示例6: create_section_view

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def create_section_view(self, widget=None, arg=None, row_obejct=None):
     section_view = SectionView(self.sections_dict, self.src)
     section_view.set_visible(True)
     section_view.set_name(widget.get_name())
     self.sections.add_named(section_view, widget.get_name())
     self.sections.set_visible_child_name(widget.get_name())
     if arg is not None:
         widget.connect("edited",
                        self.update_section_name,
                        widget.get_name(),
                        section_view)
         self.sections_dict[widget.get_name()] = Section(widget.get_name())
         section_view.add_setting()
         conf_writer = ConfWriter(self.src+'/.coafile')
         conf_writer.write_sections(self.sections_dict)
         conf_writer.close()
     self.section_stack_map[row_obejct] = section_view
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:19,代码来源:WorkspaceWindow.py

示例7: save_sections

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
def save_sections(sections):
    """
    Saves the given sections if they are to be saved.

    :param sections: A section dict.
    """
    default_section = sections['default']
    try:
        if bool(default_section.get('save', 'false')):
            conf_writer = ConfWriter(
                str(default_section.get('config', Constants.default_coafile)))
        else:
            return
    except ValueError:
        conf_writer = ConfWriter(str(default_section.get('save', '.coafile')))

    conf_writer.write_sections(sections)
    conf_writer.close()
开发者ID:RohanVB,项目名称:coala,代码行数:20,代码来源:ConfigurationGathering.py

示例8: update_value

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def update_value(self, widget, arg, setting):
     setting.value = widget.get_text()
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:7,代码来源:SectionView.py

示例9: update_key

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def update_key(self, widget, arg, setting, delete_button):
     setting.key = widget.get_name()
     delete_button.set_name(widget.get_name())
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:8,代码来源:SectionView.py

示例10: delete_setting

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
 def delete_setting(self, button, setting_row):
     self.sections_dict[self.get_name()].delete_setting(button.get_name())
     setting_row.destroy()
     conf_writer = ConfWriter(self.src+'/.coafile')
     conf_writer.write_sections(self.sections_dict)
     conf_writer.close()
开发者ID:coala-analyzer,项目名称:coala-gui,代码行数:8,代码来源:SectionView.py

示例11: ConfWriterTest

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
class ConfWriterTest(unittest.TestCase):
    example_file = ('to be ignored \n'
                    '    save=true\n'
                    '    a_default, another = val \n'
                    '    TEST = tobeignored  # thats a comment \n'
                    '    test = push \n'
                    '    t = \n'
                    '    [Section] \n'
                    '    [MakeFiles] \n'
                    '     j  , ANother = a \n'
                    '                   multiline \n'
                    '                   value \n'
                    '    ; just a omment \n'
                    '    ; just a omment \n'
                    '    key\\ space = value space\n'
                    '    key\\=equal = value=equal\n'
                    '    key\\\\backslash = value\\\\backslash\n'
                    '    key\\,comma = value,comma\n'
                    '    key\\#hash = value\\#hash\n'
                    '    key\\.dot = value.dot\n')

    def setUp(self):
        self.file = os.path.join(tempfile.gettempdir(), 'ConfParserTestFile')
        with open(self.file, 'w', encoding='utf-8') as file:
            file.write(self.example_file)

        self.conf_parser = ConfParser()
        self.write_file_name = os.path.join(tempfile.gettempdir(),
                                            'ConfWriterTestFile')
        self.uut = ConfWriter(self.write_file_name)

    def tearDown(self):
        self.uut.close()
        os.remove(self.file)
        os.remove(self.write_file_name)

    def test_exceptions(self):
        self.assertRaises(TypeError, self.uut.write_section, 5)

    def test_write(self):
        result_file = ['[Default]\n',
                       'save = true\n',
                       'a_default, another = val\n',
                       '# thats a comment\n',
                       'test = push\n',
                       't = \n',
                       '[Section]\n',
                       '[MakeFiles]\n',
                       'j, ANother = a\n',
                       'multiline\n',
                       'value\n',
                       '; just a omment\n',
                       '; just a omment\n',
                       'key\\ space = value space\n',
                       'key\\=equal = value=equal\n',
                       'key\\\\backslash = value\\\\backslash\n',
                       'key\\,comma = value,comma\n',
                       'key\\#hash = value\\#hash\n',
                       'key\\.dot = value.dot\n']
        self.uut.write_sections(self.conf_parser.parse(self.file))
        self.uut.close()

        with open(self.write_file_name, 'r') as f:
            lines = f.readlines()

        self.assertEqual(result_file, lines)
开发者ID:RohanVB,项目名称:coala,代码行数:68,代码来源:ConfWriterTest.py

示例12: run

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]

#.........这里部分代码省略.........

        self.coafile_sections = self._load_config_file(config)

        self.sections = self._merge_section_dicts(self.default_sections,
                                                  self.user_sections)

        self.sections = self._merge_section_dicts(self.sections,
                                                  self.coafile_sections)

        self.sections = self._merge_section_dicts(self.sections,
                                                  self.cli_sections)

        for section in self.sections:
            if section != "default":
                self.sections[section].defaults = self.sections["default"]

    def _load_config_file(self, filename, silent=False):
        """
        Loads sections from a config file. Prints an appropriate warning if
        it doesn't exist and returns a section dict containing an empty
        default section in that case.

        It assumes that the cli_sections are available.

        :param filename: The file to load settings from.
        :param silent:   Whether or not to warn the user if the file doesn't
                         exist.
        """
        filename = os.path.abspath(filename)

        try:
            return self.conf_parser.reparse(filename)
        except self.conf_parser.FileNotFoundError:
            if not silent:
                self.cli_sections["default"].retrieve_logging_objects()
                self.cli_sections["default"].log_printer.warn(
                    _("The requested coafile '{filename}' does not exist. "
                      "Thus it will not be used.").format(filename=filename))

            return {"default": Section("default")}

    def _fill_settings(self):
        for section_name in self.sections:
            section = self.sections[section_name]
            section.retrieve_logging_objects()

            bear_dirs = path_list(section.get("bear_dirs", ""))
            bear_dirs.append(os.path.join(StringConstants.coalib_bears_root,
                                          "**"))
            bears = list(section.get("bears", ""))
            local_bears = collect_bears(bear_dirs,
                                        bears,
                                        [BEAR_KIND.LOCAL])
            global_bears = collect_bears(bear_dirs,
                                         bears,
                                         [BEAR_KIND.GLOBAL])
            filler = SectionFiller(section)
            all_bears = copy.deepcopy(local_bears)
            all_bears.extend(global_bears)
            filler.fill_section(all_bears)

            self.local_bears[section_name] = local_bears
            self.global_bears[section_name] = global_bears

    def _save_configuration(self):
        self.conf_writer = None
        default_section = self.sections["default"]
        try:
            if bool(default_section.get("save", "false")):
                self.conf_writer = ConfWriter(str(
                    default_section.get("config", ".coafile")))
        except ValueError:
            self.conf_writer = ConfWriter(str(default_section.get("save",
                                                                  ".coafile")))

        if self.conf_writer is not None:
            self.conf_writer.write_sections(self.sections)

    @staticmethod
    def _merge_section_dicts(lower, higher):
        """
        Merges the section dictionaries. The values of higher will take
        precedence over the ones of lower. Lower will hold the modified dict in
        the end.
        """
        for name in higher:
            if name in lower:
                lower[name].update(higher[name], ignore_defaults=True)
            else:
                # no deep copy needed
                lower[name] = higher[name]

        return lower

    def _warn_nonexistent_targets(self):
        for target in self.targets:
            if target not in self.sections:
                self.sections["default"].log_printer.warn(
                    _("The requested section '{section}' is not existent. "
                      "Thus it cannot be executed.").format(section=target))
开发者ID:AhmedKamal1432,项目名称:coala,代码行数:104,代码来源:SectionManager.py

示例13: ConfWriterTest

# 需要导入模块: from coalib.output.ConfWriter import ConfWriter [as 别名]
# 或者: from coalib.output.ConfWriter.ConfWriter import write_sections [as 别名]
class ConfWriterTest(unittest.TestCase):
    example_file = ('to be ignored \n'
                    '    save=true\n'
                    '    a_default, another = val \n'
                    '    TEST = tobeignored  # thats a comment \n'
                    '    test = push \n'
                    '    t = \n'
                    '    [Section] \n'
                    '    [MakeFiles] \n'
                    '     j  , ANother = a \n'
                    '                   multiline \n'
                    '                   value \n'
                    '    ; just a omment \n'
                    '    ; just a omment \n'
                    '    key\\ space = value space\n'
                    '    key\\=equal = value=equal\n'
                    '    key\\\\backslash = value\\\\backslash\n'
                    '    key\\,comma = value,comma\n'
                    '    key\\#hash = value\\#hash\n'
                    '    key\\.dot = value.dot\n'
                    '    a_default = val, val2\n')

    append_example_file = ('[defaults]\n'
                           'a = 4\n'
                           'b = 4,5,6\n'
                           'c = 4,5\n'
                           'd = 4\n'
                           '[defaults.new]\n'
                           'a = 4,5,6,7\n'
                           'b = 4,5,6,7\n'
                           'c = 4,5,6,7\n'
                           'd = 4,5,6,7\n')

    def setUp(self):
        self.file = os.path.join(tempfile.gettempdir(), 'ConfParserTestFile')
        with open(self.file, 'w', encoding='utf-8') as file:
            file.write(self.example_file)

        self.log_printer = LogPrinter()
        self.write_file_name = os.path.join(tempfile.gettempdir(),
                                            'ConfWriterTestFile')
        self.uut = ConfWriter(self.write_file_name)

    def tearDown(self):
        self.uut.close()
        os.remove(self.file)
        os.remove(self.write_file_name)

    def test_exceptions(self):
        self.assertRaises(TypeError, self.uut.write_section, 5)

    def test_write(self):
        result_file = ['[Section]\n',
                       '[MakeFiles]\n',
                       'j, ANother = a\n',
                       'multiline\n',
                       'value\n',
                       '; just a omment\n',
                       '; just a omment\n',
                       'key\\ space = value space\n',
                       'key\\=equal = value=equal\n',
                       'key\\\\backslash = value\\\\backslash\n',
                       'key\\,comma = value,comma\n',
                       'key\\#hash = value\\#hash\n',
                       'key\\.dot = value.dot\n',
                       'a_default += val2\n',
                       '[cli]\n',
                       'save = true\n',
                       'a_default, another = val\n',
                       '# thats a comment\n',
                       'test = push\n',
                       't = \n']
        sections = load_configuration(['-c', escape(self.file, '\\')],
                                      self.log_printer)[0]
        del sections['cli'].contents['config']
        self.uut.write_sections(sections)
        self.uut.close()

        with open(self.write_file_name, 'r') as f:
            lines = f.readlines()

        self.assertEqual(result_file, lines)

    def test_append(self):
        with open(self.file, 'w', encoding='utf-8') as file:
            file.write(self.append_example_file)

        result_file = ['[defaults]\n',
                       'a = 4\n',
                       'b = 4,5,6\n',
                       'c = 4,5\n',
                       'd = 4\n',
                       '[defaults.new]\n',
                       'b += 7\n',
                       'c += 6, 7\n',
                       'a, d += 5, 6, 7\n',
                       '[cli]\n']

        sections = load_configuration(['-c', escape(self.file, '\\')],
                                      self.log_printer)[0]
#.........这里部分代码省略.........
开发者ID:Anmolbansal1,项目名称:coala,代码行数:103,代码来源:ConfWriterTest.py


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