コード例 #1
0
ファイル: deploy.py プロジェクト: ieasysoft/imetadata
def package(output_relation_dir):
    """
    编译根目录下的包括子目录里的所有py文件成pyc文件到新的文件夹下
    :param output_relation_dir: 需编译的目录
    :return:
    """
    output_relation_dir = CFile.unify(CUtils.any_2_str(output_relation_dir))

    application_dir = CFile.file_path(CFile.file_abs_path(__file__))
    output_dir = CFile.file_abs_path(CFile.join_file(application_dir, output_relation_dir))

    for each_directory, dir_name_list, file_name_without_path_list in os.walk(application_dir):
        directory_source = each_directory
        directory_name = CFile.file_name(directory_source)
        directory_relation = CFile.file_relation_path(each_directory, application_dir)
        directory_target = CFile.join_file(output_dir, directory_relation)

        path_deploy_enable = deploy_match_pattern_list(directory_relation, 'path.white_list', True, True)
        path_deploy_enable = path_deploy_enable and deploy_match_pattern_list(directory_relation, 'path.black_list',
                                                                              False, True)
        if path_deploy_enable:
            directory_deploy_enable = deploy_match_pattern_list(directory_name, 'directory.white_list', True, True)
            directory_deploy_enable = directory_deploy_enable and deploy_match_pattern_list(
                directory_name, 'directory.black_list',
                False, True
            )

            if directory_deploy_enable:
                for file_name_without_path in file_name_without_path_list:
                    file_deploy_enable = deploy_match_pattern_list(
                        file_name_without_path, 'file.white_list', True,
                        True
                    )
                    file_deploy_enable = file_deploy_enable and deploy_match_pattern_list(
                        file_name_without_path, 'file.black_list',
                        False, True
                    )

                    file_name_with_path_source = CFile.join_file(directory_source, file_name_without_path)
                    if file_deploy_enable:
                        file_compile_enable = deploy_match_pattern_list(
                            file_name_without_path, 'compile.file.white_list',
                            True, False
                        )
                        if file_compile_enable:
                            file_compile_enable = deploy_match_pattern_list(
                                file_name_without_path, 'compile.file.black_list',
                                False, False
                            )

                        file_name_without_path_target = CFile.change_file_ext(file_name_without_path, 'pyc')
                        file_name_with_path_target = CFile.join_file(directory_target, file_name_without_path_target)
                        CFile.check_and_create_directory_itself(directory_target)
                        if file_compile_enable:
                            py_compile.compile(file_name_with_path_source, cfile=file_name_with_path_target)
                            print('{0}-compile-success'.format(file_name_with_path_source))
                        else:
                            CFile.copy_file_to(file_name_with_path_source, directory_target)
                            print('{0}-no_compile'.format(file_name_with_path_source))
コード例 #2
0
ファイル: c_fileInfoEx.py プロジェクト: ieasysoft/imetadata
    def __init__(self, file_type, file_name_with_full_path, root_path,
                 rule_content):
        super().__init__(file_type, file_name_with_full_path)
        self.__root_path = root_path
        if CUtils.equal_ignore_case(root_path, file_name_with_full_path):
            self.__file_main_name_with_rel_path = ''
            self.__file_name_with_rel_path = ''
            self.__file_path_with_rel_path = ''
        else:
            self.__file_main_name_with_rel_path = CFile.file_relation_path(
                self.file_main_name_with_full_path, self.__root_path)
            self.__file_name_with_rel_path = CFile.file_relation_path(
                self.file_name_with_full_path, self.__root_path)
            self.__file_path_with_rel_path = CFile.file_relation_path(
                self.file_path, self.__root_path)

        self.__rule_content = rule_content
