def _add_depot_branch_infos_to_p4(self, ctx):
        '''
        If we created any new depot branches, 'p4 add' their branch-info
        file to Perforce. Does not submit.

        If we edited any existing depot branches, 'p4 edit' them.

        Return number of branch-info files added or edited.
        '''
        if not self.depot_branch_info_list:
            return

        add_path_list = []
        edit_path_list = []
        for dbi in self.depot_branch_info_list:
            config = dbi.to_config()
            depot_path = dbi.to_config_depot_path()
            local_path = p4gf_util.depot_to_local_path(depot_path, ctx.p4gf,
                                                       ctx.client_spec_gf)
            p4gf_util.ensure_dir(p4gf_util.parent_dir(local_path))
            p4gf_util.make_writable(local_path)
            with open(local_path, 'w') as f:
                config.write(f)
            if dbi.needs_p4add:
                add_path_list.append(local_path)
            else:
                edit_path_list.append(local_path)
            p4gf_config.clean_up_parser(config)
            del config

        success_list = self._p4_add_in_bites(ctx, add_path_list)
        success_list.extend(self._p4_sync_k_edit(ctx, edit_path_list))
        return len(success_list)
 def __exit__(self, _exc_type, _exc_value, _traceback):
     """Exit the runtime context."""
     if self.config:
         p4gf_config.clean_up_parser(self.config)
     if self.config_merged:
         p4gf_config.clean_up_parser(self.config_merged)
     return False
示例#3
0
    def _add_depot_branch_infos_to_p4(self, ctx):
        '''
        If we created any new depot branches, 'p4 add' their branch-info
        file to Perforce. Does not submit.

        If we edited any existing depot branches, 'p4 edit' them.

        Return number of branch-info files added or edited.
        '''
        if not self.depot_branch_info_list:
            return

        add_path_list = []
        edit_path_list = []
        for dbi in self.depot_branch_info_list:
            config      = dbi.to_config()
            depot_path  = dbi.to_config_depot_path()
            local_path  = p4gf_util.depot_to_local_path( depot_path
                                                       , ctx.p4gf
                                                       , ctx.client_spec_gf )
            p4gf_util.ensure_dir(p4gf_util.parent_dir(local_path))
            p4gf_util.make_writable(local_path)
            with open(local_path, 'w') as f:
                config.write(f)
            if dbi.needs_p4add:
                add_path_list.append(local_path)
            else:
                edit_path_list.append(local_path)
            p4gf_config.clean_up_parser(config)
            del config

        success_list = self._p4_add_in_bites(ctx, add_path_list)
        success_list.extend(self._p4_sync_k_edit(ctx, edit_path_list))
        return len(success_list)
 def __exit__(self, _exc_type, _exc_value, _traceback):
     """Exit the runtime context."""
     if self.config:
         p4gf_config.clean_up_parser(self.config)
     if self.config_merged:
         p4gf_config.clean_up_parser(self.config_merged)
     return False
def depot_branch_info_from_string(dbi_string):
    """ Return DepotBranchInfo from string (from file contents)"""
    config = configparser.ConfigParser( interpolation  = None
                                      , allow_no_value = True )
    config.read_string(dbi_string)
    dbi = depot_branch_info_from_config(config)
    p4gf_config.clean_up_parser(config)
    return dbi
