Пример #1
0
def re_pack():

    root_path = update.etc['root_path']
    conf = update.etc['conf']
    tmp_path = conf['local']['tmp_path']

    # start re-pack
    print('update: INFO: start re-pack plugin zip bag file ')

    # get file list
    finfo = make_zip.gen_file_list(root_path)

    # ignore some from flist
    flist = []  # keep file list
    ilist = []  # ignored file list
    for f in finfo['list']:
        # ignore .git
        if f['name'].startswith('.git'):
            ilist.append(f)
        # ignore __pycache__
        elif '__pycache__' in f['name']:
            ilist.append(f)
        # ignore tmp path
        elif f['name'].startswith(tmp_path):
            ilist.append(f)
        else:  # should keep this file
            flist.append(f)
    # count something
    isize = 0
    fsize = 0
    for f in ilist:
        isize += f['size']
    for f in flist:
        fsize += f['size']
    # print info
    t = 'update: [ OK ] make file list done, ' + str(len(flist)) + ' files, '
    t += update.byte2size(fsize, True) + '; '
    t += 'ignored ' + str(
        len(ilist)) + ' files, ' + update.byte2size(isize) + '. '
    print(t)

    tmp_path2 = etc['tmp_path']
    # create zip file
    zip_file = conf['local']['re_pack_file'] + make_re_pack_name() + '.zip'
    zip_path = os.path.join(tmp_path2, zip_file)
    print('update: INFO: create zip file \"' + update.rel_path(zip_path) +
          '\" ')

    import zipfile
    make_zip.make_zip_file(zip_path,
                           flist,
                           root_path,
                           compress=zipfile.ZIP_DEFLATED)

    # compress done
    print('update: [ OK ] compress files done. ')
Пример #2
0
def re_pack():
    
    root_path = update.etc['root_path']
    conf = update.etc['conf']
    tmp_path = conf['local']['tmp_path']
    
    # start re-pack
    print('update: INFO: start re-pack plugin zip bag file ')
    
    # get file list
    finfo = make_zip.gen_file_list(root_path)
    
    # ignore some from flist
    flist = []	# keep file list
    ilist = []	# ignored file list
    for f in finfo['list']:
        # ignore .git
        if f['name'].startswith('.git'):
            ilist.append(f)
        # ignore __pycache__
        elif '__pycache__' in f['name']:
            ilist.append(f)
        # ignore tmp path
        elif f['name'].startswith(tmp_path):
            ilist.append(f)
        else:	# should keep this file
            flist.append(f)
    # count something
    isize = 0
    fsize = 0
    for f in ilist:
        isize += f['size']
    for f in flist:
        fsize += f['size']
    # print info
    t = 'update: [ OK ] make file list done, ' + str(len(flist)) + ' files, '
    t += base.byte2size(fsize, True) + '; '
    t += 'ignored ' + str(len(ilist)) + ' files, ' + base.byte2size(isize) + '. '
    print(t)
    
    tmp_path2 = etc['tmp_path']
    # create zip file
    zip_file = conf['local']['re_pack_file'] + make_re_pack_name() + '.zip'
    zip_path = os.path.join(tmp_path2, zip_file)
    print('update: INFO: create zip file \"' + base.rel_path(zip_path) + '\" ')
    
    import zipfile
    make_zip.make_zip_file(zip_path, flist, root_path, compress=zipfile.ZIP_DEFLATED)
    
    # compress done
    print('update: [ OK ] compress files done. ')
Пример #3
0
def add_files_to_zip(zip_file, base_path, path_before=None, mode='w'):
    
    # get file list
    finfo = make_zip.gen_file_list(base_path)
    
    flist = finfo['list']
    # count something
    fsize = 0
    for f in flist:
        fsize += f['size']
    # print info
    print('update: add ' + str(len(flist)) + ' files, ' + base.byte2size(fsize, True) + ' from \"' + base.rel_path(base_path) + '\" ')
    
    # do create zip file
    import zipfile
    make_zip.make_zip_file(zip_file, flist, base_path, compress=zipfile.ZIP_STORED, path_before=path_before, mode=mode)