コード例 #3
0
ファイル: c_detailParser.py プロジェクト: ieasysoft/imetadata
    def __inbound_object_detail_of_schema(self, list_file_fullname):
        sql_detail_insert = '''
        INSERT INTO dm2_storage_obj_detail(
            dodid, dodobjectid, dodfilename, dodfileext, dodfilesize, 
            dodfilecreatetime, dodfilemodifytime, 
            dodlastmodifytime, dodfiletype)
        VALUES (
            :dodid, :dodobjectid, :dodfilename, :dodfileext, :dodfilesize, 
            :dodfilecreatetime, :dodfilemodifytime, now(), 
            :dodfiletype)
        '''

        sql_detail_insert_params_list = []

        # query_storage_id = self.file_info.storage_id
        query_file_relation_name = self.file_info.file_name_with_rel_path
        for item_file_name_with_path in list_file_fullname:
            CLogger().debug(item_file_name_with_path)
            if not CFile.file_or_path_exist(item_file_name_with_path):
                continue

            params = dict()
            file_relation_name = CFile.file_relation_path(
                item_file_name_with_path, self.file_info.root_path)
            if CUtils.equal_ignore_case(query_file_relation_name,
                                        file_relation_name):
                params['dodid'] = self.object_id
            else:
                params['dodid'] = CUtils.one_id()
            # 文件类型
            params['dodfiletype'] = self.FileType_File
            if CFile.is_dir(item_file_name_with_path):
                params['dodfiletype'] = self.FileType_Dir
            params['dodobjectid'] = self.object_id
            params['dodfilename'] = CFile.unify(file_relation_name)
            params['dodfileext'] = CFile.file_ext(item_file_name_with_path)
            params['dodfilesize'] = CFile.file_size(item_file_name_with_path)
            params['dodfilecreatetime'] = CFile.file_create_time(
                item_file_name_with_path)
            params['dodfilemodifytime'] = CFile.file_modify_time(
                item_file_name_with_path)
            # params['dodstorageid'] = query_storage_id
            # params['dodfilerelationname'] = CFile.file_relation_path(
            #     item_file_name_with_path,
            #     self.file_info.root_path)
            sql_params_tuple = (sql_detail_insert, params)
            sql_detail_insert_params_list.append(sql_params_tuple)

        if len(sql_detail_insert_params_list) > 0:
            try:
                CFactory().give_me_db(
                    self.file_info.db_server_id).execute_batch(
                        sql_detail_insert_params_list)
            except Exception as error:
                CLogger().warning('数据库处理出现异常, 错误信息为: {0}'.format(
                    error.__str__()))
                return CResult.merge_result(self.Failure, '处理失败!')
        return CResult.merge_result(self.Success, '处理完毕!')
コード例 #4
0
ファイル: c_detailParser.py プロジェクト: ieasysoft/imetadata
    def __stat_object_detail_of_schema(self) -> str:
        """
        将数据附属文件的统计信息入库
        . 仅适用于Directory_Itself模式
        :return:
        """
        result_sub_dir_count, result_file_count, result_file_size_sum = CFile.stat_of_path(
            self.__detail_file_path__, self.__detail_file_recurse__,
            self.__detail_file_match_text__, self.__detail_file_match_type__)

        query_file_relation_name = self.file_info.file_name_with_rel_path
        params = dict()
        file_relation_name = CFile.file_relation_path(
            self.__detail_file_path__, self.file_info.root_path)
        if CUtils.equal_ignore_case(query_file_relation_name,
                                    file_relation_name):
            params['dodid'] = self.object_id
        else:
            params['dodid'] = CUtils.one_id()

        params['dodfiletype'] = self.FileType_Dir
        params['dodfileext'] = None

        if CFile.is_file(self.__detail_file_path__):
            params['dodfiletype'] = self.FileType_File
            params['dodfileext'] = CFile.file_ext(self.__detail_file_path__)

        params['dodobjectid'] = self.object_id
        params['dodfilename'] = CFile.unify(file_relation_name)

        params['doddircount'] = result_sub_dir_count
        params['dodfilecount'] = result_file_count
        params['dodfilesize'] = result_file_size_sum
        params['dodfilecreatetime'] = CFile.file_create_time(
            self.__detail_file_path__)
        params['dodfilemodifytime'] = CFile.file_modify_time(
            self.__detail_file_path__)

        try:
            CFactory().give_me_db(self.file_info.db_server_id).execute(
                '''
                INSERT INTO dm2_storage_obj_detail(
                    dodid, dodobjectid, dodfilename, dodfileext, dodfilesize, doddircount, dodfilecount,
                    dodfilecreatetime, dodfilemodifytime, dodlastmodifytime, dodfiletype)
                VALUES (
                    :dodid, :dodobjectid, :dodfilename, :dodfileext, :dodfilesize, :doddircount, :dodfilecount,
                    :dodfilecreatetime, :dodfilemodifytime, now(), :dodfiletype)
                ''', params)
            return CResult.merge_result(self.Success, '处理完毕!')
        except Exception as error:
            CLogger().warning('数据库处理出现异常, 错误信息为: {0}'.format(error.__str__()))
            return CResult.merge_result(
                self.Failure, '数据库处理出现异常, 错误信息为: {0}'.format(error.__str__()))