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


Python ConfWriter.ConfWriter类代码示例

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


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

示例1: delete_row

 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,代码行数:8,代码来源:WorkspaceWindow.py

示例2: update_section_name

 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,代码行数:10,代码来源:WorkspaceWindow.py

示例3: on_key_changed

 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,代码行数:11,代码来源:SectionView.py

示例4: ConfWriterTestCase

class ConfWriterTestCase(unittest.TestCase):
    example_file = "to be ignored \n\
    save=true\n\
    a_default, another = val \n\
    TEST = tobeignored  # do you know that 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):
        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",
                       "# do you know that 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.reparse(self.file))
        del self.uut

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

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

示例5: _save_configuration

    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)
开发者ID:AhmedKamal1432,项目名称:coala,代码行数:13,代码来源:SectionManager.py

示例6: create_section_view

 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,代码行数:17,代码来源:WorkspaceWindow.py

示例7: setUp

    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)
开发者ID:CarIosRibeiro,项目名称:coala,代码行数:8,代码来源:ConfWriterTest.py

示例8: setUp

 def setUp(self):
     self.project_dir = os.getcwd()
     self.printer = ConsolePrinter()
     self.coafile = os.path.join(tempfile.gettempdir(), '.coafile')
     self.writer = ConfWriter(self.coafile)
     self.arg_parser = _get_arg_parser()
     self.old_argv = deepcopy(sys.argv)
     del sys.argv[1:]
开发者ID:coala-analyzer,项目名称:coala-quickstart,代码行数:8,代码来源:SettingsTest.py

示例9: setUp

    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)
开发者ID:Anmolbansal1,项目名称:coala,代码行数:9,代码来源:ConfWriterTest.py

示例10: test_write_with_dir

    def test_write_with_dir(self):
        self.uut_dir = ConfWriter(tempfile.gettempdir())
        self.uut_dir.write_sections({'name': Section('name')})
        self.uut_dir.close()

        with open(os.path.join(tempfile.gettempdir(), '.coafile'), 'r') as f:
            lines = f.readlines()

        self.assertEqual(['[name]\n'], lines)
        os.remove(os.path.join(tempfile.gettempdir(), '.coafile'))
开发者ID:Anmolbansal1,项目名称:coala,代码行数:10,代码来源:ConfWriterTest.py

示例11: save_sections

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,代码行数:17,代码来源:ConfigurationGathering.py

示例12: save_sections

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,代码行数:18,代码来源:ConfigurationGathering.py

示例13: generate_green_mode_sections

def generate_green_mode_sections(data, project_dir, project_files,
                                 ignore_globs, printer=None, suffix=''):
    """
    Generates the section objects for the green_mode.
    :param data:
        This is the data structure generated from the method
        generate_data_struct_for_sections().
    :param project_dir:
        The path of the project directory.
    :param project_files:
        List of paths to only the files inside the project directory.
    :param ignore_globs:
        The globs of files to ignore.
    :param printer:
        The ConsolePrinter object.
    :param suffix:
        A suffix that can be added to the `.coafile.green`.
    """
    all_sections = {'all': [], }
    lang_files = split_by_language(project_files)
    extset = get_extensions(project_files)
    ignored_files = generate_ignore_field(project_dir, lang_files.keys(),
                                          extset, ignore_globs)
    if ignored_files:
        section_all = Section('all')
        section_all['ignore'] = ignored_files
        all_sections['all'].append(section_all)

    for bear in data:
        num = 0
        bear_sections = []
        for setting_combs in data[bear]:
            if not setting_combs:
                continue
            for dict_ in setting_combs:
                num = num + 1
                section = Section('all.' + bear.__name__ + str(num), None)
                for key_ in dict_:
                    if key_ == 'filename':
                        file_list_sec = dict_[key_]
                        file_list_sec, ignore_list = aggregate_files(
                            file_list_sec, project_dir)
                        dict_[key_] = file_list_sec
                        section['ignore'] = ', '.join(
                            escape(x, '\\') for x in ignore_list)
                        section['files'] = ', '.join(
                            escape(x, '\\') for x in dict_[key_])
                    else:
                        section[key_] = str(dict_[key_])
                    section['bears'] = bear.__name__
                bear_sections.append(section)
        # Remove sections for the same bear who have common files i.e. more
        # than one setting was found to be green.
        file_list = []
        new_bear_sections = []
        for index, section in enumerate(bear_sections):
            if not section.contents['files'] in file_list:
                file_list.append(section.contents['files'])
                new_bear_sections.append(section)
        all_sections[bear.__name__] = new_bear_sections

    coafile = os.path.join(project_dir, '.coafile.green' + suffix)
    writer = ConfWriter(coafile)
    write_sections(writer, all_sections)
    writer.close()
    printer.print("'" + coafile + "' successfully generated.", color='green')
开发者ID:coala-analyzer,项目名称:coala-quickstart,代码行数:66,代码来源:green_mode.py

示例14: update_value

 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,代码行数:5,代码来源:SectionView.py

示例15: ConfWriterTest

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"
        "    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",
            "\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:CarIosRibeiro,项目名称:coala,代码行数:68,代码来源:ConfWriterTest.py


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