Пример #1
0
 def setUp(self):
     """
     init
     """
     sys.argv = ['NOT PLANISH']
     module = BrocModule_pb2.Module()
     module.name = 'broc'
     module.module_cvspath = 'baidu/broc'
     module.broc_cvspath = 'baidu/broc/BROC'
     module.is_main = True
     module.repo_kind = BrocModule_pb2.Module.GIT
     module.revision = "1234"
     module.last_changed_rev = "1236"
     module.dep_level = 0
     #get home dir
     home = os.environ['HOME']
     module.workspace = '%s/unittest_broc/workspace' % home
     module.root_path = '%s/unittest_broc/workspace/baidu/broc' % home
     module.url = 'https://github.com/baidu/broc'
     module.br_kind = BrocModule_pb2.Module.BRANCH
     module.br_name = 'trunk'
     #module.commit_id = '5d9819900c2781873aa0ffce285d5d3e75b072a8'
     self._module = module
     Function.RunCommand("mkdir -p %s" % module.root_path, ignore_stderr_when_ok = True)
     Function.RunCommand("touch %s/hello.cpp" % module.root_path, ignore_stderr_when_ok = True)
     Function.RunCommand("touch %s/hello.h" % module.root_path, ignore_stderr_when_ok = True)
     self._env = Environment.Environment(module)
     Environment.SetCurrent(self._env)
Пример #2
0
def CreateGitModule(config, dep_level, workspace, repo_domain):
    """
    to create a BrocModule_pb2.Module object whose repo_kind is BrocModule_pb2.Module.GIT
    Args:
        config : a str object whose format is cvspath@branch_name@key_word_branch or cvspath@tag_name@key_word_tag
        dep_level : int value representing dependent level
        workspace : the abs path of worksapce, ie $WORKSPACE
        repo_domain : the domain name of repository server
    Returns:
        return a BrocModule_pb2.Module object 
    Raise:
        PlanishError exception
    """
    infos = config.split('@')
    if len(infos) < 3 or infos[2] not in ['branch', 'tag']:
        raise PlanishError("%s is illegal" % config)

    module = BrocModule_pb2.Module()
    # if 'ub' is module name, infos[0] format can be 'ub', 'xx/ub' or 'xx/xx/ub', ...
    module.module_cvspath = infos[0]
    module.name = infos[0].split('/')[-1]
    module.repo_kind = BrocModule_pb2.Module.GIT
    module.is_main = False
    module.broc_cvspath = os.path.join(module.module_cvspath, 'BROC')
    module.dep_level = dep_level
    module.workspace = workspace
    module.root_path = os.path.join(workspace, module.module_cvspath)
    module.url = os.path.join(repo_domain, infos[0])
    module.origin_config = config
    if infos[2] == 'branch':
        module.br_kind = BrocModule_pb2.Module.BRANCH
        module.br_name = infos[1]
    else:
        module.br_kind = BrocModule_pb2.Module.TAG
        module.tag_name = infos[1]

    return module
Пример #3
0
def CreateBrocModuleFromDir(target_path, repo_domain, postfix_branch,
                            postfix_tag, logger):
    """
    create one BrocModule_pb2.Module object from a existing directory 
    Args:
        target_path : the abs path of a directory
        repo_domain : the domain name of repository
        postfix_branch : a string object representint the postfix of branch
        postfix_tag : a string object representint the postfix of tag
        logger : the object of Log.Log
    Returns:
        return a BrocModule_pb2.Module object when creating successfully, 
        if fail to create, PlanishError is raised
    """
    # check BROC file
    broc_file = os.path.normpath(os.path.join(target_path, 'BROC'))
    if not os.path.exists(broc_file):
        raise PlanishError("No BROC file founded in %s" % target_path)

    # get infos form directory target_path
    repo_kind = None
    module_infos = None
    if RepoUtil.IsUnderSvnControl(target_path):
        repo_kind = BrocModule_pb2.Module.SVN
        module_infos = RepoUtil.GetSvnUrlInfos(target_path, postfix_branch,
                                               postfix_tag,
                                               ['trunk', 'branches', 'tags'],
                                               repo_domain, logger)
    elif RepoUtil.IsUnderGitControl(target_path):
        repo_kind = BrocModule_pb2.Module.GIT
        module_infos = RepoUtil.GetGitUrlInfos(target_path, repo_domain,
                                               logger)
    else:
        raise PlanishError("%s is not under version control" % target_path)

    if not module_infos['result']:
        raise PlanishError("get module infos from dir(%s) failed" %
                           target_path)

    module = BrocModule_pb2.Module()
    module.name = module_infos['name']
    module.module_cvspath = module_infos['module_cvspath']
    module.broc_cvspath = module_infos['broc_cvspath']
    module.workspace = module_infos['workspace']
    module.root_path = module_infos['root_path']
    # default is not main module
    module.is_main = True
    module.repo_kind = repo_kind
    module.url = module_infos['url']
    if module_infos['br_kind'] in ['TRUNK', 'BRANCH']:
        module.br_kind = BrocModule_pb2.Module.BRANCH
    else:
        module.br_kind = BrocModule_pb2.Module.TAG
    module.br_name = module_infos['br_name']
    module.tag_name = module_infos['tag_name']
    if repo_kind == BrocModule_pb2.Module.GIT:
        module.commit_id = module_infos['commit_id']
    else:
        module.revision = module_infos['revision']
        module.last_changed_rev = module_infos['last_changed_rev']
    # main module don't care the following infos
    module.origin_config = ""
    module.highest_version = ""
    module.lowest_version = ""
    return module
