mirror of
https://github.com/SmallJoker/minetest-u_skinsdb.git
synced 2025-02-15 16:40:19 +01:00
fixed pipelining
cleaning everything up, working around python's stupidity for capturing loop variables (it was saving every image as ...preview_584.png), testing it on 1-9 to make sure they come in as a single block of drains. It works, yay!
This commit is contained in:
parent
0021eb65c5
commit
aa175d8e1e
@ -12,8 +12,10 @@ def die(message,code=23):
|
||||
server = "minetest.fensta.bplaced.net"
|
||||
skinsdir = "u_skins/textures/"
|
||||
metadir = "u_skins/meta/"
|
||||
curskin = 580
|
||||
curpage = 59
|
||||
#curskin = 580
|
||||
#curpage = 59
|
||||
curskin = 0
|
||||
curpage = 1
|
||||
pages = None
|
||||
|
||||
def replace(location,base,encoding=None,path=None):
|
||||
@ -65,6 +67,7 @@ class Pipeline(list):
|
||||
self.drain()
|
||||
def trydrain(self):
|
||||
for penguin in self:
|
||||
print('drain',penguin.url)
|
||||
try:
|
||||
penguin.response.begin()
|
||||
penguin.recv(penguin.response)
|
||||
@ -73,10 +76,10 @@ class Pipeline(list):
|
||||
return False
|
||||
except HTTPException as e:
|
||||
die(penguin.diemessage+' '+repr(e)+' (url='+penguin.url+')')
|
||||
self.clear()
|
||||
return True
|
||||
self.clear()
|
||||
return True
|
||||
def drain(self):
|
||||
print('draining pipeline...')
|
||||
print('draining pipeline...',len(self))
|
||||
assert self.sent, "Can't drain without sending the requests!"
|
||||
self.sent = False
|
||||
while self.trydrain() is not True:
|
||||
@ -86,6 +89,7 @@ class Pipeline(list):
|
||||
self.reopen()
|
||||
def trysend(self):
|
||||
for penguin in pipeline:
|
||||
print('fill',penguin.url)
|
||||
try:
|
||||
self.c.request("GET", penguin.url)
|
||||
self.c._HTTPConnection__state = _CS_IDLE
|
||||
@ -99,7 +103,7 @@ class Pipeline(list):
|
||||
return True
|
||||
def send(self):
|
||||
if self.sent: return
|
||||
print('filling pipeline...')
|
||||
print('filling pipeline...',len(self))
|
||||
while self.trysend() is not True:
|
||||
self.c.close()
|
||||
print('derped resending')
|
||||
@ -152,15 +156,19 @@ with Pipeline() as pipeline:
|
||||
f.write(str(s["author"]) + '\n')
|
||||
f.write(str(s["license"]))
|
||||
url = "/skins/1/" + str(s["id"]) + ".png"
|
||||
def tryget(r):
|
||||
if r.status != 200:
|
||||
print("Error", r.status)
|
||||
return
|
||||
@replace(skinsdir,previewbase,path=preview)
|
||||
def go(f):
|
||||
shutil.copyfileobj(r,f)
|
||||
def closure(skinsdir,previewbase,preview,s):
|
||||
"explanation: python sucks"
|
||||
def tryget(r):
|
||||
print('replacing',s["id"])
|
||||
if r.status != 200:
|
||||
print("Error", r.status)
|
||||
return
|
||||
@replace(skinsdir,previewbase,path=preview)
|
||||
def go(f):
|
||||
shutil.copyfileobj(r,f)
|
||||
return tryget
|
||||
|
||||
pipeline.append(url,tryget,
|
||||
pipeline.append(url,closure(skinsdir,previewbase,preview,s),
|
||||
"Couldn't get {} because of a".format(
|
||||
s["id"]))
|
||||
if not foundOne:
|
||||
|
Loading…
Reference in New Issue
Block a user