Update erisupdate.py
Updated erisurl to have the eris.json from git.foxo.me
This commit is contained in:
parent
80d29edede
commit
8269c48d2f
843
erisupdate.py
843
erisupdate.py
|
@ -1,421 +1,422 @@
|
||||||
import json
|
import json
|
||||||
import urllib3
|
import urllib3
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import os
|
import os
|
||||||
import cgi
|
import cgi
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import argparse
|
import argparse
|
||||||
import string
|
import string
|
||||||
#import getpass
|
#import getpass
|
||||||
#print("Env thinks the user is [%s]" % (os.getlogin()))
|
#print("Env thinks the user is [%s]" % (os.getlogin()))
|
||||||
#print("Effective user is [%s]" % (getpass.getuser()))
|
#print("Effective user is [%s]" % (getpass.getuser()))
|
||||||
|
|
||||||
import erisscan
|
import erisscan
|
||||||
|
|
||||||
|
|
||||||
def filter_str(s: str) -> str:
|
def filter_str(s: str) -> str:
|
||||||
return "".join(filter(lambda x: x in string.printable, s))
|
return "".join(filter(lambda x: x in string.printable, s))
|
||||||
|
|
||||||
|
|
||||||
def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
def downloadcivitai(modelid: str, type: str, image: bool) -> bool:
|
||||||
|
|
||||||
match type:
|
match type:
|
||||||
case "lora":
|
case "lora":
|
||||||
dlpath = f"./models/Lora/"
|
dlpath = f"./models/Lora/"
|
||||||
case "sd":
|
case "sd":
|
||||||
dlpath = f"./models/Stable-diffusion/"
|
dlpath = f"./models/Stable-diffusion/"
|
||||||
case "emb":
|
case "emb":
|
||||||
dlpath = f"./embeddings/"
|
dlpath = f"./embeddings/"
|
||||||
|
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
urlid = f"https://civitai.com/api/v1/models/{modelid}"
|
urlid = f"https://civitai.com/api/v1/models/{modelid}"
|
||||||
resp = http.request('GET', urlid)
|
resp = http.request('GET', urlid)
|
||||||
modelarray = json.loads(resp.data.decode('utf-8'))
|
modelarray = json.loads(resp.data.decode('utf-8'))
|
||||||
modelsha256 = modelarray.get('modelVersions')[0].get('files')[0].get('hashes').get("SHA256")
|
modelsha256 = modelarray.get('modelVersions')[0].get('files')[0].get('hashes').get("SHA256")
|
||||||
urlhash = f"https://civitai.com/api/v1/model-versions/by-hash/{modelsha256}"
|
urlhash = f"https://civitai.com/api/v1/model-versions/by-hash/{modelsha256}"
|
||||||
modelimageurl = modelarray.get('modelVersions')[0].get('images')[0].get('url')
|
modelimageurl = modelarray.get('modelVersions')[0].get('images')[0].get('url')
|
||||||
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
||||||
#modelfilesize = int(modelarray.get('modelVersions')[0].get('files')[0].get('sizeKB'))
|
#modelfilesize = int(modelarray.get('modelVersions')[0].get('files')[0].get('sizeKB'))
|
||||||
modelname = Path(modelfilename).stem
|
modelname = Path(modelfilename).stem
|
||||||
modelfileurl = modelarray.get('modelVersions')[0].get('files')[0].get('downloadUrl')
|
modelfileurl = modelarray.get('modelVersions')[0].get('files')[0].get('downloadUrl')
|
||||||
#modeldisplayname = modelarray.get('name')
|
#modeldisplayname = modelarray.get('name')
|
||||||
#trainedwords = modelarray.get('modelVersions')[0].get('trainedWords')
|
#trainedwords = modelarray.get('modelVersions')[0].get('trainedWords')
|
||||||
|
|
||||||
modelimagename = [f"{modelname}.preview.jpg", f"{modelname}.preview.jpeg", f"{modelname}.preview.png"]
|
modelimagename = [f"{modelname}.preview.jpg", f"{modelname}.preview.jpeg", f"{modelname}.preview.png"]
|
||||||
#modelimagename = ""
|
#modelimagename = ""
|
||||||
modelinfofile = f"{modelname}.civitai.info"
|
modelinfofile = f"{modelname}.civitai.info"
|
||||||
|
|
||||||
|
|
||||||
def downloadmodel(url: str, dlpath: str) -> bool:
|
def downloadmodel(url: str, dlpath: str) -> bool:
|
||||||
print(f"Download {modelfilename} to {dlpath}")
|
print(f"Download {modelfilename} to {dlpath}")
|
||||||
dlrequest = http.request('GET', url, preload_content=False)
|
dlrequest = http.request('GET', url, preload_content=False)
|
||||||
filesize = dlrequest.getheader('content-length')
|
filesize = dlrequest.getheader('content-length')
|
||||||
contentdis = dlrequest.getheader('Content-Disposition')
|
contentdis = dlrequest.getheader('Content-Disposition')
|
||||||
try:
|
try:
|
||||||
type, filename = cgi.parse_header(contentdis)
|
type, filename = cgi.parse_header(contentdis)
|
||||||
#print("Found file", dict(filename).get('filename'))
|
#print("Found file", dict(filename).get('filename'))
|
||||||
filename = dict(filename).get('filename')
|
filename = dict(filename).get('filename')
|
||||||
#filename = filename.encode('utf-8')
|
#filename = filename.encode('utf-8')
|
||||||
#filename = filter_str(filename)
|
#filename = filter_str(filename)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Cannot get filename", e)
|
print("Cannot get filename", e)
|
||||||
if filesize:
|
if filesize:
|
||||||
filesize = int(filesize)
|
filesize = int(filesize)
|
||||||
blocksize = max(4096, filesize//100)
|
blocksize = max(4096, filesize//100)
|
||||||
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
||||||
else:
|
else:
|
||||||
blocksize = 10000
|
blocksize = 10000
|
||||||
#with open(f"{dlpath}{filename}", 'wb') as out:
|
#with open(f"{dlpath}{filename}", 'wb') as out:
|
||||||
with open(Path(dlpath) / filename, 'wb') as out:
|
with open(Path(dlpath) / filename, 'wb') as out:
|
||||||
size = 0
|
size = 0
|
||||||
while True:
|
while True:
|
||||||
data = dlrequest.read(blocksize)
|
data = dlrequest.read(blocksize)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
size += len(data)
|
size += len(data)
|
||||||
out.write(data)
|
out.write(data)
|
||||||
if filesize:
|
if filesize:
|
||||||
Percent = int((size / filesize)*100)
|
Percent = int((size / filesize)*100)
|
||||||
if Percent == 100:
|
if Percent == 100:
|
||||||
print(f"Download: {Percent}%")
|
print(f"Download: {Percent}%")
|
||||||
else:
|
else:
|
||||||
print(f"Download: {Percent}%", end='\r')
|
print(f"Download: {Percent}%", end='\r')
|
||||||
dlrequest.release_conn()
|
dlrequest.release_conn()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def downloadimage(url: str, dlpath: str) -> bool:
|
def downloadimage(url: str, dlpath: str) -> bool:
|
||||||
print(f"Download Image for {modelfilename}")
|
print(f"Download Image for {modelfilename}")
|
||||||
imagerequest = http.request('GET', url, preload_content=False)
|
imagerequest = http.request('GET', url, preload_content=False)
|
||||||
#path = f"{os.getcwd()}/models/Loras/"
|
#path = f"{os.getcwd()}/models/Loras/"
|
||||||
filesize = imagerequest.getheader('content-length')
|
filesize = imagerequest.getheader('content-length')
|
||||||
#contentdis = imagerequest.getheader('Content-Disposition')
|
#contentdis = imagerequest.getheader('Content-Disposition')
|
||||||
#type, filename = cgi.parse_header(contentdis)
|
#type, filename = cgi.parse_header(contentdis)
|
||||||
filename = f"{Path(modelfilename).stem}.preview{Path(filename).suffix}"
|
filename = f"{Path(modelfilename).stem}.preview{Path(filename).suffix}"
|
||||||
global modelimagename
|
global modelimagename
|
||||||
modelimagename = filename
|
modelimagename = filename
|
||||||
#print(filename['filename'])
|
#print(filename['filename'])
|
||||||
if filesize:
|
if filesize:
|
||||||
filesize = int(filesize)
|
filesize = int(filesize)
|
||||||
blocksize = max(4096, filesize//100)
|
blocksize = max(4096, filesize//100)
|
||||||
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
||||||
else:
|
else:
|
||||||
blocksize = 1000
|
blocksize = 1000
|
||||||
with open(f"{dlpath}{filename}", 'wb') as out:
|
with open(f"{dlpath}{filename}", 'wb') as out:
|
||||||
size = 0
|
size = 0
|
||||||
while True:
|
while True:
|
||||||
data = imagerequest.read(blocksize)
|
data = imagerequest.read(blocksize)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
size += len(data)
|
size += len(data)
|
||||||
out.write(data)
|
out.write(data)
|
||||||
if filesize:
|
if filesize:
|
||||||
Percent = int((size / filesize)*100)
|
Percent = int((size / filesize)*100)
|
||||||
if Percent == 100:
|
if Percent == 100:
|
||||||
print(f"Download: {Percent}%")
|
print(f"Download: {Percent}%")
|
||||||
else:
|
else:
|
||||||
print(f"Download: {Percent}%", end='\r')
|
print(f"Download: {Percent}%", end='\r')
|
||||||
imagerequest.release_conn()
|
imagerequest.release_conn()
|
||||||
|
|
||||||
def downloadinfo(url: str, dlfullpath: str) -> bool:
|
def downloadinfo(url: str, dlfullpath: str) -> bool:
|
||||||
print(f"Download Infofile for {modelfilename}")
|
print(f"Download Infofile for {modelfilename}")
|
||||||
resp = http.request('GET', url)
|
resp = http.request('GET', url)
|
||||||
infofile = open(f"{dlfullpath}", "w")
|
infofile = open(f"{dlfullpath}", "w")
|
||||||
infofile.write(resp.data.decode('utf-8'))
|
infofile.write(resp.data.decode('utf-8'))
|
||||||
infofile.close()
|
infofile.close()
|
||||||
|
|
||||||
# download Model file
|
# download Model file
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(f"{dlpath}{modelfilename}"):
|
if not os.path.exists(f"{dlpath}{modelfilename}"):
|
||||||
downloadmodel(modelfileurl, dlpath)
|
downloadmodel(modelfileurl, dlpath)
|
||||||
else:
|
else:
|
||||||
print(f"{modelfilename} already exist, skip download")
|
print(f"{modelfilename} already exist, skip download")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
finally:
|
finally:
|
||||||
if not os.path.exists(f"{dlpath}{modelfilename}"):
|
if not os.path.exists(f"{dlpath}{modelfilename}"):
|
||||||
print(f"{modelfilename} could not be saved, abort.")
|
print(f"{modelfilename} could not be saved, abort.")
|
||||||
return False
|
return False
|
||||||
# download Preview image, if not disabled
|
# download Preview image, if not disabled
|
||||||
if image:
|
if image:
|
||||||
try:
|
try:
|
||||||
if os.path.exists(f"{dlpath}{modelimagename[0]}") == False and os.path.exists(f"{dlpath}{modelimagename[1]}") == False and os.path.exists(f"{dlpath}{modelimagename[2]}") == False:
|
if os.path.exists(f"{dlpath}{modelimagename[0]}") == False and os.path.exists(f"{dlpath}{modelimagename[1]}") == False and os.path.exists(f"{dlpath}{modelimagename[2]}") == False:
|
||||||
downloadimage(modelimageurl, dlpath)
|
downloadimage(modelimageurl, dlpath)
|
||||||
else:
|
else:
|
||||||
print(f"Preview Image for {modelfilename} already exist, skip download")
|
print(f"Preview Image for {modelfilename} already exist, skip download")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
finally:
|
finally:
|
||||||
if isinstance(modelfilename, str):
|
if isinstance(modelfilename, str):
|
||||||
if not os.path.exists(f"{dlpath}{modelimagename}"):
|
if not os.path.exists(f"{dlpath}{modelimagename}"):
|
||||||
print(f"{modelfilename} could not be saved, continue.")
|
print(f"{modelfilename} could not be saved, continue.")
|
||||||
# save infofile
|
# save infofile
|
||||||
try:
|
try:
|
||||||
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
||||||
downloadinfo(urlhash, f"{dlpath}{modelinfofile}")
|
downloadinfo(urlhash, f"{dlpath}{modelinfofile}")
|
||||||
else:
|
else:
|
||||||
print(f"{modelinfofile} already exist, skip creation")
|
print(f"{modelinfofile} already exist, skip creation")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
finally:
|
finally:
|
||||||
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
if not os.path.exists(f"{dlpath}{modelinfofile}"):
|
||||||
print(f"{modelinfofile} could not be created, abort.")
|
print(f"{modelinfofile} could not be created, abort.")
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# ______________________________________________________________________
|
# ______________________________________________________________________
|
||||||
|
|
||||||
def downloadsideload(name: str, modeltype: str) -> bool:
|
def downloadsideload(name: str, modeltype: str) -> bool:
|
||||||
sideloadserver = f"https://eris.hitmare.me/eris/{modeltype}/"
|
sideloadserver = f"https://eris.hitmare.me/eris/{modeltype}/"
|
||||||
|
|
||||||
match modeltype:
|
match modeltype:
|
||||||
case "lora":
|
case "lora":
|
||||||
dlpath = "./models/lora/"
|
dlpath = "./models/lora/"
|
||||||
case "sd":
|
case "sd":
|
||||||
dlpath = "./models/stable-diffusion/"
|
dlpath = "./models/stable-diffusion/"
|
||||||
case "emb":
|
case "emb":
|
||||||
dlpath = "./embeddings/"
|
dlpath = "./embeddings/"
|
||||||
|
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
url = f"{sideloadserver}{name}"
|
url = f"{sideloadserver}{name}"
|
||||||
try:
|
try:
|
||||||
print(f"Download {name}")
|
print(f"Download {name}")
|
||||||
dlrequest = http.request('GET', url, preload_content=False)
|
dlrequest = http.request('GET', url, preload_content=False)
|
||||||
|
|
||||||
if not int(dlrequest.status) == 200:
|
if not int(dlrequest.status) == 200:
|
||||||
print(f"File {name} not found")
|
print(f"File {name} not found")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
filesize = dlrequest.getheader('content-length')
|
filesize = dlrequest.getheader('content-length')
|
||||||
#print(filesize)
|
#print(filesize)
|
||||||
#contentdis = dlrequest.getheader('Content-Disposition')
|
#contentdis = dlrequest.getheader('Content-Disposition')
|
||||||
#type, filename = cgi.parse_header(contentdis)
|
#type, filename = cgi.parse_header(contentdis)
|
||||||
filename = name
|
filename = name
|
||||||
if filesize:
|
if filesize:
|
||||||
filesize = int(filesize)
|
filesize = int(filesize)
|
||||||
blocksize = max(4096, filesize//100)
|
blocksize = max(4096, filesize//100)
|
||||||
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
print(f"Filesize: {filesize//1024} kB | {filesize//1024//1024} MB")
|
||||||
else:
|
else:
|
||||||
blocksize = 10000
|
blocksize = 10000
|
||||||
with open(f"{dlpath}{filename}", 'wb') as out:
|
with open(f"{dlpath}{filename}", 'wb') as out:
|
||||||
size = 0
|
size = 0
|
||||||
while True:
|
while True:
|
||||||
data = dlrequest.read(blocksize)
|
data = dlrequest.read(blocksize)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
size += len(data)
|
size += len(data)
|
||||||
out.write(data)
|
out.write(data)
|
||||||
if filesize:
|
if filesize:
|
||||||
Percent = int((size / filesize)*100)
|
Percent = int((size / filesize)*100)
|
||||||
if Percent == 100:
|
if Percent == 100:
|
||||||
print(f"Download: {Percent}%")
|
print(f"Download: {Percent}%")
|
||||||
else:
|
else:
|
||||||
print(f"Download: {Percent}%", end='\r')
|
print(f"Download: {Percent}%", end='\r')
|
||||||
print(f"Downloaded {dlpath}{filename}")
|
print(f"Downloaded {dlpath}{filename}")
|
||||||
dlrequest.release_conn()
|
dlrequest.release_conn()
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(name, "not found on Sideloadserver", " | Python Error:" ,e)
|
print(name, "not found on Sideloadserver", " | Python Error:" ,e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ______________________________________________________________________
|
# ______________________________________________________________________
|
||||||
# check current status of online and local lora
|
# check current status of online and local lora
|
||||||
def checkcivitai(locallist: list, erislist: list) -> tuple:
|
def checkcivitai(locallist: list, erislist: list) -> tuple:
|
||||||
#print("Check Civitai")
|
#print("Check Civitai")
|
||||||
#url = "https://eris.hitmare.me/lora.txt"
|
#url = "https://eris.hitmare.me/lora.txt"
|
||||||
erismodels = erislist
|
erismodels = erislist
|
||||||
localmodels = locallist
|
localmodels = locallist
|
||||||
missingmodels = set()
|
missingmodels = set()
|
||||||
additionalmodels = set()
|
additionalmodels = set()
|
||||||
savedmodels = set()
|
savedmodels = set()
|
||||||
# check online list against local list
|
# check online list against local list
|
||||||
for loraid in erismodels:
|
for loraid in erismodels:
|
||||||
if not loraid in localmodels:
|
if not loraid in localmodels:
|
||||||
missingmodels.add(loraid)
|
missingmodels.add(loraid)
|
||||||
else:
|
else:
|
||||||
savedmodels.add(loraid)
|
savedmodels.add(loraid)
|
||||||
|
|
||||||
# check local list against online list
|
# check local list against online list
|
||||||
for loraid in localmodels:
|
for loraid in localmodels:
|
||||||
if not loraid in erismodels:
|
if not loraid in erismodels:
|
||||||
additionalmodels.add(loraid)
|
additionalmodels.add(loraid)
|
||||||
|
|
||||||
return tuple((missingmodels, additionalmodels, savedmodels))
|
return tuple((missingmodels, additionalmodels, savedmodels))
|
||||||
|
|
||||||
|
|
||||||
def checksideload(locallist: list, erislist: list) -> tuple:
|
def checksideload(locallist: list, erislist: list) -> tuple:
|
||||||
#print("Check Sideload")
|
#print("Check Sideload")
|
||||||
#url = "https://eris.hitmare.me/lora.txt"
|
#url = "https://eris.hitmare.me/lora.txt"
|
||||||
erismodels = erislist
|
erismodels = erislist
|
||||||
localmodels = locallist
|
localmodels = locallist
|
||||||
missingmodels = set()
|
missingmodels = set()
|
||||||
additionalmodels = set()
|
additionalmodels = set()
|
||||||
savedmodels = set()
|
savedmodels = set()
|
||||||
# check online list against local list
|
# check online list against local list
|
||||||
for loraid in erismodels:
|
for loraid in erismodels:
|
||||||
if not loraid in localmodels:
|
if not loraid in localmodels:
|
||||||
missingmodels.add(loraid)
|
missingmodels.add(loraid)
|
||||||
else:
|
else:
|
||||||
savedmodels.add(loraid)
|
savedmodels.add(loraid)
|
||||||
|
|
||||||
# check local list against online list
|
# check local list against online list
|
||||||
for loraid in localmodels:
|
for loraid in localmodels:
|
||||||
if not loraid in erismodels:
|
if not loraid in erismodels:
|
||||||
additionalmodels.add(loraid)
|
additionalmodels.add(loraid)
|
||||||
|
|
||||||
return tuple((missingmodels, additionalmodels, savedmodels))
|
return tuple((missingmodels, additionalmodels, savedmodels))
|
||||||
|
|
||||||
def deleteFiles(nameid: str, modeltype: str, localfile: bool = False) -> bool:
|
def deleteFiles(nameid: str, modeltype: str, localfile: bool = False) -> bool:
|
||||||
match modeltype:
|
match modeltype:
|
||||||
case "lora":
|
case "lora":
|
||||||
dlpath = "./models/lora/"
|
dlpath = "./models/lora/"
|
||||||
case "sd":
|
case "sd":
|
||||||
dlpath = "./models/stable-diffusion/"
|
dlpath = "./models/stable-diffusion/"
|
||||||
case "emb":
|
case "emb":
|
||||||
dlpath = "./embeddings/"
|
dlpath = "./embeddings/"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if localfile:
|
if localfile:
|
||||||
modelfilename = nameid
|
modelfilename = nameid
|
||||||
else:
|
else:
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
urlid = f"https://civitai.com/api/v1/models/{nameid}"
|
urlid = f"https://civitai.com/api/v1/models/{nameid}"
|
||||||
resp = http.request('GET', urlid)
|
resp = http.request('GET', urlid)
|
||||||
modelarray = json.loads(resp.data.decode('utf-8'))
|
modelarray = json.loads(resp.data.decode('utf-8'))
|
||||||
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
modelfilename = modelarray.get('modelVersions')[0].get('files')[0].get('name')
|
||||||
|
|
||||||
modelfiles = os.listdir(dlpath)
|
modelfiles = os.listdir(dlpath)
|
||||||
for modelfile in modelfiles:
|
for modelfile in modelfiles:
|
||||||
if Path(modelfile).stem == Path(modelfilename).stem:
|
if Path(modelfile).stem == Path(modelfilename).stem:
|
||||||
os.remove(f"{dlpath}{modelfile}")
|
os.remove(f"{dlpath}{modelfile}")
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Could not delete {nameid}. Error: {e}")
|
print(f"Could not delete {nameid}. Error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog='Eris File Updater',
|
prog='Eris File Updater',
|
||||||
description='Updates Lora, Embeddings and Stable-diffusion Models',
|
description='Updates Lora, Embeddings and Stable-diffusion Models',
|
||||||
epilog='Thanks for being a part of the Eris Bot ^-^')
|
epilog='Thanks for being a part of the Eris Bot ^-^')
|
||||||
|
|
||||||
parser.add_argument('-si', '--skipimage', help=r"Skips the download of the preview images, Applies to all Model Types", action="store_true")
|
parser.add_argument('-si', '--skipimage', help=r"Skips the download of the preview images, Applies to all Model Types", action="store_true")
|
||||||
parser.add_argument('-sl', '--skiplora', help=r"Skips check of lora models", action="store_true")
|
parser.add_argument('-sl', '--skiplora', help=r"Skips check of lora models", action="store_true")
|
||||||
parser.add_argument('-ss', '--skipsdmodel', help=r"Skips check of stable-diffusion models", action="store_true")
|
parser.add_argument('-ss', '--skipsdmodel', help=r"Skips check of stable-diffusion models", action="store_true")
|
||||||
parser.add_argument('-se', '--skipemb', help=r"Skips check of embedding models", action="store_true")
|
parser.add_argument('-se', '--skipemb', help=r"Skips check of embedding models", action="store_true")
|
||||||
parser.add_argument('-c', '--cleanup', help=r"Deletes any models that are locally but not on the eris model list. Affected by Skip Triggers", action="store_true")
|
parser.add_argument('-c', '--cleanup', help=r"Deletes any models that are locally but not on the eris model list. Affected by Skip Triggers", action="store_true")
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
if not os.path.exists("./eris.json"):
|
if not os.path.exists("./eris.json"):
|
||||||
# start scan python or exit
|
# start scan python or exit
|
||||||
#print("Please run the erisscan bat/sh file first")
|
#print("Please run the erisscan bat/sh file first")
|
||||||
#exit()
|
#exit()
|
||||||
print("No eris.json file found. Starting scan ...")
|
print("No eris.json file found. Starting scan ...")
|
||||||
erisscan.scanall()
|
erisscan.scanall()
|
||||||
|
|
||||||
|
|
||||||
# get the eris list from the web and local
|
# get the eris list from the web and local
|
||||||
http = urllib3.PoolManager()
|
http = urllib3.PoolManager()
|
||||||
erisurl = "https://eris.hitmare.me/eris.json"
|
#erisurl = "https://eris.hitmare.me/eris.json"
|
||||||
resp = http.request('GET', erisurl)
|
erisurl = "https://git.foxo.me/Hitmare/Eris-Update-script/src/branch/main/eris.json"
|
||||||
erisremote = json.loads(resp.data.decode('utf-8'))
|
resp = http.request('GET', erisurl)
|
||||||
erislocal = json.load(open("./eris.json", "r"))
|
erisremote = json.loads(resp.data.decode('utf-8'))
|
||||||
|
erislocal = json.load(open("./eris.json", "r"))
|
||||||
if args.skipimage:
|
|
||||||
dlimage = False
|
if args.skipimage:
|
||||||
else:
|
dlimage = False
|
||||||
dlimage = True
|
else:
|
||||||
|
dlimage = True
|
||||||
if args.skiplora:
|
|
||||||
print("Skip Lora Model check")
|
if args.skiplora:
|
||||||
else:
|
print("Skip Lora Model check")
|
||||||
lorastate = checkcivitai(erislocal.get('lora')['civitai'], erisremote.get('lora')['civitai'])
|
else:
|
||||||
if len(lorastate[0]) > 0 :
|
lorastate = checkcivitai(erislocal.get('lora')['civitai'], erisremote.get('lora')['civitai'])
|
||||||
print(f"Missing lora ids: {lorastate[0]}")
|
if len(lorastate[0]) > 0 :
|
||||||
for lora in lorastate[0]:
|
print(f"Missing lora ids: {lorastate[0]}")
|
||||||
if downloadcivitai(lora, 'lora', dlimage):
|
for lora in lorastate[0]:
|
||||||
erislocal.get('lora')['civitai'].append(lora)
|
if downloadcivitai(lora, 'lora', dlimage):
|
||||||
lorasideloadstate = checksideload(erislocal.get('lora')['sideload'], erisremote.get('lora')['sideload'])
|
erislocal.get('lora')['civitai'].append(lora)
|
||||||
if len(lorasideloadstate[0]) > 0 :
|
lorasideloadstate = checksideload(erislocal.get('lora')['sideload'], erisremote.get('lora')['sideload'])
|
||||||
print(f"Missing lora files: {lorasideloadstate[0]}")
|
if len(lorasideloadstate[0]) > 0 :
|
||||||
for lora in lorasideloadstate[0]:
|
print(f"Missing lora files: {lorasideloadstate[0]}")
|
||||||
if downloadsideload(lora, 'lora'):
|
for lora in lorasideloadstate[0]:
|
||||||
erislocal.get('lora')['sideload'].append(lora)
|
if downloadsideload(lora, 'lora'):
|
||||||
if args.cleanup:
|
erislocal.get('lora')['sideload'].append(lora)
|
||||||
if len(lorastate[1]) > 0:
|
if args.cleanup:
|
||||||
print("Additional CivitAI lora ids:", lorastate[1])
|
if len(lorastate[1]) > 0:
|
||||||
for dellora in lorastate[1]:
|
print("Additional CivitAI lora ids:", lorastate[1])
|
||||||
if deleteFiles(dellora, 'lora'):
|
for dellora in lorastate[1]:
|
||||||
erislocal.get('lora')['civitai'].remove(dellora)
|
if deleteFiles(dellora, 'lora'):
|
||||||
if len(lorasideloadstate[1]) > 0:
|
erislocal.get('lora')['civitai'].remove(dellora)
|
||||||
print("Additional CivitAI lora files:", lorastate[1])
|
if len(lorasideloadstate[1]) > 0:
|
||||||
for delslora in lorasideloadstate[1]:
|
print("Additional CivitAI lora files:", lorastate[1])
|
||||||
if deleteFiles(delslora, 'lora', True):
|
for delslora in lorasideloadstate[1]:
|
||||||
erislocal.get('lora')['sideload'].remove(delslora)
|
if deleteFiles(delslora, 'lora', True):
|
||||||
#print(len(lorastate[1]))
|
erislocal.get('lora')['sideload'].remove(delslora)
|
||||||
if args.skipsdmodel:
|
#print(len(lorastate[1]))
|
||||||
print("Skip Stable-Diffusion Model check")
|
if args.skipsdmodel:
|
||||||
else:
|
print("Skip Stable-Diffusion Model check")
|
||||||
sdstate = checkcivitai(erislocal.get('sd')['civitai'], erisremote.get('sd')['civitai'])
|
else:
|
||||||
if len(sdstate[0]) > 0 :
|
sdstate = checkcivitai(erislocal.get('sd')['civitai'], erisremote.get('sd')['civitai'])
|
||||||
print(f"Missing CivitAI stable-diffusion ids: {sdstate[0]}")
|
if len(sdstate[0]) > 0 :
|
||||||
for sd in sdstate[0]:
|
print(f"Missing CivitAI stable-diffusion ids: {sdstate[0]}")
|
||||||
if downloadcivitai(sd, 'sd', dlimage):
|
for sd in sdstate[0]:
|
||||||
erislocal.get('sd')['civitai'].append(sd)
|
if downloadcivitai(sd, 'sd', dlimage):
|
||||||
sdsideloadstate = checksideload(erislocal.get('sd')['sideload'], erisremote.get('sd')['sideload'])
|
erislocal.get('sd')['civitai'].append(sd)
|
||||||
if len(sdsideloadstate[0]) > 0 :
|
sdsideloadstate = checksideload(erislocal.get('sd')['sideload'], erisremote.get('sd')['sideload'])
|
||||||
print(f"Missing Sideload stable-diffusion files: {sdsideloadstate[0]}")
|
if len(sdsideloadstate[0]) > 0 :
|
||||||
for sd in sdsideloadstate[0]:
|
print(f"Missing Sideload stable-diffusion files: {sdsideloadstate[0]}")
|
||||||
if downloadsideload(sd, 'sd'):
|
for sd in sdsideloadstate[0]:
|
||||||
erislocal.get('sd')['sideload'].append(sd)
|
if downloadsideload(sd, 'sd'):
|
||||||
if args.cleanup:
|
erislocal.get('sd')['sideload'].append(sd)
|
||||||
if len(sdstate[1]) > 0:
|
if args.cleanup:
|
||||||
print("Additional CivitAI stable-diffusion ids:", sdstate[1])
|
if len(sdstate[1]) > 0:
|
||||||
for delsd in sdstate[1]:
|
print("Additional CivitAI stable-diffusion ids:", sdstate[1])
|
||||||
if deleteFiles(delsd, 'lora'):
|
for delsd in sdstate[1]:
|
||||||
erislocal.get('sd')['civitai'].remove(delsd)
|
if deleteFiles(delsd, 'lora'):
|
||||||
if len(sdsideloadstate[1]) > 0:
|
erislocal.get('sd')['civitai'].remove(delsd)
|
||||||
print("Additional Sideload stable-diffusion files:", sdstate[1])
|
if len(sdsideloadstate[1]) > 0:
|
||||||
for delssd in sdsideloadstate[1]:
|
print("Additional Sideload stable-diffusion files:", sdstate[1])
|
||||||
if deleteFiles(delssd, 'lora', True):
|
for delssd in sdsideloadstate[1]:
|
||||||
erislocal.get('sd')['sideload'].remove(delssd)
|
if deleteFiles(delssd, 'lora', True):
|
||||||
|
erislocal.get('sd')['sideload'].remove(delssd)
|
||||||
if args.skipemb:
|
|
||||||
print("Skip Embedding Model check")
|
if args.skipemb:
|
||||||
else:
|
print("Skip Embedding Model check")
|
||||||
embstate = checkcivitai(erislocal.get('emb')['civitai'], erisremote.get('emb')['civitai'])
|
else:
|
||||||
if len(embstate[0]) > 0 :
|
embstate = checkcivitai(erislocal.get('emb')['civitai'], erisremote.get('emb')['civitai'])
|
||||||
print(f"Missing embedding ids: {embstate[0]}")
|
if len(embstate[0]) > 0 :
|
||||||
for emb in embstate[0]:
|
print(f"Missing embedding ids: {embstate[0]}")
|
||||||
if downloadcivitai(emb, 'emb', dlimage):
|
for emb in embstate[0]:
|
||||||
erislocal.get('emb')['civitai'].append(emb)
|
if downloadcivitai(emb, 'emb', dlimage):
|
||||||
embsideloadstate = checksideload(erislocal.get('emb')['sideload'], erisremote.get('emb')['sideload'])
|
erislocal.get('emb')['civitai'].append(emb)
|
||||||
if len(embsideloadstate[0]) > 0 :
|
embsideloadstate = checksideload(erislocal.get('emb')['sideload'], erisremote.get('emb')['sideload'])
|
||||||
print(f"Missing embedding files: {embsideloadstate[0]}")
|
if len(embsideloadstate[0]) > 0 :
|
||||||
for emb in embsideloadstate[0]:
|
print(f"Missing embedding files: {embsideloadstate[0]}")
|
||||||
if downloadsideload(emb, 'emb'):
|
for emb in embsideloadstate[0]:
|
||||||
erislocal.get('emb')['sideload'].append(emb)
|
if downloadsideload(emb, 'emb'):
|
||||||
if args.cleanup:
|
erislocal.get('emb')['sideload'].append(emb)
|
||||||
if len(embstate[1]) > 0:
|
if args.cleanup:
|
||||||
print("Additional CivitAI embedding ids:", embstate[1])
|
if len(embstate[1]) > 0:
|
||||||
for delemb in embstate[1]:
|
print("Additional CivitAI embedding ids:", embstate[1])
|
||||||
if deleteFiles(delemb, 'lora'):
|
for delemb in embstate[1]:
|
||||||
erislocal.get('emb')['civitai'].remove(delemb)
|
if deleteFiles(delemb, 'lora'):
|
||||||
if len(embsideloadstate[1]) > 0:
|
erislocal.get('emb')['civitai'].remove(delemb)
|
||||||
print("Additional Sideload embedding files:", embsideloadstate[1])
|
if len(embsideloadstate[1]) > 0:
|
||||||
for delsemb in embsideloadstate[1]:
|
print("Additional Sideload embedding files:", embsideloadstate[1])
|
||||||
if deleteFiles(delsemb, 'lora', True):
|
for delsemb in embsideloadstate[1]:
|
||||||
erislocal.get('emb')['sideload'].remove(delsemb)
|
if deleteFiles(delsemb, 'lora', True):
|
||||||
|
erislocal.get('emb')['sideload'].remove(delsemb)
|
||||||
erisjsonfile = open("./eris.json", "w")
|
|
||||||
erisjsonfile.write(json.dumps(erislocal, indent=2))
|
erisjsonfile = open("./eris.json", "w")
|
||||||
erisjsonfile.close()
|
erisjsonfile.write(json.dumps(erislocal, indent=2))
|
||||||
|
erisjsonfile.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue