LogOutput Update
This commit is contained in:
parent
1c2851e36b
commit
ce21a4ce29
72
core.py
72
core.py
@ -22,10 +22,6 @@ class MultiThreadDownload(threading.Thread):
|
|||||||
|
|
||||||
class GMCLCore(object):
|
class GMCLCore(object):
|
||||||
'''The Main Class of the Launcher Core'''
|
'''The Main Class of the Launcher Core'''
|
||||||
'''
|
|
||||||
self.__GamePath=GamePath
|
|
||||||
self.__Version=Version
|
|
||||||
'''
|
|
||||||
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0",LogOutput=False):
|
def __init__(self,LauncherName="GMCLCore",LauncherVersion="A0.2.0",LogOutput=False):
|
||||||
'''The global variable set function'''
|
'''The global variable set function'''
|
||||||
''':LauncherName The name of your launcher,the default value is "GMCLCore"'''
|
''':LauncherName The name of your launcher,the default value is "GMCLCore"'''
|
||||||
@ -36,6 +32,10 @@ class GMCLCore(object):
|
|||||||
self.__LogOutput=LogOutput
|
self.__LogOutput=LogOutput
|
||||||
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
self.__UserAgent={'User-Agent':LauncherName+'/'+LauncherVersion+' ((GMCL Core Alpha 0.2.0;Alpha))'}
|
||||||
self.__Log=[]
|
self.__Log=[]
|
||||||
|
self.__AuthWay=""
|
||||||
|
self.Log("info","Successful.","__init__")
|
||||||
|
def __del__(self):
|
||||||
|
self.Log("info","Successful.","__del__")
|
||||||
def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"):
|
def Log(self,Type,Text,Function="Anonymous Function",ErrorType="TypeError"):
|
||||||
'''The function which was used to manager the log output system'''
|
'''The function which was used to manager the log output system'''
|
||||||
''':Type Type of the log info'''
|
''':Type Type of the log info'''
|
||||||
@ -60,6 +60,14 @@ class GMCLCore(object):
|
|||||||
else:
|
else:
|
||||||
self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),Function,Text))
|
self.__Log.append(("OTHER",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),Function,Text))
|
||||||
return ("OTHER",Text)
|
return ("OTHER",Text)
|
||||||
|
def ReturnLog(self):
|
||||||
|
'''The function which was used to return the list of program log'''
|
||||||
|
self.Log("info","Successful.","ReturnLog")
|
||||||
|
return self.__Log
|
||||||
|
def PrintLog(self):
|
||||||
|
'''The function which was used to print the list of program log'''
|
||||||
|
self.Log("info","Successful.","PrintLog")
|
||||||
|
print(self.__Log)
|
||||||
def MakeDir(self,Path):
|
def MakeDir(self,Path):
|
||||||
'''The function which was used to create a dir with determination'''
|
'''The function which was used to create a dir with determination'''
|
||||||
''':Path The path of the dir you want to create'''
|
''':Path The path of the dir you want to create'''
|
||||||
@ -121,12 +129,12 @@ class GMCLCore(object):
|
|||||||
self.__ID=result['selectedProfile']['name']
|
self.__ID=result['selectedProfile']['name']
|
||||||
self.Log("info","Success.","GetAccount")
|
self.Log("info","Success.","GetAccount")
|
||||||
else:
|
else:
|
||||||
return Log("warn","Fail to request Mojang\'s auth server.","SetAccount")
|
return self.Log("warn","Fail to request Mojang\'s auth server.","SetAccount")
|
||||||
else:
|
else:
|
||||||
return Log("warn","Wrong Account.","SetAccount")
|
return self.Log("warn","Wrong Account.","SetAccount")
|
||||||
elif(self.__AuthWay=="offline"):
|
elif(self.__AuthWay=="offline"):
|
||||||
if(Account.count("@")==1):
|
if(Account.count("@")==1):
|
||||||
return Log("warn","Wrong Account.","SetAccount")
|
return self.Log("warn","Wrong Account.","SetAccount")
|
||||||
else:
|
else:
|
||||||
self.__ID=Account
|
self.__ID=Account
|
||||||
self.__UUID=self.GetUUID(Account)
|
self.__UUID=self.GetUUID(Account)
|
||||||
@ -139,60 +147,66 @@ class GMCLCore(object):
|
|||||||
''':AuthWay Your auth way,must be "offline" or "online"'''
|
''':AuthWay Your auth way,must be "offline" or "online"'''
|
||||||
if(AuthWay=="offline"):
|
if(AuthWay=="offline"):
|
||||||
self.__AuthWay="offline"
|
self.__AuthWay="offline"
|
||||||
|
self.Log("info","Success.","SetAuthWay")
|
||||||
elif(AuthWay=="online"):
|
elif(AuthWay=="online"):
|
||||||
self.__AuthWay="online"
|
self.__AuthWay="online"
|
||||||
|
self.Log("info","Success.","SetAuthWay")
|
||||||
else:
|
else:
|
||||||
return "Error:Wrong Auth Way."
|
self.Log("warn","Wrong Auth Way.","SetAccount")
|
||||||
def SetRecomMem(self):
|
def SetRecomMem(self):
|
||||||
'''The recommendation memory value set function'''
|
'''The recommendation memory value set function'''
|
||||||
self.__Memory = float(psutil.virtual_memory().free / 1024 ** 3) * 0.8
|
self.__Memory = float(psutil.virtual_memory().free / 1024 ** 3) * 0.8
|
||||||
|
self.Log("info","Success.","SetRecomMem")
|
||||||
def SetJavaPath(self,path):
|
def SetJavaPath(self,path):
|
||||||
'''The java path set function'''
|
'''The java path set function'''
|
||||||
''':Path Your java path'''
|
''':Path Your java path'''
|
||||||
if(path==None):
|
if(path==None):
|
||||||
return "Error:Wrong local address for java."
|
self.Log("warn","Wrong local address for java.","SetJavaPath")
|
||||||
else:
|
else:
|
||||||
if(os.path.exists(path)):
|
if(os.path.exists(path)):
|
||||||
self.__JAVA=path
|
self.__JAVA=path
|
||||||
|
self.Log("info","Success.","SetJavaPath")
|
||||||
else:
|
else:
|
||||||
return "Error:Wrong local address for java."
|
self.Log("warn","Wrong local address for java.","SetJavaPath")
|
||||||
def SetGameMem(self,Memory):
|
def SetGameMem(self,Memory):
|
||||||
'''The game memory value set function'''
|
'''The game memory value set function'''
|
||||||
''':Memory The memory of the game,the unit is GiBytes'''
|
''':Memory The memory of the game,the unit is GiBytes'''
|
||||||
try:
|
try:
|
||||||
self.__Memory=float(Memory)
|
self.__Memory=float(Memory)
|
||||||
|
self.Log("info","Success.","SetGameMem")
|
||||||
except:
|
except:
|
||||||
return "Error:Wrong parameter for game memory."
|
self.Log("warn","Wrong parameter for game memory.","SetGameMem")
|
||||||
def Download(self,DownloadFrom,DownloadTo,ThreadNum=3):
|
def Download(self,DownloadFrom,DownloadTo,ThreadNum=3):
|
||||||
'''The multi-thread download function'''
|
'''The multi-thread download function'''
|
||||||
''':DownloadFrom The online url for the file'''
|
''':DownloadFrom The online url for the file'''
|
||||||
''':DownloadTo The local path for the file'''
|
''':DownloadTo The local path for the file'''
|
||||||
''':ThreadNum The number of the thread,the default value is 3'''
|
''':ThreadNum The number of the thread,the default value is 3'''
|
||||||
if(DownloadFrom=="" or DownloadTo==""):
|
if(DownloadFrom=="" or DownloadTo==""):
|
||||||
return "Error:Wrong online address or local address for download."
|
self.Log("warn","Wrong online address or local address for download.","Download")
|
||||||
else:
|
else:
|
||||||
url = DownloadFrom
|
url=DownloadFrom
|
||||||
filename = DownloadTo
|
filename=DownloadTo
|
||||||
filesize = int(requests.head(url,headers=self.__UserAgent).headers['Content-Length'])
|
filesize=int(requests.head(url,headers=self.__UserAgent).headers['Content-Length'])
|
||||||
threadnum = ThreadNum
|
threadnum=ThreadNum
|
||||||
threading.BoundedSemaphore(threadnum)
|
threading.BoundedSemaphore(threadnum)
|
||||||
step = filesize // threadnum
|
step=filesize // threadnum
|
||||||
mtd_list = []
|
mtd_list=[]
|
||||||
start = 0
|
start=0
|
||||||
end = -1
|
end=-1
|
||||||
tempf = open(filename,'w')
|
tempf=open(filename,'w')
|
||||||
tempf.close()
|
tempf.close()
|
||||||
with open(filename,'rb+') as f:
|
with open(filename,'rb+') as f:
|
||||||
fileno = f.fileno()
|
fileno=f.fileno()
|
||||||
while end < filesize -1:
|
while end < filesize -1:
|
||||||
start = end +1
|
start=end +1
|
||||||
end = start + step -1
|
end=start + step -1
|
||||||
if end > filesize:
|
if end > filesize:
|
||||||
end = filesize
|
end=filesize
|
||||||
dup = os.dup(fileno)
|
dup=os.dup(fileno)
|
||||||
fd = os.fdopen(dup,'rb+',-1)
|
fd=os.fdopen(dup,'rb+',-1)
|
||||||
t = MultiThreadDownload(url,start,end,fd,self.__UserAgent)
|
t=MultiThreadDownload(url,start,end,fd,self.__UserAgent)
|
||||||
t.start()
|
t.start()
|
||||||
mtd_list.append(t)
|
mtd_list.append(t)
|
||||||
for i in mtd_list:
|
for i in mtd_list:
|
||||||
i.join()
|
i.join()
|
||||||
|
self.Log("info","Success.","Download")
|
||||||
|
Reference in New Issue
Block a user