Пример #4
0
def CreateSvnModule(config, dep_level, workspace, repo_domain, repo_kind,
                    postfix_branch, postfix_tag):
    """
    to create a BrocModule_pb2.Module object whose repo_kind is BrocModule_pb2.Module.SVN
    Args:
        config : a str object whose format just like xx@xx, xx@xx@xx
        dep_level : int value representing dependent level
        workspace : the abs path of worksapce, ie $WORKSPACE
        repo_domain : the domain name of repository server
        postfix_branch : the branch postfix, for example 'BRANCH'
        postfix_tag : the tag postfix, for example 'PD_BL'
    Returns:
        return a BrocModule_pb2.Module object 
    Raise:
        PlanishError exception
    """
    # infos = [module cvs path, branch name, version or tag name]
    infos = config.split('@')
    if len(infos) < 2:
        raise PlanishError("%s is illegal" % config)

    module = BrocModule_pb2.Module()
    module_cvspath = infos[0]
    module_branch = infos[1]
    module_version = None

    module.name = module_cvspath.split('/')[-1]
    module.module_cvspath = module_cvspath
    module.broc_cvspath = os.path.join(module_cvspath, 'BROC')
    module.is_main = False
    module.repo_kind = repo_kind
    module.dep_level = dep_level
    module.workspace = workspace
    module.root_path = os.path.join(workspace, module_cvspath)
    module.origin_config = config
    try:
        module.br_kind = ParseBranch(module_branch, repo_kind, postfix_branch,
                                     postfix_tag)
    except PlanishError:
        raise PlanishError("%s is illegal" % config)

    # check revision
    if len(infos) == 3:
        module.revision = infos[2]
    else:
        # default revision is empty
        module.revision = ''
    cvs_prefix = '/'.join(module_cvspath.split('/')[:-1])
    if module.br_kind == BrocModule_pb2.Module.TAG:
        module.tag_name = module_branch
        module.url = os.path.join(repo_domain, cvs_prefix, 'tags', module.name,
                                  module_branch)
    else:
        module.br_name = module_branch
        if module_branch == 'trunk':
            module.url = os.path.join(repo_domain, cvs_prefix, 'trunk',
                                      module.name)
        else:
            module.url = os.path.join(repo_domain, cvs_prefix, 'branches',
                                      module.name, module_branch)
    return module
