Ejemplo n.º 1
0
 def test_split_cmd_para(self):
     """
     split_cmd_para
     """
     cmd_para = 'a1 -b1 -c1 c1value  d1 -c2'
     want_obj = {'a1': '', '-b1': '', '-c1': 'c1value', 'd1': '', '-c2': ''}
     real_obj = FCMMTools.split_cmd_para(cmd_para)
     self.assertDictEqual(want_obj, real_obj, 'split_cmd_para失败')
     return
Ejemplo n.º 2
0
    def main_cmd_fun(cmd='', cmd_para=''):
        """
        主含函数入口,所有命令都是走这个函数进行处理

        @decorators staticmethod

        @param {string} cmd='' - 命令
        @param {string} cmd_para='' - 参数字符串

        @returns {list} - 执行结果[returncode, msgstring]
            returncode - 0代表成功,其他代表失败
            msgstring - 要返回显示的内容
        """
        back_obj = [0, '']
        # 通过switch字典实现switch的代码
        switch = {
            'cd': FCMMGitCmd.cmd_cd,
            'help': FCMMGitCmd.cmd_help,
            'init': FCMMGitCmd.cmd_init,
            'add-pkg': FCMMGitCmd.cmd_add_pkg,
            'add-dev': FCMMGitCmd.cmd_add_dev,
            'add-temp': FCMMGitCmd.cmd_add_temp,
            'rollback': FCMMGitCmd.cmd_rollback,
            'check': FCMMGitCmd.cmd_check
        }
        try:
            dict_cmd_para = FCMMTools.split_cmd_para(cmd_para)
            if 'h' in dict_cmd_para.keys() or 'help' in dict_cmd_para.keys():
                # 只是返回帮助文档
                back_obj = FCMMGitCmd.cmd_help({"cmd": ""})
            else:
                back_obj = switch[cmd](dict_cmd_para)
        except Exception as e:
            back_obj[0] = -1
            back_obj[1] = 'execute "%s %s" error : \n%s' % (
                cmd, cmd_para, traceback.format_exc())

        return back_obj