Example #1
0
def minify_file_in_script(data, offset_path='.', argv=None):
    """
    压缩文件
    :param data: 规则字典
    :param path: 当前路径
    :return:
    """
    now_path = data['source_path'] + '/' + offset_path
    if os.path.isdir(now_path):
        fps = os.listdir(now_path)
        for fp in fps:
            minify_file_in_script(data, offset_path + '/' + fp, argv=argv)
    else:

        # 判断是不是修改了这个文件
        if os.path.realpath(now_path) != os.path.realpath(
                argv['change_file_path']):
            return

        fp_type = tools.get_file_type(now_path)
        if fp_type and fp_type in ['html', 'css', 'js']:
            read_type = 'r'
        else:
            read_type = 'rb'

        with open(now_path, read_type) as fp:
            fp_data = fp.read()
            if fp_type and fp_type in ['html', 'css', 'js']:
                fp_data = minify_file(fp_data, fp_type, data['encryption'],
                                      data['encryption'])
                write_type = 'w'
            else:
                write_type = 'wb'
            tools.output_file(data['target_path'] + '/' + offset_path, fp_data,
                              write_type)
Example #2
0
def minify_file_in_script(data, offset_path='.', argv=None):
    """
    压缩文件
    :param data: 规则字典
    :param path: 当前路径
    :return:
    """
    now_path = data['source_path'] + '/' + offset_path
    if os.path.isdir(now_path):
        fps = os.listdir(now_path)
        for fp in fps:
            minify_file_in_script(data, offset_path + '/' + fp, argv=argv)
    else:

        # 判断是不是修改了这个文件
        if os.path.realpath(now_path) != os.path.realpath(argv['change_file_path']):
            return

        fp_type = tools.get_file_type(now_path)
        if fp_type and fp_type in ['html', 'css', 'js']:
            read_type = 'r'
        else:
            read_type = 'rb'

        with open(now_path, read_type) as fp:
            fp_data = fp.read()
            if fp_type and fp_type in ['html', 'css', 'js']:
                fp_data = minify_file(fp_data, fp_type, data['encryption'], data['encryption'])
                write_type = 'w'
            else:
                write_type = 'wb'
            tools.output_file(data['target_path'] + '/' + offset_path, fp_data, write_type)
Example #3
0
def merge_file(data):
    """
    合并文件
    :param data: 规则字典
    :return:
    """
    text = get_after_merge_file_str(data['source_path'])
    text = minify_file(text, data['minify'], data['encryption'], data['encryption'])
    tools.output_file(data['target_path'], text)
Example #4
0
def merge_file(data):
    """
    合并文件
    :param data: 规则字典
    :return:
    """
    text = get_after_merge_file_str(data['source_path'])
    text = minify_file(text, data['minify'], data['encryption'],
                       data['encryption'])
    tools.output_file(data['target_path'], text)