示例#1
0
 def handle_configs(self, s, parent):
     """
     Args:
         s : xx@xx@xx set at tag CONFIGS
         parent : the BrocNode object
     """
     if s in self._checked_configs:
         return
     tree = BrocTree.BrocTree()
     repo_domain = BrocConfig.BrocConfig().RepoDomain(parent.module.repo_kind)
     postfix_branch = BrocConfig.BrocConfig().SVNPostfixBranch()
     postfix_tag = BrocConfig.BrocConfig().SVNPostfixTag()
     child_module = PlanishUtil.ParseConfig(s,
                                    parent.module.workspace,
                                    parent.module.dep_level + 1,
                                    parent.module.repo_kind,
                                    repo_domain,
                                    postfix_branch,
                                    postfix_tag)
     # Log.Log().LevPrint("MSG", 'create node(%s), level %d' % (s, child_module.dep_level))
     child_node = BrocTree.BrocNode(child_module, parent, False)
     parent.AddChild(child_node)
     self.AddNode(child_node)
     self._queue.put(child_node)
     self._checked_configs.add(s)
示例#2
0
 def test_singleton(self):
     """
     Test singleton interface 
     """
     logger = Log.Log()
     repo_domain = 'https://github.com'
     postfix = ['trunk', 'BRANCH', 'PD_BL']
     root = PlanishUtil.CreateBrocModuleFromDir("..", repo_domain,
                                                postfix[1], postfix[2],
                                                logger)
     tree = BrocTree.BrocTree()
     tree.SetRoot(root)
     tree1 = BrocTree.BrocTree()
     tree2 = BrocTree.BrocTree()
     self.assertEqual(tree.Id(), tree1.Id())
     self.assertEqual(tree.Id(), tree2.Id())
示例#3
0
    def DoPlanish(self, download_flag=True):
        """
        choose one version from multiple version of module
        Args:
            download_flag : whether download the code of module, if it is set True download code, and vice versa
        Returns:
            return True if planish successfully, otherwise return False
        """
        self.logger.LevPrint('MSG', 'Analyzing dependency ...')
        # create dependent tree
        broc_loader = Syntax.BrocLoader()
        try:
            broc_loader.LoadBROC()
        except BaseException as err:
            self.logger.LevPrint('ERROR', '%s' % err)
            return False
        if len(broc_loader.LackBrocModules()) != 0:
            self.logger.LevPrint('ERROR',
                                 "Can't find BROC in following module(s):")
            for cvspath in broc_loader.LackBrocModules():
                self.logger.LevPrint('ERROR', "\t%s" % cvspath)
            return False
        # check graph has circles
        (ret, msg) = BrocTree.BrocTree().HasCircle()
        if ret:
            self.logger.LevPrint(
                "ERROR",
                "There is a circle in dependency graph\nCircle is [%s]" % msg,
                False)
            return False

        nodes = Syntax.BrocLoader().AllNodes()
        for k, nodes in nodes.iteritems():
            for node in nodes:
                # jump main module itself
                if node.module.is_main:
                    continue
                if node.module.module_cvspath not in self.planished_nodes:
                    self.planished_nodes[node.module.module_cvspath] = node
                else:
                    reserved_node = self.planished_nodes[
                        node.module.module_cvspath]
                    ret = self._filter_dep_nodes(reserved_node, node)
                    if ret == 1:
                        self.planished_nodes[node.module.module_cvspath] = node
                    if ret == -1:
                        self.logger.LevPrint("ERROR", "dependent conficts(%s PK %s)" % \
                                             (reserved_node.module.origin_config, \
                                             node.module.origin_config), False)
                        return False

        self.logger.LevPrint('MSG', 'Analyzing dependency success')
        # dump planished dependency tree
        self.Dump()
        if download_flag:
            return self._download_modules()
        else:
            return True
示例#4
0
 def SetRoot(self, root):
     """
     Args:
         root : the BrocNode object
     """
     if not self._root:
         self._root = root
         BrocTree.BrocTree().SetRoot(root)
         self._queue.put(root)
示例#5
0
 def handle_configs(self, s, parent):
     """
     Args:
         s : xx@xx@xx set at tag CONFIGS 
         parent : the BrocNode object
     """
     if s in self._checked_configs:
         return 
     tree = BrocTree.BrocTree()
