Esempio n. 1
0
    def get_cardbin_info_with_json_format(self):
        # 先将原始lua文件读进来,并存储关键信息便于接下来进处理
        self.content = myfile.read_file_content(self.file_path,
                                                encoding_='utf-8')

        # 获取原始cardbin信息
        self.ori_card_info = self._get_card_info(self.content)
        # print(self.ori_card_info)

        # 转换成正常的json格式代码,先保留,后续有需要再使用
        # dst_array = []
        # for i in self.ori_card_info:
        #     item = {}
        #     for k in i:
        #         if i[k]:
        #             item[SIMPLIFY_MAP[k]] = i[k]
        #     dst_array.append(item)

        # if with_format:
        #     json_str = json.dumps(dst_array, ensure_ascii=False, sort_keys=True, indent=4)
        # else:
        #     json_str = json.dumps(dst_array, ensure_ascii=False)

        json_str = self._generate_card_info_table_with_js_format(
            self.ori_card_info)

        myfile.write_to_file(self.dst_path, json_str, encoding='utf-8')
 def _write_build_info(self):
     build_info_format = self.ori_build_config[BuildConfigLabel.BUILD_INFO_TEMPLET_FLAG]
     build_info = build_info_format.format(ver_name=self.whole_ver_name, code_ver=self.prj_code_ver,
                                           ver_code=self.ver_code)
     readme_file_name = 'readme-{}-{}.txt'.format(self.whole_ver_name, self.ver_code)
     build_info_path = os.path.join(self.output_directory, readme_file_name)
     file_util.write_to_file(build_info_path, build_info, encoding='utf-8')
Esempio n. 3
0
    def _update_json_file(self):
        src = open(self.file_path, encoding='utf-8')
        with src:
            obj = json.load(src)
            if self.is_pure:
                src_obj = obj
            else:
                src_obj = obj["interface"]
        
        src_obj = self._sort_array(src_obj)
#         src_obj.sort(key=self._cmp_item)
        
        if src_obj:
#             output = json.dumps(src_obj, ensure_ascii=False, sort_keys=True, indent=4)
#             output = re.sub('("describe":\s*"[^"]*")(\s*,\s+)("id":\s*"[^"]*")(\s*,)', self._replace_ptn, output)
            output = self._join_array(src_obj)
#             print(output)

        
        if not self.is_pure:
            src_content = myfile.read_file_content(self.file_path)
            self.array_str = output
            output = re.sub('("interface":\s*)(\[[^\]]*\])', self._replace_dst_ptn, src_content)
            
#         print('-' * 120)
#         print(output)
        myfile.write_to_file(self.file_path, output, 'utf-8')
Esempio n. 4
0
    def test_replace_string_in_file(self):
        test_name = 'gbk.txt'
        ori_data = '这是一个文件,用于进行测试。what are you doing.'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name

        expect_data = ori_data
        file_data = myfile.read_file_content(file_name)
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data))

        enc_result = myfile.detect_file_enc(file_name)
        expect_data = 'gb2312'
        encoding = enc_result['encoding'].lower()
        self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding))

        src_dst_list = list(zip(['what'], ['F**k']))
        enc_result = myfile.replace_string_in_file(file_name, src_dst_list)
        expect_data = '这是一个文件,用于进行测试。F**k are you doing.'
        file_data = myfile.read_file_content(file_name)
        self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data))

        enc_result = myfile.detect_file_enc(file_name)
        expect_data = 'gb2312'
        encoding = enc_result['encoding'].lower()
        self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding))

        myfile.write_to_file(file_name, ori_data, encoding)
