update synchronize/synchronize.py.

This commit is contained in:
Bigsk 2020-03-05 14:09:58 +08:00 committed by Gitee
parent 961eac36ff
commit cb215942e5

View File

@ -32,10 +32,14 @@ def log(logvar):
def synchronize(url, filepath):
global Log
log('[INFO]:The ' + SystemName + ' is synchronizing the file ' + SavePath + filepath + '.')
synchronize=requests.get(url)
with open(SavePath + filepath,"wb") as code:
code.write(synchronize.content)
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
try:
synchronize=requests.get(url)
with open(SavePath + filepath,"wb") as code:
code.write(synchronize.content)
except:
log('[ERROR]:There has a error in task of synchronizing the file ' + SavePath + filepath + '.')
else:
log('[INFO]:The file ' + SavePath + filepath + ' has been synchronized successfully.')
#Module Which Be Used To Determine Whether The Dir Exists.
def make_sure_dir_exists(dirpath):
global Log
@ -116,7 +120,6 @@ log('[INFO]:There has ' + str(mcversionsnumber) + ' MC versions in total .')
log('[INFO]:Counting how many MC versions in total successfully.')
#Starting To Synchronize More Files And Dirs.
#Auto Synchronize Files And Dirs on https://launchermeta.mojang.com/.
'''
log('[INFO]:Starting to synchronize files and dirs on https://launchermeta.mojang.com/.')
whiletimes=0#Set Var whiletimes To Avoid Error.
while(whiletimes < mcversionsnumber):
@ -133,7 +136,6 @@ while(whiletimes < mcversionsnumber):
make_sure_dir_exists(filetosync)
synchronize(onlineurlwithouthttps, fileurl)
log('[INFO]:Synchronizing files and dirs on https://launchermeta.mojang.com/ successfully.')
'''
#Auto Synchronize Files And Dirs on https://libraries.minecraft.net/.
log('[INFO]:Starting to synchronize files and dirs on https://libraries.minecraft.net/.')
#Part Of 'downloads'.
@ -148,12 +150,17 @@ while(whiletimes < mcversionsnumber):
onlineurlwithouthttps=onlineurl.replace('https://', 'http://')#Avoid Https Connetion Errors
log('[INFO]:Starting to get the json of MC libraries ' + onlineurl +' list.')
#Save MC Libraries Json In Global Variables
mclibrariesjson=requests.get(url=onlineurlwithouthttps)
log('[INFO]:Get json of MC libraries ' + onlineurl +' successfully.')
try:#Avoid Http/Httos Connection Errors Making Whole Synchronize Stop.
mclibrariesjson=requests.get(url=onlineurlwithouthttps)
except:
log('[ERROR]:There has a error in task of getting json of MC libraries ' + onlineurl + '.')
else:
log('[INFO]:Get json of MC libraries ' + onlineurl + ' successfully.')
#Read Json Of MC Libraries.
mclibrariesload=json.loads(mclibrariesjson.text)
#Synchronize Files In "downloads".
try:
log('[INFO]:Starting to synchronize files in ”downloads".')
try:#Avoid Http/Httos Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
onlineurl2=mclibrariesload['downloads']['client']['url']
fileurl2='mojang/launcher/' + onlineurl2.replace('https://launcher.mojang.com/','')
filetosync2=fileurl2[::-1].split('/', 1)[-1][::-1]
@ -181,9 +188,9 @@ while(whiletimes < mcversionsnumber):
make_sure_dir_exists(filetosync2)
synchronize(onlineurl2, fileurl2)
except:
placeholder=''
finally:
placeholder=''
log('[ERROR]:There has a error in task of synchronizing files in "downloads".')
else:
log('[INFO]:Synchronizing files in "downloads" successfully.')
log('[INFO]:Starting to count how many MC libraries files in ' + onlineurl + ' in total.')
#Count How Many MC Libraries Files in total.
mclibrariesjsontext=mclibrariesjson.text
@ -195,8 +202,9 @@ while(whiletimes < mcversionsnumber):
#Count While Times.
whiletimes3=whiletimes3 + 1
whiletimesload3=whiletimes3 - 1
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries".
log('[INFO]:Starting to synchronize Files In "libraries".')
try:#Avoid Http/Httos Connection Errors Or Synchronize Module Download Failed Errors Making Whole Synchronize Stop.
#Synchronize Files In "libraries/.../downloads/artifact".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['artifact']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -204,12 +212,6 @@ while(whiletimes < mcversionsnumber):
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries/.../downloads/classifiers/javadoc".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['javadoc']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -217,12 +219,6 @@ while(whiletimes < mcversionsnumber):
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries/.../downloads/classifiers/natives-linux".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-linux']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -230,12 +226,6 @@ while(whiletimes < mcversionsnumber):
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries/.../downloads/classifiers/natives-macos".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-macos']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -243,12 +233,6 @@ while(whiletimes < mcversionsnumber):
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries/.../downloads/classifiers/natives-windows".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['natives-windows']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -256,12 +240,6 @@ while(whiletimes < mcversionsnumber):
filetosync3=fileurl3[::-1].split('/', 1)[-1][::-1]
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
#Use 'try' To Avoid Out Of Range Errors.
try:
#Synchronize Files In "libraries/.../downloads/artifact/classifiers/sources".
onlineurl3=mclibrariesload['libraries'][whiletimesload3]['downloads']['classifiers']['sources']['url']
onlineurlwithouthttps3=onlineurl3.replace('https://', 'http://')
@ -270,9 +248,9 @@ while(whiletimes < mcversionsnumber):
make_sure_dir_exists(filetosync3)
synchronize(onlineurlwithouthttps3, fileurl3)
except:
placeholder=''
finally:
placeholder=''
log('[ERROR]:There has a error in task of synchronizing files in ”libraries".')
else:
log('[INFO]:Synchronizing files in "libraries" successfully.')
log('[INFO]:Synchronizing files and dirs on https://libraries.minecraft.net/ successfully.')