示例#6
0
 def Dump(self):
     """
     save the infos of dependent modules that have planished into file
     """
     config_file = os.path.join(
         BrocTree.BrocTree().Root().module.workspace,
         BrocTree.BrocTree().Root().module.module_cvspath,
         ".BROC.PLANISHED.DEPS")
     config_list = []
     for k in self.planished_nodes:
         config_list.append(self.planished_nodes[k].module.origin_config)
     try:
         with open(config_file, 'w') as f:
             f.write("=========BROC PLANISNHED DEPENDENCY==========\n")
             f.write(BrocTree.BrocTree().Root().module.root_path + "\n\t")
             f.write("\n\t".join(config_list))
     except IOError as err:
         self.logger.LevPrint('ERROR',
                              'save planished dependency failed(%s)' % err)
示例#7
0
 def __init__(self, main_module, repo_domain, logger, postfix):
     """
     Args:
         main_module : the BrocModule_pb2.Module object representing the main module
         repo_domain : the domain name of repository
         logger : the log facility object
         postfix : the list of postfix [postfix_branche, postfix_tag]
     """
     Syntax.BrocLoader().SetRoot(BrocTree.BrocNode(main_module, None, True))
     self.logger = logger
     self.planished_nodes = dict()  # module cvspath --> BrocNode
示例#8
0
 def test_load_broc(self):
     """
     """
     logger = Log.Log()
     repo_domain = 'https://github.com'
     postfix = ['trunk', 'BRANCH', 'PD_BL']
     root = PlanishUtil.CreateBrocModuleFromDir("..", repo_domain,
                                                postfix[1], postfix[2],
                                                logger)
     node = BrocTree.BrocNode(root, None, True)
     Syntax.BrocLoader().SetRoot(node)
     Syntax.BrocLoader().LoadBROC()
     if Syntax.BrocLoader().LackBrocModules():
         print(Syntax.BrocLoader().LackBrocModules())
示例#9
0
    def _download_modules(self):
        """
        dnowload dependent module from repository
        Returns:
            download all modules successfully return True, otherwise return False
        """
        for k, node in self.planished_nodes.iteritems():
            if node.module.repo_kind == BrocModule_pb2.Module.SVN:
                # the infos of local code equal Node's info
                if os.path.exists(node.module.root_path):
                    if BrocTree.BrocTree().SameSvnNode(node):
                        continue
                    else:
                        dst = "%s-%f" % (node.module.root_path, time.time())
                        self.logger.LevPrint(
                            "WARNING", "local code doesn't match BROC, \
reload it(%s)" % (node.module.origin_config))
                        Function.MoveFiles(node.module.root_path, dst)

                # generate command donwloading code from repository
                cmd = None
                url = node.module.url
                if node.module.revision:
                    url = "%s -r %s --force" % (url, node.module.revision)
                else:
                    url = "%s --force" % url
                cmd = "svn checkout %s %s" % (url, node.module.root_path)
            else:
                # for git
                cmd = "cd %s" % node.module.module_cvspath
                if node.module.tag_name:
                    tag_name = node.module.tag_name
                    cmd += " && (git checkout %s || (git fetch origin %s:%s && git checkout %s))" \
                           % (tag_name, tag_name, tag_name, tag_name)
                elif node.module.br_name:
                    br_name = node.module.br_name
                    if br_name != "master":
                        cmd += " && (git checkout %s || (git fetch origin %s:%s && git checkout %s))" \
                               % (br_name, br_name, br_name, br_name)
                    else:
                        cmd += " && git checkout master"

            self.logger.LevPrint("MSG", "%s" % cmd)
            ret, msg = Function.RunCommand(cmd)
            if ret != 0:
                self.logger.LevPrint("ERROR", "%s failed(%s)" % (cmd, msg))
                return False
        return True
示例#10
0
 def LoadBROC(self):
     """
     to run main module BROC file
     """
     # main thread to load BROC
     # first node is root node representing main module
     while not self._queue.empty():
         parent = self._queue.get()
         sys.argv = ['PLANISH', parent]
         broc_file = self._download_broc(parent)
         if not broc_file:
             self._lack_broc.add(parent.module.origin_config)
             continue
         try:
             execfile(broc_file)
         except BaseException as err:
             traceback.print_exc()
     # print dependent tree
     BrocTree.BrocTree().Dump()
示例#11
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))