Esempio n. 5
0
    def filter_duplicated_values(self, root_dir_path, dupicated_result,
                                 is_drawable_or_string):
        # 遍历所记录的重复字符串,若存在逗号拼接的,说明有重复的串,这时需要拼接并存到文件
        dupicated_content = []
        for result_key in dupicated_result.keys():
            result_value = dupicated_result[result_key]
            value_list = result_value.split(',')
            if len(value_list) > 1:
                if is_drawable_or_string:
                    dupicated_content.append('{}\n\n'.format(result_value))
                else:
                    dupicated_content.append('{}: {}\n\n'.format(
                        result_key, result_value))

        if len(dupicated_content) == 0:
            if is_drawable_or_string:
                print('没有找到重复的drawable资源.')
            else:
                print('没有找到重复的string资源.')
        else:
            file_name = '重复的字符串资源.txt'
            success_tip = '已将重复的字符串资源记录到文件,可在{}目录中查看.'
            if is_drawable_or_string:
                file_name = '重复的drawable资源.txt'
                success_tip = '已将重复的drawable资源记录到文件,可在{}目录中查看.'

            # 记录数据到本地文件
            root_parent_dir = os.path.join(os.path.dirname(root_dir_path))
            file_path = '{}\\{}'.format(root_parent_dir, file_name)
            myfile.write_to_file(file_path,
                                 ''.join(dupicated_content),
                                 encoding='utf-8')

            print(success_tip.format(root_parent_dir))
Esempio n. 6
0
    def setUp(self):
        self.temp_dir = tempfile.gettempdir()
        self.svn_name = 'txxy'
        self.svn_dir = os.path.join(self.temp_dir, self.svn_name)
        hooks_dir = 'hooks'
        self.dir_path = os.path.join(self.svn_dir, hooks_dir)

        self.normal = 'pre-commit_normal.cmd'
        self.refuse = 'pre-commit_refuse.cmd'
        self.target = 'pre-commit.cmd'

        if not os.path.isdir(self.dir_path):
            os.makedirs(self.dir_path)

        self.normal_str = 'a'
        self.refuse_str = 'b'
        self.normal_path = os.path.join(self.dir_path, self.normal)
        self.refuse_path = os.path.join(self.dir_path, self.refuse)
        self.target_path = os.path.join(self.dir_path, self.target)

        file_util.write_to_file(self.normal_path,
                                self.normal_str,
                                encoding='utf-8')
        file_util.write_to_file(self.refuse_path,
                                self.refuse_str,
                                encoding='utf-8')
Esempio n. 7
0
    def testExposed_switch_commit(self):
        token = 'abc'
        file_util.write_to_file(self.target_path,
                                self.normal_str,
                                encoding='utf-8')
        service = SvnService(self.temp_dir,
                             token=token,
                             normal=self.normal,
                             refuse=self.refuse,
                             target=self.target)
        code, _ = service.exposed_switch_commit(self.svn_name,
                                                True,
                                                token=token)
        self.assertEqual(code, svn_service.CODE_SUCCESS,
                         f'code: {code}, expect: {svn_service.CODE_SUCCESS}')

        code, _ = service.exposed_switch_commit(self.svn_name, True)
        self.assertEqual(
            code, svn_service.CODE_INVALID_TOKEN,
            f'code: {code}, expect: {svn_service.CODE_INVALID_TOKEN}')

        os.remove(self.target_path)
        code, _ = service.exposed_switch_commit(self.svn_name,
                                                True,
                                                token=token)
        self.assertEqual(code, svn_service.CODE_FAILED,
                         f'code: {code}, expect: {svn_service.CODE_FAILED}')
Esempio n. 8
0
def format_xml_file(file_path):
    header = myfile.read_file_first_line(file_path)
    root = ElementTree.parse(file_path).getroot()
    indent(root)
    #     ElementTree.dump(root)
    content = ElementTree.tostring(root, 'utf-8').decode()
    #     print(content)
    myfile.write_to_file(file_path, header + content, 'utf-8')
Esempio n. 9
0
    def update_multi_item(self, item_map):
        if item_map:
            for key in item_map:
                self._update_single_item_value(key, item_map[key])
                info = 'update string item {} with "{}".'.format(key, item_map[key])
                print(info)

        if self.config_modified:
            myfile.write_to_file(self.config_path, self.config_data, 'utf-8')
