def update_ffmpeg(): print('更新FFMPEG') # first time, check path if not os.path.exists(ffmpeg_home): os.makedirs(ffmpeg_home) # download files url = ff print('downloading from ', url) fname = '{}{}'.format(ffmpeg_home, ffname) outPath = '{}{}'.format(ffmpeg_home, outfname) download_file(ff, fname=fname) if platform: # extract zip z = zipfile.ZipFile(fname, 'r') z.extractall(path=ffmpeg_home) z.close() ndir = os.listdir(ffmpeg_home)[0] copyfile(ffmpeg_home + ndir + '/bin/ffmpeg.exe', outPath) # clean tmp shutil.rmtree(ffmpeg_home + ndir) else: file = tarfile.open(fname).extractfile( 'ffmpeg-4.1-64bit-static/ffmpeg-10bit') buf = file.read() file.close() with open(outPath, 'wb') as out: out.write(buf) os.remove(fname)
def update(): # make temp dir if not os.path.exists('./update_tmp'): os.mkdir('./update_tmp') v = getVersion() current_v = json.load('./package.json')['version'] print('current version==',current_v) if compareVersion(v, current_v) <= 0: print('已是最新版本') else: url_new_version = ufile+v+'.zip' # download zip print('downloading from ',url_new_version) url = url_new_version r = requests.get(url) with open("./update_tmp/tmp.zip", "wb") as code: code.write(r.content) # extract zip z = zipfile.ZipFile('./update_tmp/tmp.zip', 'r') z.extractall(path='./update_tmp') z.close() # copy files print('copying files') py_files = os.listdir('./update_tmp') for f in py_files: if f[-3:] == '.py': # copyfile('./update_tmp/'+f,'./python/update_tmp/'+f) compile_pyc(path='./update_tmp/') copyfile('./update_tmp/__pycache__/'+f[:-3]+'.pyc','./'+f[:-3]+'.pyc') # recompile pyc elif f[-4:] == '.txt': copyfile('./update_tmp/'+f,'./'+f) print('升级完成,请重启软件') #clean temp files shutil.rmtree('./update_tmp')
def update_ffmpeg(manifest, platform=isWindows): print('更新FFMPEG') # first time, check path if not os.path.exists(ffmpeg_home): os.makedirs(ffmpeg_home) # download files url = manifest['ffmpeg-win' if platform else 'ffmpeg-linux'] print('downloading from ',url) fname = '{}{}'.format(ffmpeg_home, ffname) outPath = '{}{}'.format(ffmpeg_home, outfname) download_file(url,fname=fname) if platform: # extract zip ndir = 'ffmpeg-latest-win64-static' z = zipfile.ZipFile(fname, 'r') z.extract('{}/bin/ffmpeg.exe'.format(ndir), path=ffmpeg_home) z.close() copyfile('{}{}/bin/ffmpeg.exe'.format(ffmpeg_home, ndir),outPath) # clean tmp shutil.rmtree(ffmpeg_home+ndir) else: tar = tarfile.open(fname) file = tar.extractfile('{}/ffmpeg'.format(tar.getnames()[0])) buf = file.read() tar.close() with open(outPath, 'wb') as out: out.write(buf) os.remove(fname)
def update_ffmpeg(): print('更新FFMPEG') # first time, check path ffmpeg_home = './ffmpeg/bin/' if not os.path.exists(ffmpeg_home): os.makedirs(ffmpeg_home) # download files url = ff print('downloading from ',url) download_file(ff,fname=ffmpeg_home+'ffmpeg.zip') # extract zip z = zipfile.ZipFile(ffmpeg_home+'ffmpeg.zip', 'r') z.extractall(path=ffmpeg_home) z.close() ndir = os.listdir(ffmpeg_home)[0] copyfile(ffmpeg_home+ndir+'/bin/ffmpeg.exe',ffmpeg_home+'ffmpeg.exe') # clean tmp shutil.rmtree(ffmpeg_home+ndir) os.remove(ffmpeg_home+'ffmpeg.zip')