Пример #5
0
 def test_svn_FilterDepNodes(self):
     """
     test Plansh._filter_dep_nodes
     """
     #init
     logger = Log.Log()
     root_node = BrocModule_pb2.Module()
     repo_domain = 'https://github.com'
     postfix = ["trunk", "_BRANCH", "_PD_BL"]
     planish = Planish.Planish(root_node, repo_domain, logger, postfix)
     reserved = BrocModule_pb2.Module()
     coming = BrocModule_pb2.Module()
     first_node = BrocTree.BrocNode(reserved, root_node, False)
     second_node = BrocTree.BrocNode(coming, root_node, False)
     #dep_Level is 1 VS dep_level is 1
     first_node.module.dep_level = 1
     first_node.module.dep_level = 1
     #tags VS BRANCH
     first_node.module.br_kind = BrocModule_pb2.Module.TAG
     second_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     first_node.module.tag_name = 'ub_1-1-1-1_PD_BL'
     second_node.module.br_name = 'ub_1-0-0_BRANCH'
     self.assertEqual(-1, planish._filter_dep_nodes(first_node, second_node))
     #dep_level is 1 VS dep_level is 2 or more
     first_node.module.dep_level = 1
     second_node.module.dep_level = 2
     #tags VS tags
     first_node.module.br_kind = BrocModule_pb2.Module.TAG
     second_node.module.br_kind = BrocModule_pb2.Module.TAG
     #1-1-1-1 VS 2-2-2-2
     first_node.module.tag_name = 'ub_1-1-1-1_PD_BL'
     second_node.module.tag_name = 'ub_2-2-2-2_PD_BL'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #1-10-0-0 VS 1-9-0-0
     first_node.module.tag_name = 'ub_1-10-0-0_PD_BL'
     second_node.module.tag_name = 'ub_1-9-0-0_PD_BL'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #BRANCH VS BRANCH
     first_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     second_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     #1-0-0_BRANCH VS 1-0-1_BRANCH
     first_node.module.br_name = 'ub_1-0-0_BRANCH'
     second_node.module.br_name = 'ub_1-0-1_BRANCH'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #1-0-0_BRANCH@12345 VS 1-0-0_BRANCH@12346
     first_node.module.br_name = 'ub_1-0-0_BRANCH'
     second_node.module.br_name = 'ub_1-0-0_BRANCH'
     first_node.module.revision = '12345'
     second_node.module.revision = '12346'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #1-0-0_BRANCH@12345 VS 1-0-0_BRANCH@234
     second_node.module.revision = '234'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #tags VS BRANCH
     first_node.module.br_kind = BrocModule_pb2.Module.TAG
     second_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     first_node.module.tag_name = 'ub_1-1-1-1_PD_BL'
     second_node.module.br_name = 'ub_1-0-0_BRANCH'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #dep_level is 2 or more VS dep_level is 2 or more
     first_node.module.dep_level = 2
     second_node.module.dep_level = 2
     #tags VS tags
     first_node.module.br_kind = BrocModule_pb2.Module.TAG
     second_node.module.br_kind = BrocModule_pb2.Module.TAG
     #1-1-1-1 VS 2-2-2-2
     first_node.module.tag_name = 'ub_1-1-1-1_PD_BL'
     second_node.module.tag_name = 'ub_2-2-2-2_PD_BL'
     self.assertEqual(1, planish._filter_dep_nodes(first_node, second_node))
     #1-10-0-0 VS 1-9-0-0
     first_node.module.tag_name = 'ub_1-10-0-0_PD_BL'
     second_node.module.tag_name = 'ub_1-9-0-0_PD_BL'
     self.assertEqual(1, planish._filter_dep_nodes(first_node, second_node))
     #BRANCH VS BRANCH
     first_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     second_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     #1-0-0_BRANCH VS 1-0-1_BRANCH
     first_node.module.br_name = 'ub_1-0-0_BRANCH'
     second_node.module.br_name = 'ub_1-0-1_BRANCH'
     self.assertEqual(-1, planish._filter_dep_nodes(first_node, second_node))
     #1-0-0_BRANCH@12345 VS 1-0-0_BRANCH@12346
     first_node.module.br_name = 'ub_1-0-0_BRANCH'
     second_node.module.br_name = 'ub_1-0-0_BRANCH'
     first_node.module.revision = '12345'
     second_node.module.revision = '12346'
     self.assertEqual(1, planish._filter_dep_nodes(first_node, second_node))
     #1-0-0_BRANCH@12345 VS 1-0-0_BRANCH@234
     second_node.module.revision = '234'
     self.assertEqual(0, planish._filter_dep_nodes(first_node, second_node))
     #tags VS BRANCH
     first_node.module.br_kind = BrocModule_pb2.Module.TAG
     second_node.module.br_kind = BrocModule_pb2.Module.BRANCH
     first_node.module.tag_name = 'ub_1-1-1-1_PD_BL'
     second_node.module.br_name = 'ub_1-0-0_BRANCH'
     self.assertEqual(-1, planish._filter_dep_nodes(first_node, second_node))