Esempio n. 10
0
    def update_multi_meta_data(self, meta_data_map):
        if meta_data_map:
            for key in meta_data_map:
                self._update_single_meta_data(key, meta_data_map[key])
                info = 'update meta_data {} with "{}".'.format(key, meta_data_map[key])
                print(info)

        if self.config_modified:
            myfile.write_to_file(self.config_path, self.config_data, 'utf-8')
Esempio n. 11
0
def format_xml_file_for_pretty(file_path):
    header = myfile.read_file_first_line(file_path)

    dom = minidom.parse(file_path)
    root = dom.documentElement

    pretty_xml_str = root.toprettyxml()
    #         print(pretty_xml_str)
    myfile.write_to_file(file_path, header + pretty_xml_str, 'utf-8')
Esempio n. 12
0
 def process(self):
     content = myfile.read_file_content(self.src, encoding_='utf-8')
     # content = open(self.src).read().decode('gb18030', 'ignore')
     # content = myfile.read_file_content(self.src)
     print(content)
     content = content.replace('\t', '|')
     content = content.replace('\r\n', '|\r\n|')
     content = '|' + content + '|'
     myfile.write_to_file(self.src, content, encoding='utf-8')
Esempio n. 13
0
    def update_single_item(self, name, value):
        self._update_single_item_value(name, value)
        if self.config_modified:
            info = 'update string item {} with "{}".'.format(name, value)
        else:
            info = 'string item {} remain as "{}".'.format(name, value)
        print(info)

        if self.config_modified:
            myfile.write_to_file(self.config_path, self.config_data, 'utf-8')
Esempio n. 14
0
 def update_setup_version(self, file_path, version):
     # example: version='0.0.2'
     re_ptn = '(version\s*=\s*[\'\"])([^\'\"]*)([\'\"])'
     src_data = file_util.read_file_content(file_path)
     new_data = re.sub(re_ptn, '\g<1>{}\g<3>'.format(version), src_data)
     if new_data != src_data:
         file_util.write_to_file(file_path, new_data, 'utf-8')
         return True
     else:
         return False
Esempio n. 15
0
 def update_init_version(self, file_path, version):
     # example: version_info = (0, 0, 9)
     re_ptn = '(version_info\s*=\s*\()(\d+(?:,\s*\d+){2})(\))'
     src_data = file_util.read_file_content(file_path)
     target_version = ', '.join(re.split('\.\s*', version))
     new_data = re.sub(re_ptn, f'\g<1>{target_version}\g<3>', src_data)
     if new_data != src_data:
         file_util.write_to_file(file_path, new_data, 'utf-8')
         return True
     else:
         return False
Esempio n. 16
0
    def test_write_to_file(self):
        content = "info to write"

        dst_name = r'file_output.txt'
        dst_file = myfile.get_real_dir(__modpath__) + os.sep + dst_name
        myfile.write_to_file(dst_file, content)

        readed_content = myfile.read_file_content(dst_file)

        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(content, readed_content, msg_format.format(content, readed_content))
Esempio n. 17
0
    def _write_build_info(self):
        build_info_format = self.ori_build_config[Label.build_info_template]
        build_info = build_info_format.format(ver_name=self.whole_ver_name,
                                              code_ver=self.prj_code_ver,
                                              formal_desc=self.formal_desc)
        readme_file_name = 'readme-{}.txt'.format(self.whole_ver_name)
        build_info_path = os.path.join(self.output_directory, readme_file_name)
        parent_dir = os.path.dirname(build_info_path)
        if not os.path.exists(parent_dir):
            os.makedirs(parent_dir)

        file_util.write_to_file(build_info_path, build_info, encoding='utf-8')
Esempio n. 18
0
def format_json_file(filepath):
    src = open(filepath, encoding='utf-8')
    with src:
        obj = json.load(src)

#             pprint.pprint(obj)
#             print('-'*160)

    if obj:
        output = json.dumps(obj, ensure_ascii=False, sort_keys=True, indent=4)
        #         print(output)

        myfile.write_to_file(filepath, output, 'utf-8')
