Esempio n. 1
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')
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. ')
def check_latest_commit():
    print('update: INFO: checking latest commit ')

    conf = update.etc['conf']
    # get github latest commit
    page_url = conf['remote']['youtube_dl_home']

    print('update: INFO: load github page \"' + page_url + '\" ')
    g_latest_commit, g_zip_url = update.check_github_latest_commit(page_url)
    print('update: [ OK ] got latest commit [' + g_latest_commit + ']')

    # save g_zip_url
    etc['g_zip_url'] = g_zip_url

    # save latest_commit
    etc['g_latest_commit'] = g_latest_commit

    # get local latest commit
    l_latest_commit = ''
    local_file = conf['local']['youtube_dl_latest_commit']
    root_path = update.etc['root_path']
    fpath = os.path.join(root_path, local_file)
    try:
        with open(fpath) as f:
            l_latest_commit = f.read().split('\n')[0].split('\r')[0]
    except OSError:
        print('update: ERROR: can not open local commit info file \"' +
              base.rel_path(fpath) + '\" ')
        return True
    # got local latest commit
    print('update: [ OK ] local commit [' + l_latest_commit + ']')

    # check match
    if l_latest_commit == g_latest_commit:
        # check force flag
        if etc['flag_force']:
            print('update: INFO: ignore latest commit check result. ')
        else:
            print('update: INFO: no need to update. ')
            return False
    else:  # should update
        print('update: INFO: start real update')
    return True
def check_latest_commit():
    print('update: INFO: checking latest commit ')
    
    conf = update.etc['conf']
    # get github latest commit
    page_url = conf['remote']['youtube_dl_home']
    
    print('update: INFO: load github page \"' + page_url + '\" ')
    g_latest_commit, g_zip_url = update.check_github_latest_commit(page_url)
    print('update: [ OK ] got latest commit [' + g_latest_commit + ']')
    
    # save g_zip_url
    etc['g_zip_url'] = g_zip_url
    
    # save latest_commit
    etc['g_latest_commit'] = g_latest_commit
    
    # get local latest commit
    l_latest_commit = ''
    local_file = conf['local']['youtube_dl_latest_commit']
    root_path = update.etc['root_path']
    fpath = os.path.join(root_path, local_file)
    try:
        with open(fpath) as f:
            l_latest_commit = f.read().split('\n')[0].split('\r')[0]
    except OSError:
        print('update: ERROR: can not open local commit info file \"' + base.rel_path(fpath) + '\" ')
        return True
    # got local latest commit
    print('update: [ OK ] local commit [' + l_latest_commit + ']')
    
    # check match
    if l_latest_commit == g_latest_commit:
        # check force flag
        if etc['flag_force']:
            print('update: INFO: ignore latest commit check result. ')
        else:
            print('update: INFO: no need to update. ')
            return False
    else:	# should update
        print('update: INFO: start real update')
    return True
Esempio n. 6
0
def pack_zip(zip_file):
    root_path = update.etc['root_path']
    conf = update.etc['conf']
    tmp_path = etc['tmp_path']
    
    # find plugin files, and get sub path
    extract_path = etc['extract_path']
    extracted_path = base.find_first_dir(extract_path)
    sub_path0 = conf['local']['youtube_dl_path']
    sub_path = os.path.join(root_path, sub_path0)
    
    print('\nupdate: INFO: start pack plugin zip file \"' + base.rel_path(zip_file) + '\" ')
    
    # add lieying_plugin files
    add_files_to_zip(zip_file, extracted_path)
    # add sub files
    add_files_to_zip(zip_file, sub_path, path_before=sub_path0, mode='a')
    
    # done
    print('update: [ OK ] create plugin zip file done. ')
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. ')
Esempio n. 9
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)