def depot_branch_info_from_string(dbi_string):
    """Return DepotBranchInfo from string (from file contents).

    :param dbi_string: the content to be parsed as a config file.

    Returns the depot branch info object, or None if the content produced
    no configuration values (i.e. ConfigParser.sections() yielded nothing).

    """
    config = configparser.ConfigParser(interpolation=None, allow_no_value=True)
    config.read_string(dbi_string)
    # detect if the file contained actual values
    if len(config.sections()) > 0:
        dbi = depot_branch_info_from_config(config)
    else:
        dbi = None
    p4gf_config.clean_up_parser(config)
    if dbi and not dbi.root_depot_path:
        LOG.debug(
            'error parsing DepotBranchInfo\ncontent={}\nresult={}'.format(
                dbi_string, dbi.dump()))
    return dbi
    def _add_branch_defs_to_p4(self, ctx):
        '''
        If we defined any new named+lightweight branches, update (or write the
        first revision of) this repo's p4gf_config2 file with all the
        currently defined named+lightweight branches.
        '''
        # Nothing to write? well maybe we have just deleted the remaining refs
        have_branches = bool(self.branch_list)

        # What does the file look like now?
        p4 = ctx.p4gf  # For less typing later.
        old_content = None
        new_content = None
        depot_path = p4gf_config.depot_path_repo2(ctx.config.view_name)
        local_path = p4gf_util.depot_to_local_path(depot_path, p4)
        depot_exists = False

        # 'p4 print' will fail if file doesn't exist yet. Okay.
        with ctx.p4gf.at_exception_level(p4.RAISE_NONE):
            b = p4gf_util.print_depot_path_raw(p4, depot_path)
            if b:
                old_content = b.decode()  # as UTF-8
                depot_exists = True

        # What do we want the file to look like? ConfigParser writes only to
        # file, not to string, so we have to give it a file path. Ooh! I know!
        # How about writing to the very file that we have to 'p4 add' or 'p4
        # edit' if its content differs?
        if have_branches:
            config = configparser.ConfigParser(interpolation=None)
            for b in self.branch_list:
                LOG.debug("add branch {0}".format(b))
                b.add_to_config(config)

            p4gf_util.ensure_dir(p4gf_util.parent_dir(local_path))
            p4gf_util.make_writable(local_path)
            with open(local_path, 'w') as f:
                config.write(f)
            with open(local_path, 'r') as f:
                new_content = f.read()
            p4gf_config.clean_up_parser(config)
            del config

        # Did nothing change? Then nothing to write.
        if p4gf_config.compare_configs_string(old_content, new_content):
            LOG.debug("No change to p4gf_config2 file")
            return False

        # Have to add or edit or delete the file.
        if not have_branches:
            ctx.p4gfrun(['sync', '-fkq', depot_path])
            ctx.p4gfrun(['delete', depot_path])
            LOG.debug("Deleted p4gf_config2 file")
        else:
            if depot_exists:
                ctx.p4gfrun(['sync', '-fkq', depot_path])
                ctx.p4gfrun(['edit', depot_path])
                LOG.debug("Edited p4gf_config2 file")
            else:
                ctx.p4gfrun(['add', '-t', 'text', local_path])
                LOG.debug("Added  p4gf_config2 file")

        return True
示例#8
0
    def _add_branch_defs_to_p4(self, ctx):
        '''
        If we defined any new named+lightweight branches, update (or write the
        first revision of) this repo's p4gf_config2 file with all the
        currently defined named+lightweight branches.
        '''
        # Nothing to write? well maybe we have just deleted the remaining refs
        have_branches = bool(self.branch_list)

        # What does the file look like now?
        p4           = ctx.p4gf         # For less typing later.
        old_content  = None
        new_content  = None
        depot_path   = p4gf_config.depot_path_repo2(ctx.config.view_name)
        local_path   = p4gf_util.depot_to_local_path(depot_path, p4)
        depot_exists = False

        # 'p4 print' will fail if file doesn't exist yet. Okay.
        with ctx.p4gf.at_exception_level(p4.RAISE_NONE):
            b = p4gf_util.print_depot_path_raw(p4, depot_path)
            if b:
                old_content = b.decode()    # as UTF-8
                depot_exists = True

        # What do we want the file to look like? ConfigParser writes only to
        # file, not to string, so we have to give it a file path. Ooh! I know!
        # How about writing to the very file that we have to 'p4 add' or 'p4
        # edit' if its content differs?
        if have_branches:
            config = configparser.ConfigParser(interpolation=None)
            for b in self.branch_list:
                LOG.debug("add branch {0}".format(b))
                b.add_to_config(config)

            p4gf_util.ensure_dir(p4gf_util.parent_dir(local_path))
            p4gf_util.make_writable(local_path)
            with open(local_path, 'w') as f:
                config.write(f)
            with open(local_path, 'r') as f:
                new_content = f.read()
            p4gf_config.clean_up_parser(config)
            del config

        # Did nothing change? Then nothing to write.
        if p4gf_config.compare_configs_string(old_content, new_content):
            LOG.debug("No change to p4gf_config2 file")
            return False

        # Have to add or edit or delete the file.
        if not have_branches:
            ctx.p4gfrun(['sync', '-fkq', depot_path])
            ctx.p4gfrun(['delete', depot_path])
            LOG.debug("Deleted p4gf_config2 file")
        else:
            if depot_exists:
                ctx.p4gfrun(['sync', '-fkq', depot_path])
                ctx.p4gfrun(['edit', depot_path])
                LOG.debug("Edited p4gf_config2 file")
            else:
                ctx.p4gfrun(['add', '-t', 'text',  local_path])
                LOG.debug("Added  p4gf_config2 file")

        return True