Esempio n. 19
0
 def update_coverage_switch(self, env_mode):
     file_path = os.path.join(self.prj_path, 'build.gradle')
     content = file_util.read_file_content(file_path, 'utf-8')
     coverage_label = 'testCoverageEnabled'
     ptn_str = '({}\s*=\s*)\w+(\s+)'.format(coverage_label)
     ptn = re.compile(ptn_str, flags=(re.I | re.M))
     value = self.info[ProjectBuilder.COVERAGE_FLAG][
         ProjectBuilder.COMPILE_FLAG][env_mode]
     new_content = ptn.sub('\\1{}\\2'.format(value), content)
     if new_content != content:
         file_util.write_to_file(file_path, new_content, 'utf-8')
         print('update {} with value {}.'.format(coverage_label, value))
     else:
         print('{} remain as {}.'.format(coverage_label, value))
Esempio n. 20
0
def get_file_list(file_dir, cnt=3):
    text_format = '测试文件0{}'
    file_path_format = 'file_0{}.txt'

    file_list = list()
    butt = cnt + 1
    for index in range(1, butt):
        dst_path = os.path.join(file_dir, file_path_format.format(index))
        text = text_format.format(index)
        file_util.write_to_file(dst_path, text, encoding='utf-8')
        file_item = dict()
        file_item[SenderLabel.PATH_FLAG] = dst_path
        file_item[SenderLabel.NAME_FLAG] = text
        file_list.append(file_item)

    return file_list
Esempio n. 21
0
def generate_test_card_info(rec_file_name, target_file_name):
    lines = myfile.read_file_lines(rec_file_name)
    recs = []
    rec_split_str = ','
    for line in lines:
        if line and not line.isspace():
            items = line.strip().split(rec_split_str)
            if items and len(items) > 2:
                rec_item = '  {{card="{}", name="{}", code={}}}'.format(
                    items[1], items[0], items[2])
                recs.append(rec_item)
            else:
                print('error: ' + items)
        else:
            print('error: ' + line)

    str_recs = ',\r\n'.join(recs)
    str_info = '{{\r\n{}\r\n}}'.format(str_recs)
    myfile.write_to_file(target_file_name, str_info, 'utf-8')
Esempio n. 22
0
def add_prefix_map_to_info(name_map_file, rec_file_name, target_file_name):
    map_lines = myfile.read_file_lines(name_map_file)
    name_map = {}
    for line in map_lines:
        if line and not line.isspace():
            items = line.split(',')
            if items and len(items) > 1:
                name_map[items[0].strip()] = items[1].strip()
            else:
                print('error: ' + items)
        else:
            print('error: ' + line)

    lines = myfile.read_file_lines(rec_file_name)

    recs = []
    for line in lines:
        if line and not line.isspace():
            ptn_str = '^\s*{\s*prefix\s*=\s*"(\d+)",\s*name\s*=\s*"([\u2e80-\ua4cf]+)",'
            ptn = re.compile(ptn_str)
            match_rlt = ptn.match(line)
            if match_rlt:
                k = match_rlt.group(1)
                name = match_rlt.group(2)

                rec_reserved = line.strip()
                if rec_reserved.endswith(','):
                    rec_reserved = rec_reserved[:-1]

                rec_reserved = rec_reserved[:-1]

                rec_item = '  {}, index={}}}'.format(rec_reserved,
                                                     name_map[name])
                recs.append(rec_item)
            else:
                print('error: ' + items)
        else:
            print('error: ' + line)

    str_info = ',\r\n'.join(recs)
    myfile.write_to_file(target_file_name, str_info, 'utf-8')
