Example #1
0
        def GetNodeHash(self, node):
            """
            return the hash value of node
            node hash value = hash(module_cvspath) + hash(BROC) + hash(module tag/branch type) + hash(module tag/branch name)
            Args:
                node : the BrocNode object
            """
            key = None
            if node.module.br_kind == BrocModule_pb2.Module.TAG:
                key = node.module.module_cvspath + str(
                    node.module.br_kind) + node.module.tag_name
            else:
                key = node.module.module_cvspath + str(
                    node.module.br_kind) + node.module.br_name

            return Function.CalcHash(key)
Example #2
0
        def _download_broc(self, node):
            """
            download BROC file from repository
            Args:
                node : the BrocNode object
            Returns:
                return abs path of BROC file if download success
                return None if download failed
            """
            broc_path = None
            cmd = None
            # for svn
            # Log.Log().LevPrint("MSG", 'download BROC %s' % node.module.url)
            if node.module.repo_kind == BrocModule_pb2.Module.SVN:
                hash_value = Function.CalcHash(node.module.url)
                broc_url = os.path.join(node.module.url, 'BROC')
                broc_path = os.path.join(self._broc_dir, "%s_BROC" % hash_value)
                if node.module.revision:
                    broc_url = "%s -r %s" % (broc_url, node.module.revision)
                cmd = "svn export %s %s" % (broc_url, broc_path)
            else:
                # for GIT
                cmd = ""
                broc_path = os.path.join(node.module.workspace, node.module.module_cvspath, 'BROC')
                broc_dir = os.path.dirname(broc_path)
                if not os.path.exists(broc_path):
                    cmd += "git clone %s %s" \
                          % ("%s.git" % node.module.url, "%s" % broc_dir)

                    if node.module.br_name and node.module.br_name != 'master':
                        br_name = node.module.br_name
                        cmd += " && cd %s && (git checkout %s || (git fetch origin %s:%s && git checkout %s))" \
                               % (broc_dir, br_name, br_name, br_name, br_name)
                    elif node.module.tag_name:
                        tag_name = node.module.tag_name
                        cmd += " && cd %s && (git checkout %s || (git fetch origin %s:%s && git checkout %s))" \
                               % (broc_dir, tag_name, tag_name, tag_name, tag_name)

            if cmd:
                Log.Log().LevPrint("MSG", "Getting BROC(%s) ..." % cmd)
                ret, msg = Function.RunCommand(cmd)
                if ret != 0:
                    Log.Log().LevPrint("ERROR", msg)
                    return None

            return broc_path