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


Python GitHandler.status方法代码示例

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


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

示例1: __init__

# 需要导入模块: from git_handler import GitHandler [as 别名]
# 或者: from git_handler.GitHandler import status [as 别名]
class Preprocessor:
    config_file = 'config.json'
    configuration = {}

    command_runner = None
    git_handler = None

    def __init__(self):
        self.config_file = os.path.dirname(os.path.abspath(__file__)) + '/config.json'
        config_data = self.load_configuration()

        self.command_runner = SystemCommandRunner()
        self.configuration = ConfigurationLoader(json_config_data=config_data)
        self.git_handler = GitHandler(project_path=self.configuration.get_project_path_value())

    def execute(self):
        errors = self.validate()

        if errors.__len__() > 0:
            self.show_errors(errors)
        else:
            self.do_commit()

    def validate(self):
        files_to_check = self.get_files_to_check_list()

        if files_to_check.__len__() <= 0:
            return []

        errors = {}
        filename = ''
        appendable = True

        files_to_check = " ".join(files_to_check)

        phpcs_run_command = self.configuration.get_codesniffer_path_value() + ' --standard=PSR2' + files_to_check
        phpcs_response = self.command_runner.execute(command=phpcs_run_command)

        break_point_list = self.get_break_points()

        for line in phpcs_response:
            if 'FILE:' in line:
                filename = line.split(':')[1].strip()

            if any(break_point in line for break_point in break_point_list):
                data = line.split('|')

                if data.__len__() == 3:

                    if not errors.get(filename):
                        errors[filename] = []

                    errors[filename].append({
                        'line': data[0].strip(),
                        'message': data[2].strip()
                    })
                appendable = True
            elif line.split('|').__len__() > 1 and line.split('|')[0].isspace() and appendable:
                errors[filename][-1]['message'] += ' ' + line.split('|')[2].strip()
            else:
                appendable = False

        return errors

    def load_configuration(self):
        with open(self.config_file) as config_data_file:
            config_data = json.load(config_data_file)

        return config_data

    def get_files_to_check_list(self):
        files_to_check = []
        add_to_check_list = False

        files_to_commit = self.git_handler.status()

        for line in files_to_commit:

            if 'Changes to be committed' in line:
                add_to_check_list = True
            elif 'Untracked files' in line or 'Changes not staged for commit' in line:
                add_to_check_list = False
            elif '.php~' in line:
                add_to_check_list = False

            if add_to_check_list is True and ('new file' in line or 'modified' in line):
                filename = self.configuration.get_project_path_value() + '/' + line.split(':')[1].strip()

                if self.configuration.get_ignore_view_files_value():
                    if any(view_files_extension in filename
                           for view_files_extension in
                           self.configuration.get_view_files_extensions_list()):
                        continue

                if self.configuration.get_ignore_js_files_value():
                    if any(js_files_extension in filename
                           for js_files_extension in
                           self.configuration.get_js_files_extensions_list()):
                        continue

#.........这里部分代码省略.........
开发者ID:xedinaska,项目名称:CodestyleAutochecker,代码行数:103,代码来源:preprocessor.py


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