Esempio n. 23
0
    def process(self):
        git_flag = 'use_git'
        if not hasattr(self, git_flag):
            self.use_git = False

        code_url = self.ori_build_config[BuildConfigParser.ROOT_FLAG][
            BuildConfigParser.CODE_URL_FLAG]

        static_config_path = self.work_path + os.sep + self.ori_build_config[
            BuildConfigParser.ROOT_FLAG][BuildConfigParser.STATIC_FLAG]
        static_config_path = file_util.normalpath(static_config_path)

        main_prj_name = self.ori_build_config[
            BuildConfigParser.WORKSPACE_FLAG][BuildConfigParser.MAIN_FLAG]

        if self.use_git:
            self.project_code_path = os.path.join(self.project_path,
                                                  self.branch)
        else:
            self.project_code_path = self.project_path

        # 进行代码更新操作
        if self.to_update:
            if self.use_git:
                git.checkout_or_update(self.project_code_path, code_url,
                                       self.code_ver, self.branch)
            else:
                # 根据参数配置svn用户名和密码
                username_flag = 'svn_user'
                password_flag = 'svn_pwd'
                if hasattr(self, username_flag) and hasattr(
                        self, password_flag):
                    #                 print('{}: {}'.format(username_flag, self.svn_user))
                    #                 print('{}: {}'.format(password_flag, self.svn_pwd))
                    svn.set_user_info(getattr(self, username_flag),
                                      getattr(self, password_flag))

                # 先checkout svn库上代码,再更新和本地相关的配置文件
                checkout_or_update_single_item(self.project_code_path,
                                               code_url,
                                               revision=self.code_ver)

                # 更新gradle编译配置配置,新框架不再需要该步骤(20161110 17:39)
            #             gradle_setting_name = 'settings.gradle'
            #             gradle_setting_path = static_config_path + os.sep + gradle_setting_name
            #             update_gradle_setting(main_prj_path, gradle_setting_path)

        # 设置配置信息并获取当前代码版本号
        if self.use_git:
            self.prj_root = git.get_git_root(self.project_code_path)
            main_prj_path = os.path.join(self.prj_root, main_prj_name)
            self.code_ver = git.get_revision(self.prj_root)
        else:
            self.prj_root = self.project_code_path
            main_prj_path = os.path.join(self.project_code_path, main_prj_name)
            self.code_ver = svn.get_revision(self.project_code_path)
        print('current code version is ' + str(self.code_ver))

        if self.to_update:
            # 更新android sdk本地配置
            local_file_name = 'local.properties'
            local_build_file = os.path.join(static_config_path,
                                            local_file_name)
            target_build_file = os.path.join(self.prj_root, local_file_name)
            file_util.replace_file(local_build_file, target_build_file)

        # 进行版本编译操作
        if self.to_build:
            to_check_vals = ['ver_name', 'ver_code', 'ver_env']
            for name in to_check_vals:
                value = getattr(self, name)
                if not value:
                    info = 'Please specify the {}.'.format(name)
                    print(info)
                    exit(1)

            # 参数非空判断验证通过开始进行正式业务逻辑
            self.pro_build_config = self._get_pro_build_config()
            self.pre_build()

            if self.is_debug:
                mode_flag = apk_builder.DEBUG_FLAG
            else:
                mode_flag = apk_builder.RELEASE_FLAG

            mode = apk_builder.FLAG_MODE_MAP[mode_flag]

            workspace_map = self.ori_build_config[
                BuildConfigParser.WORKSPACE_FLAG]
            if BuildConfigParser.CHANNEL_INFO_FLAG in workspace_map:
                res_path = self.work_path + os.sep + workspace_map[
                    BuildConfigParser.CHANNEL_INFO_FLAG]
            else:
                res_path = None

            if hasattr(self, 'channel_file') and hasattr(self, 'channel'):
                if self.channel_file:
                    if not os.path.exists(self.channel_file):
                        print('not exist {}'.format(self.channel_file))
                        exit(1)

                    self.build_app(main_prj_path, self.channel_file, res_path,
                                   self.pro_build_config)
                else:
                    if self.channel:
                        chan_id = self.channel
                    else:
                        chan_id = ProjectBuilder.DEFAULT_CHAN

                    self.build_app(main_prj_path, None, res_path,
                                   self.pro_build_config, chan_id, mode)
            else:
                chan_id = ProjectBuilder.DEFAULT_CHAN
                self.build_app(main_prj_path, None, res_path,
                               self.pro_build_config, chan_id, mode)

            if os.path.exists(self.apk_output_path) and os.path.isfile(
                    self.apk_output_path):
                # 将编译信息写文件
                build_info_format = self.ori_build_config[
                    BuildConfigParser.BUILD_INFO_TEMPLET_FLAG]
                build_info = build_info_format.format(ver_name=self.ver_name,
                                                      code_ver=self.code_ver,
                                                      ver_code=self.ver_code)
                build_info_path = self.output_directory + os.sep + 'readme-{}-{}.txt'.format(
                    self.ver_name, self.ver_code)
                file_util.write_to_file(build_info_path,
                                        build_info,
                                        encoding='utf-8')

                target_name = os.path.basename(self.apk_output_path)
                to_upload_path = os.path.dirname(self.apk_output_path)
                source_name = os.path.basename(self.apk_output_path)

                # 有需要则先加固,再签名
                if ProjectBuilder.PROTECT_FLAG in self.pro_build_config and ProjectBuilder.SIGNER_FLAG in self.pro_build_config:
                    env_mode = self.pro_build_config[
                        ProjectBuilder.ENV_MODE_FLAG]
                    if self.pro_build_config[ProjectBuilder.PROTECT_FLAG][
                            ProjectBuilder.IS_NEED_FLAG][env_mode]:
                        ip = self.pro_build_config[
                            ProjectBuilder.PROTECT_FLAG][
                                ProjectBuilder.IP_FLAG]
                        user_name = self.pro_build_config[
                            ProjectBuilder.PROTECT_FLAG][
                                ProjectBuilder.USER_FLAG]
                        api_key = self.pro_build_config[
                            ProjectBuilder.PROTECT_FLAG][
                                ProjectBuilder.API_KEY_FLAG]
                        api_secret = self.pro_build_config[
                            ProjectBuilder.PROTECT_FLAG][
                                ProjectBuilder.API_SECRET_FLAG]
                        protected_path = protect_app.protect(
                            ip, user_name, api_key, api_secret,
                            self.apk_output_path)

                        if hasattr(self, 'to_align') and self.to_align:
                            aligned_path = file_util.get_middle_path(
                                protected_path)
                            apk_util.zipalign(protected_path, aligned_path)
                            to_sign_path = aligned_path
                        else:
                            to_sign_path = protected_path

                        keystore = os.path.join(
                            main_prj_path,
                            self.pro_build_config[ProjectBuilder.SIGNER_FLAG][
                                ProjectBuilder.KEYSTORE_FLAG])
                        storepass = self.pro_build_config[
                            ProjectBuilder.SIGNER_FLAG][
                                ProjectBuilder.STOREPASS_FLAG]
                        storealias = self.pro_build_config[
                            ProjectBuilder.SIGNER_FLAG][
                                ProjectBuilder.STOREALIAS_FLAG]
                        signed_path = apk_util.get_default_signed_path(
                            protected_path)
                        rtn = apk_util.sign_apk(keystore, storepass,
                                                storealias, to_sign_path,
                                                signed_path)
                        if rtn:
                            str_info = 'Protect {} and sign success.'.format(
                                self.apk_output_path)
                            source_name = os.path.basename(signed_path)
                        else:
                            str_info = 'Protect {} and sign failed!'.format(
                                self.apk_output_path)
                            raise Exception(str_info)

                        print(str_info)

                str_info = 'Build success, code version is {}.'.format(
                    self.code_ver)
                print(str_info)

                # 进行编译好的版本提交操作
                if hasattr(self, 'to_upload') and self.to_upload:
                    result = re.match(BuildManager.__APK_OUTPUT_PATH_PATTERN,
                                      target_name)
                    if result:
                        ver_name_info = result.group(1)
                    else:
                        str_info = 'The output file name {} is invalid!'.format(
                            target_name)
                        raise Exception(str_info)

                    #                     ftp_config_path = os.path.join(self.work_path, 'config')
                    ftp_config_path = self.work_path
                    print('ver_name_info:', ver_name_info)
                    print('target_name: ', target_name)
                    print('source_name:', source_name)

                    ftp_upload.upload_to_sftp(ftp_config_path, ver_name_info,
                                              self.ver_env, self.code_ver,
                                              to_upload_path, 'Android',
                                              target_name, source_name)
            else:
                str_info = 'Build failed, code version is {}.'.format(
                    self.code_ver)
                print(str_info)
