Exemplo n.º 1
0
    def clone_remote_repo(url, path, rename=None, is_del_exit_dir=False):
        """
        克隆远程库到本地

        @decorators staticmethod

        @param {string} url - 远程库的地址
        @param {string} path - 本地主路径(不含repo目录)

        @param {string} rename=None - 本地目录重命名
        @param {bool} is_del_exit_dir=False - 如果本地目录已存在是否删除

        @returns {list} - 执行结果[returncode, msgstring]
            returncode - 0代表成功,其他代表失败
            msgstring - 要返回显示的内容
        """
        repo_name = rename
        if repo_name is None:
            repo_name = FCMMGitTools.get_remote_repo_name(url)
        full_path = os.path.realpath(path).rstrip('\\/') + '/'
        full_repo_path = full_path + repo_name

        # 删除已存在的目录
        if os.path.exists(full_repo_path):
            if is_del_exit_dir:
                FileTools.remove_dir(full_repo_path)
            else:
                print('path is already exists: %s !' % (full_repo_path))
                return [1, '']
        # 克隆远程库
        os.chdir(full_path)  # 转到目录下
        return FCMMTools.run_sys_cmd('git clone %s %s' % (url, repo_name))
Exemplo n.º 2
0
 def tearDown(self):
     """
     结束测试执行的销毁
     """
     os.chdir(self.current_path)
     FileTools.remove_dir(TEST_PATH)
     FileTools.remove_file('fcmm.json')
     return
Exemplo n.º 3
0
    def setUp(self):
        """
        启动测试执行的初始化
        """
        self.current_path = os.path.realpath('')
        if os.path.exists(TEST_PATH):
            FileTools.remove_dir(TEST_PATH)

        FileTools.create_dir(TEST_PATH)

        shutil.copyfile('../fcmm4git/fcmm.json', 'fcmm.json')

        fcmm.fcmm_init()
        return
Exemplo n.º 4
0
    def setUp(self):
        """
        启动测试执行的初始化
        """
        global TEST_PATH
        if os.path.exists(TEST_PATH):
            FileTools.remove_dir(TEST_PATH)

        FileTools.create_dir(TEST_PATH)

        # 删除临时和备份目录
        if os.path.exists(TEMP_PATH):
            FileTools.remove_dir(TEMP_PATH)

        if os.path.exists(BACKUP_PATH):
            FileTools.remove_dir(BACKUP_PATH)

        return
Exemplo n.º 5
0
    def test_init(self):
        """
        测试init
        """
        print('测试init')
        global TEST_PATH, TEST_REPO_URL, FCMM_PATH, TEMP_PATH, BACKUP_PATH
        # 常用参数
        root_dir = TEST_PATH + '/init/'
        test_repo_name = fcmm_git_cmd.FcmmGitCmd.get_remote_repo_name(
            TEST_REPO_URL)
        repo_dir = root_dir + test_repo_name + '/'

        # 准备远程环境
        print('准备远程环境')
        FileTools.create_dir(root_dir)
        os.chdir(root_dir)
        self.assertTrue(
            subprocess.run('git clone %s' % (TEST_REPO_URL),
                           shell=True).returncode == 0, '准备远程环境: clone命令处理失败')
        os.chdir(repo_dir)
        # 清空文件夹
        subprocess.run('git rm * -r', shell=True)
        repo_info = fcmm_git_cmd.FcmmGitCmd.get_repo_info(repo_dir)
        if repo_info['repo'].is_dirty():
            # 有修改,要提交及上传
            self.assertTrue(
                subprocess.run('git commit -m "fcmm4git test clear file"',
                               shell=True).returncode == 0, '准备远程环境: rm命令处理失败')
            self.assertTrue(
                subprocess.run('git push -f origin master',
                               shell=True).returncode == 0,
                '准备远程环境: push命令处理失败')

        os.chdir(root_dir)
        FileTools.remove_dir(repo_dir)

        # 测试本地目录上传服务器
        print('测试本地目录上传服务器')
        local_repo_name = 'local'
        local_repo_path = root_dir + local_repo_name + '/'
        FileTools.create_dir(local_repo_path)
        os.chdir(local_repo_path)
        subprocess.run(
            'echo "test local to remote: no pkg v0.1.2" > readme.md',
            shell=True)

        print('测试本地目录上传服务器,成功但不建立lb-pkg')
        self.assertTrue(
            subprocess.run(
                'python %s/fcmm.py init -b local -url %s -v v0.1.2 -force -n -r'
                % (FCMM_PATH, TEST_REPO_URL),
                shell=True).returncode == 0, '本地目录上传: init命令处理失败')
        # 检查处理情况,先是备份
        file_list = FileTools.get_filelist(
            path=BACKUP_PATH,
            regex_str=test_repo_name.replace('.', '\.') + '\.bak\..*\.tar')
        self.assertTrue(len(file_list) > 0, '本地目录上传: 备份文件不存在')
        # 分支信息
        repo_info = fcmm_git_cmd.FcmmGitCmd.get_repo_info(local_repo_path)
        has_pkg = False
        for branch in repo_info['repo'].branches:
            if branch.name == 'lb-pkg':
                has_pkg = True
                break
        self.assertFalse(has_pkg, '本地目录上传: 不应建立lb-pkg')

        print('测试本地目录上传服务器,非强制被拒绝')
        self.assertFalse(
            subprocess.run(
                'python %s/fcmm.py init -b local -url %s -v v0.0.9' %
                (FCMM_PATH, TEST_REPO_URL),
                shell=True).returncode == 0, '本地目录上传: init命令处理失败')

        print('测试本地目录上传服务器,成功并建立lb-pkg')
        subprocess.run(
            'echo "test local to remote: with pkg v0.0.9" > readme1.md',
            shell=True)
        FileTools.remove_file(local_repo_path + '.fcmm4git')
        FileTools.remove_file(local_repo_path + 'readme.md')
        self.assertTrue(
            subprocess.run(
                'python %s/fcmm.py init -b local -url %s -v v0.0.9 -force' %
                (FCMM_PATH, TEST_REPO_URL),
                shell=True).returncode == 0, '本地目录上传: init命令处理失败')
        # 检查处理情况,先是备份
        file_list = FileTools.get_filelist(
            path=BACKUP_PATH,
            regex_str=test_repo_name.replace('.', '\.') + '\.bak\..*\.tar')
        self.assertTrue(len(file_list) > 0, '本地目录上传: 备份文件不存在')
        # 分支信息
        repo_info = fcmm_git_cmd.FcmmGitCmd.get_repo_info(local_repo_path)
        has_pkg = False
        for branch in repo_info['repo'].branches:
            if branch.name == 'lb-pkg':
                has_pkg = True
                break
        self.assertTrue(has_pkg, '本地目录上传: 没有成功建立lb-pkg')

        print('测试从服务器下载并建立本地目录,远程已带有fcmm4git')
        local_repo_name = 'remote1'
        local_repo_path = root_dir + local_repo_name + '/'
        FileTools.create_dir(local_repo_path)
        os.chdir(local_repo_path)
        subprocess.run(
            'echo "test remote to local: no pkg v0.1.3" > readme.md',
            shell=True)
        self.assertTrue(
            subprocess.run(
                'python %s/fcmm.py init -b remote -url %s -v v0.1.3 -force -n'
                % (FCMM_PATH, TEST_REPO_URL),
                shell=True).returncode == 0, '服务器下载并建立本地目录: init命令处理失败')