示例#1
0
    def _valid_branches(self):
        """Check if branch definitions in config file are valid."""
        # validation requires use of some settings merged in from the global config
        # for example [@features]
        config = self.config
        # Does the config contain any branch sections?
        sections = self.config.branch_sections()
        if not sections:
            self._report_error(_('repository configuration missing branch ID\n'))
            return False

        self._check_duplicate_branches(sections)

        if LOG.isEnabledFor(logging.DEBUG3):
            # config contents are too lengthy for debug level
            cfg_text = p4gf_config.to_text("", p4gf_config.GlobalConfig.instance())
            LOG.debug3('global config: %s', cfg_text)
        # check branch creation option
        try:
            config.getboolean(p4gf_config.SECTION_GIT_TO_PERFORCE,
                              p4gf_config.KEY_ENABLE_BRANCH_CREATION)
        except ValueError:
            self._report_error(_("repository configuration option '{key}' has illegal value\n")
                               .format(key=p4gf_config.KEY_ENABLE_BRANCH_CREATION))

        # check merge commits option
        try:
            config.getboolean(p4gf_config.SECTION_GIT_TO_PERFORCE,
                              p4gf_config.KEY_ENABLE_MERGE_COMMITS)
        except ValueError:
            self._report_error(_("repository configuration option '{key}' has illegal value\n")
                               .format(key=p4gf_config.KEY_ENABLE_MERGE_COMMITS))

        # check read-only option
        try:
            config.getboolean(p4gf_config.SECTION_REPO, p4gf_config.KEY_READ_ONLY, fallback=False)
        except ValueError:
            self._report_error(_("repository configuration option '{key}' has illegal value\n")
                               .format(key=p4gf_config.KEY_READ_ONLY))

        # Examine them and confirm they have branch views and all RHS match
        enable_mismatched_rhs = \
            config.getboolean(p4gf_config.SECTION_REPO,
                              p4gf_config.KEY_ENABLE_MISMATCHED_RHS,
                              fallback=False)
        first_branch = None
        for section in sections:
            branch = self._valid_branch(config.repo_config, section, first_branch)
            if not branch:
                return False

            if not enable_mismatched_rhs and not first_branch:
                first_branch = branch

        error_msg = self._validate_view_lines_using_p4_client()
        if error_msg:
            self._report_error(error_msg)
            return False

        return True
 def _report_error(self, msg):
     '''Report error message, including path to offending file'''
     if not self.report_count:
         sys.stderr.write(_("error: invalid configuration file: '{}'\n")
                          .format(self.config_file_path))
         contents = p4gf_config.to_text('', self.config) if self.config else ''
         LOG.debug('config {} contents: ' + contents)
     self.report_count += 1
     LOG.error("Config {} has error: {}".format(self.config_file_path, msg))
     sys.stderr.write(_('error: {}').format(msg))
示例#3
0
 def _report_error(self, msg):
     """Report error message, including path to offending file."""
     if not self.report_count:
         sys.stderr.write(_("error: invalid configuration file: '{config_source}'\n")
                          .format(config_source=self.config.repo_config_source))
         if LOG.isEnabledFor(logging.DEBUG):
             contents = p4gf_config.to_text('', self.config.repo_config)
             LOG.debug('config contents: %s', contents)
     self.report_count += 1
     LOG.error("Config {} has error: {}".format(self.config.repo_config_source, msg))
     sys.stderr.write(_('error: {error}').format(error=msg))
 def _report_error(self, msg):
     '''Report error message, including path to offending file'''
     if not self.report_count:
         sys.stderr.write(
             _("error: invalid configuration file: '{}'\n").format(
                 self.config_file_path))
         contents = p4gf_config.to_text('',
                                        self.config) if self.config else ''
         LOG.debug('config {} contents: ' + contents)
     self.report_count += 1
     LOG.error("Config {} has error: {}".format(self.config_file_path, msg))
     sys.stderr.write(_('error: {}').format(msg))
    def write_dbi(self, dbi):
        """Write a depot branch-info file to our payload."""
        dbi_config = dbi.to_config()
        no_comment_header = ""
        dbi_str = p4gf_config.to_text(no_comment_header, dbi_config)
        dbi_bytes = dbi_str.encode("utf-8")

        self._add_gmchange_rev(depot_path=dbi.to_config_depot_path(),
                               md5=hashlib.md5(dbi_bytes).hexdigest().upper(),
                               raw_bytes=dbi_bytes,
                               lbr_file_type=p4gf_p4dbschema.FileType.CTEXT,
                               lbr_rev_change_num=1)
示例#6
0
    def _valid_branches2(self):
        """Check if branch definitions in config file are valid.

        Returns branch if valid, else None
        """
        # validation requires use of some settings merged in from the global config
        # for example [@features]
        config = self.config
        # Does the config contain any branch sections?
        sections = self.config.branch_sections2()
        if not sections:
            self._report_error(_('repository configuration missing branch ID\n'))
            return False

        if LOG.isEnabledFor(logging.DEBUG3):
            # config contents are too lengthy for debug level
            cfg_text = p4gf_config.to_text("", p4gf_config.GlobalConfig.instance())
            LOG.debug3('global config: %s', cfg_text)

        # Examine them and confirm they have branch views and all RHS match
        enable_mismatched_rhs = \
            config.getboolean(p4gf_config.SECTION_REPO,
                              p4gf_config.KEY_ENABLE_MISMATCHED_RHS,
                              fallback=False)
        first_branch = None
        for section in sections:
            branch = self._valid_branch(config.repo_config2, section, first_branch)
            if not branch:
                return False

            if not enable_mismatched_rhs and not first_branch:
                first_branch = branch

        error_msg = self._validate_view_lines_using_p4_client()
        if error_msg:
            self._report_error(error_msg)
            return False

        return True