Esempio n. 24
0
    def process(self):
        code_svn_url = self.ori_build_config[BuildConfigParser.ROOT_FLAG][BuildConfigParser.CODE_SVN_FLAG]
        
        static_config_path = self.work_path + os.sep + self.ori_build_config[BuildConfigParser.ROOT_FLAG][BuildConfigParser.STATIC_FLAG]
        static_config_path = myfile.normalpath(static_config_path)
        
        main_prj_name = self.ori_build_config[BuildConfigParser.WORKSPACE_FLAG][BuildConfigParser.MAIN_FLAG]
        main_prj_path = self.project_path + os.sep + main_prj_name
        
        # 进行代码更新操作
        if self.to_update:
            # 先checkout svn库上代码,再更新和本地相关的配置文件
            checkout_or_update_single_item(self.project_path, static_config_path, code_svn_url, revision=self.svn_ver)
            
            # 更新gradle编译配置配置,新框架不再需要该步骤(20161110 17:39)
#             gradle_setting_name = 'settings.gradle'
#             gradle_setting_path = static_config_path + os.sep + gradle_setting_name
#             update_gradle_setting(main_prj_path, gradle_setting_path)
            
        # 获取当前svn版本号    
        self.svn_ver_code = svn.get_revision(self.project_path)
        print('svn version code is ' + str(self.svn_ver_code))
    
        # 进行版本编译操作
        if self.to_build:
            to_check_vals = ['ver_name', 'ver_code', 'ver_env']
            for name in to_check_vals:
                value = getattr(self, name)
                if not value:
                    info = 'Please specify the {}.'.format(name)
                    print(info)
                    exit(1)
                    
            # 参数非空判断验证通过开始进行正式业务逻辑
            self.pro_build_config = self._get_pro_build_config()
            self.pre_build()
            
            if self.is_debug:
                mode_flag = apk_builder.DEBUG_FLAG
            else:
                mode_flag = apk_builder.RELEASE_FLAG
                
            mode = apk_builder.FLAG_MODE_MAP[mode_flag]
            res_path = self.work_path + os.sep + self.ori_build_config[BuildConfigParser.WORKSPACE_FLAG][BuildConfigParser.CHANNEL_INFO_FLAG]
        
            if self.channel_file:
                if not os.path.exists(self.channel_file):
                    print('not exist {}'.format(self.channel_file))
                    exit(1)
                    
                build_app(main_prj_path, self.channel_file, res_path, self.pro_build_config)
            else:
                if self.channel:
                    chan_id = self.channel
                else:
                    chan_id = ProjectBuilder.DEFAULT_CHAN
                    
                build_app(main_prj_path, None, res_path, self.pro_build_config, chan_id, mode)
            
            if os.path.exists(self.apk_output_path) and os.path.isfile(self.apk_output_path):
                # 将编译信息写文件
                build_info_format = self.ori_build_config[BuildConfigParser.BUILD_INFO_TEMPLET_FLAG]
                build_info = build_info_format.format(ver_name=self.ver_name, svn_ver=self.svn_ver_code, ver_code=self.ver_code)
                build_info_path = self.output_directory + os.sep + 'readme-{}-{}.txt'.format(self.ver_name, self.ver_code)
                myfile.write_to_file(build_info_path, build_info, encoding='utf-8')
                
                str_info = 'Build success, svn code is {}.'.format(self.svn_ver_code)
                print(str_info)
            else:
                str_info = 'Build failed, svn code is {}.'.format(self.svn_ver_code)
                print(str_info)
