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. ')
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 main():
    
    # init info
    print('update: INFO: start update plugin ')
    
    # load config file
    update.load_config()
    # process config content
    root_path = update.etc['root_path']
    conf = update.etc['conf']
    
    tmp_path = os.path.join(root_path, conf['local']['tmp_path'])
    etc['tmp_path'] = tmp_path
    
    conf_file = os.path.join(root_path, update.CONFIG_FILE)
    print('update: [ OK ] load config file \"' + base.rel_path(conf_file) + '\"')
    
    # update youtube_dl first
    exit_code = update_sub()
    if exit_code != 0:
        print('update: ERROR: update sub failed. ')
        exit(1)	# exit with an error
        return True
    else:	# update youtube_dl OK
        print('update: [ OK ] update sub done. ')
    
    # do not check, just download and pack
    zip_url = conf['remote']['plugin_zip']
    print('\nupdate: INFO: download lieying_plugin zip file from \"' + zip_url + '\" ')
    
    # make zip file path
    zip_file = os.path.join(tmp_path, os.path.basename(zip_url))
    if not (zip_file.endswith('.zip')):
        zip_file += '.zip'
    # do download
    ed_byte = update.dl_file(zip_url, zip_file)
    # download info
    print('update: [ OK ] saved ' + base.byte2size(ed_byte, True) + ' to \"' + base.rel_path(zip_file) + '\"')
    
    etc['zip_file'] = zip_file
    
    # extract pack
    print('')
    extract_pack()
    # make plugin zip bag
    zip_bag = conf['local']['plugin_zip_file']
    zip_bag = os.path.join(root_path, zip_bag)
    # TODO should auto-gen file name here TODO
    pack_zip(zip_bag)
    
    # done
    print('\nupdate: done')
示例#4
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)
def main():

    # init info
    print('update: INFO: start update youtube-dl ')

    # get and process command line args
    get_args()

    # load config file
    update.load_config()
    # process config content
    root_path = update.etc['root_path']
    conf = update.etc['conf']

    tmp_path = os.path.join(root_path, conf['local']['tmp_path'])
    etc['tmp_path'] = tmp_path

    conf_file = os.path.join(root_path, update.CONFIG_FILE)
    print('update: [ OK ] load config file \"' + base.rel_path(conf_file) +
          '\"')

    # check flags
    if etc['flag_dl_github']:
        # check latest commit
        if not check_latest_commit():
            # no need to update
            print('update: done')
            return

        # start real update
        zip_url = etc['g_zip_url']
        print('update: INFO: download youtube-dl zip file from \"' + zip_url +
              '\" ')

        # make zip file path
        zip_file = os.path.join(tmp_path, os.path.basename(zip_url))
        if not (zip_file.endswith('.zip')):
            zip_file += '.zip'
        # do download
        ed_byte = update.dl_file(zip_url, zip_file)
        # download info
        print('update: [ OK ] saved ' + base.byte2size(ed_byte, True) +
              ' to \"' + base.rel_path(zip_file) + '\"')

        etc['zip_file'] = zip_file

        # extract zip file
        extract_pack()
        # move files
        mv_file()
    # check and download from github, done

    # check flag
    if etc['flag_pack_zip']:
        # re-pack
        re_pack()

    # check flag
    if etc['flag_dl_github']:
        latest_commit_file = conf['local']['youtube_dl_latest_commit']
        latest_commit_file = os.path.join(root_path, latest_commit_file)
        g_latest_commit = etc['g_latest_commit']
        # update latest commit
        print('update: INFO: save latest commit [' + g_latest_commit +
              '] to \"' + base.rel_path(latest_commit_file) + '\" ')
        with open(latest_commit_file, 'w') as f:
            f.write(g_latest_commit)
    # done
    print('update: [ OK ] done. All works finished. ')
def main():
    
    # init info
    print('update: INFO: start update youtube-dl ')
    
    # get and process command line args
    get_args()
    
    # load config file
    update.load_config()
    # process config content
    root_path = update.etc['root_path']
    conf = update.etc['conf']
    
    tmp_path = os.path.join(root_path, conf['local']['tmp_path'])
    etc['tmp_path'] = tmp_path
    
    conf_file = os.path.join(root_path, update.CONFIG_FILE)
    print('update: [ OK ] load config file \"' + base.rel_path(conf_file) + '\"')
    
    # check flags
    if etc['flag_dl_github']:
        # check latest commit
        if not check_latest_commit():
            # no need to update
            print('update: done')
            return
        
        # start real update
        zip_url = etc['g_zip_url']
        print('update: INFO: download youtube-dl zip file from \"' + zip_url + '\" ')
        
        # make zip file path
        zip_file = os.path.join(tmp_path, os.path.basename(zip_url))
        if not (zip_file.endswith('.zip')):
            zip_file += '.zip'
        # do download
        ed_byte = update.dl_file(zip_url, zip_file)
        # download info
        print('update: [ OK ] saved ' + base.byte2size(ed_byte, True) + ' to \"' + base.rel_path(zip_file) + '\"')
        
        etc['zip_file'] = zip_file
        
        # extract zip file
        extract_pack()
        # move files
        mv_file()
    # check and download from github, done
    
    # check flag
    if etc['flag_pack_zip']:
        # re-pack
        re_pack()
    
    # check flag
    if etc['flag_dl_github']:
        latest_commit_file = conf['local']['youtube_dl_latest_commit']
        latest_commit_file = os.path.join(root_path, latest_commit_file)
        g_latest_commit = etc['g_latest_commit']
        # update latest commit
        print('update: INFO: save latest commit [' + g_latest_commit + '] to \"' + base.rel_path(latest_commit_file) + '\" ')
        with open(latest_commit_file, 'w') as f:
            f.write(g_latest_commit)
    # done
    print('update: [ OK ] done. All works finished. ')