Esempio n. 25
0
 def update_config(self, config=None):
     self._update_config(config)
     
     if self.config_modified:
         myfile.write_to_file(self.config_path, self.config_data, 'utf-8')
Esempio n. 26
0
 def update_info(self, target_info):
     if target_info:
         self._update_config(target_info)
     
     if self.modify_flag:
         myfile.write_to_file(self.src_path, self.src_data, 'utf-8')
Esempio n. 27
0
 def update_chan_info(self, chan_str):
     self._update_chan_config(chan_str)
     if self.modify_flag:
         myfile.write_to_file(self.src_path, self.src_data, 'utf-8')
Esempio n. 28
0
    def testSwitch_commit_with_file(self):
        service = SvnService(self.temp_dir,
                             normal=self.normal,
                             refuse=self.refuse,
                             target=self.target)
        target_path = self.target_path
        normal_str = self.normal_str
        refuse_str = self.refuse_str
        svn_name = self.svn_name

        # 验证原本可正常提交情况,当前要切换为可提交情况
        file_util.write_to_file(target_path, normal_str, encoding='utf-8')
        time.sleep(1)
        target_m_time = os.path.getmtime(target_path)
        service.switch_commit_with_file(svn_name, True)
        new_target_m_time = os.path.getmtime(target_path)
        content = file_util.read_file_content(target_path, encoding_='utf-8')
        self.assertEqual(
            target_m_time, new_target_m_time,
            f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}'
        )
        self.assertEqual(content, normal_str,
                         f'content: {content}, normal_str: {normal_str}')

        # 验证原本非正常提交情况,当前要切换为可提交情况
        file_util.write_to_file(target_path, refuse_str, encoding='utf-8')
        time.sleep(1)
        target_m_time = os.path.getmtime(target_path)
        service.switch_commit_with_file(svn_name, True)
        new_target_m_time = os.path.getmtime(target_path)
        content = file_util.read_file_content(target_path, encoding_='utf-8')
        self.assertNotEqual(
            target_m_time, new_target_m_time,
            f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}'
        )
        self.assertEqual(content, normal_str,
                         f'content: {content}, normal_str: {normal_str}')

        # 验证原本可正常提交情况,当前要切换为不可提交情况
        file_util.write_to_file(target_path, normal_str, encoding='utf-8')
        time.sleep(1)
        target_m_time = os.path.getmtime(target_path)
        service.switch_commit_with_file(svn_name, False)
        new_target_m_time = os.path.getmtime(target_path)
        content = file_util.read_file_content(target_path, encoding_='utf-8')
        self.assertNotEqual(
            target_m_time, new_target_m_time,
            f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}'
        )
        self.assertEqual(content, refuse_str,
                         f'content: {content}, refuse_str: {refuse_str}')

        # 验证原本非正常提交情况,当前要切换为不可提交情况
        file_util.write_to_file(target_path, refuse_str, encoding='utf-8')
        time.sleep(1)
        target_m_time = os.path.getmtime(target_path)
        service.switch_commit_with_file(svn_name, False)
        new_target_m_time = os.path.getmtime(target_path)
        content = file_util.read_file_content(target_path, encoding_='utf-8')
        self.assertEqual(
            target_m_time, new_target_m_time,
            f'target_c_time: {target_m_time}, new_target_c_time: {new_target_m_time}'
        )
        self.assertEqual(content, refuse_str,
                         f'content: {content}, refuse_str: {refuse_str}')
Esempio n. 29
0
    def update_version_config(self):
        self._update_version_code()
        self._update_version_name()

        if self.config_modified:
            myfile.write_to_file(self.config_path, self.config_data, 'utf-8')
Esempio n. 30
0
    def update_version_config(self, version_code=None, version_name=None):
        self._update_version_code(version_code)
        self._update_version_name(version_name)

        if self.config_modified:
            myfile.write_to_file(self.config_path, self.config_data, 'utf-8')