Fixes
This commit is contained in:
parent
777920a456
commit
cb72fdb870
1 changed files with 32 additions and 14 deletions
|
@ -15,6 +15,7 @@ from sorteerhoed.Signal import Signal
|
||||||
import io
|
import io
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
import datetime
|
import datetime
|
||||||
|
from shutil import copyfile
|
||||||
|
|
||||||
|
|
||||||
class CentralManagement():
|
class CentralManagement():
|
||||||
|
@ -99,6 +100,7 @@ class CentralManagement():
|
||||||
time.sleep(.5)
|
time.sleep(.5)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
self.logger.warning("Stopping Central Managment")
|
||||||
self.isRunning.clear()
|
self.isRunning.clear()
|
||||||
self.server.stop()
|
self.server.stop()
|
||||||
|
|
||||||
|
@ -183,7 +185,11 @@ class CentralManagement():
|
||||||
#{'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentAbandoned', 'EventTimestamp': '2019-10-23T20:23:06Z', 'HITId': '3JHB4BPSFKKFQ263K4EFULI3LC79QJ', 'AssignmentId': '3U088ZLJVL450PB6MJZUIIUCB6VW0Y', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}}
|
#{'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentAbandoned', 'EventTimestamp': '2019-10-23T20:23:06Z', 'HITId': '3JHB4BPSFKKFQ263K4EFULI3LC79QJ', 'AssignmentId': '3U088ZLJVL450PB6MJZUIIUCB6VW0Y', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}}
|
||||||
sqsHit.accept_time = None
|
sqsHit.accept_time = None
|
||||||
sqsHit.open_page_at = None
|
sqsHit.open_page_at = None
|
||||||
|
if self.currentHit.id == sqsHit.id:
|
||||||
|
if not sqsHit.submit_page_at:
|
||||||
self.reset()
|
self.reset()
|
||||||
|
else:
|
||||||
|
sqsHit.submit_hit_at = datetime.datetime.utcnow() # fake submit
|
||||||
if updateStatus:
|
if updateStatus:
|
||||||
self.setLight(False)
|
self.setLight(False)
|
||||||
|
|
||||||
|
@ -191,7 +197,11 @@ class CentralManagement():
|
||||||
self.logger.info(f'Set status progress to returned')
|
self.logger.info(f'Set status progress to returned')
|
||||||
sqsHit.accept_time = None
|
sqsHit.accept_time = None
|
||||||
sqsHit.open_page_at = None
|
sqsHit.open_page_at = None
|
||||||
|
if self.currentHit.id == sqsHit.id:
|
||||||
|
if not sqsHit.submit_page_at:
|
||||||
self.reset()
|
self.reset()
|
||||||
|
else:
|
||||||
|
sqsHit.submit_hit_at = datetime.datetime.utcnow() # fake submit
|
||||||
if updateStatus:
|
if updateStatus:
|
||||||
self.setLight(False)
|
self.setLight(False)
|
||||||
# {'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentReturned', 'EventTimestamp': '2019-10-23T20:16:47Z', 'HITId': '3IH9TRB0FBAKKZFP3JUD6D9YWQ1I1F', 'AssignmentId': '3BF51CHDTWLN3ZGHRKDUHFKPWIJ0H3', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}}
|
# {'event': {'HITGroupId': '301G7MYOAJ85NEW128ZDGF5DSBW53S', 'EventType': 'AssignmentReturned', 'EventTimestamp': '2019-10-23T20:16:47Z', 'HITId': '3IH9TRB0FBAKKZFP3JUD6D9YWQ1I1F', 'AssignmentId': '3BF51CHDTWLN3ZGHRKDUHFKPWIJ0H3', 'WorkerId': 'A1CK46PK9VEUH5', 'HITTypeId': '3EYXOXDEN7RX0YSMN4UMVN01AYKZJ0'}}
|
||||||
|
@ -308,8 +318,7 @@ class CentralManagement():
|
||||||
"""
|
"""
|
||||||
Run scanimage on scaner and returns a string with the filename
|
Run scanimage on scaner and returns a string with the filename
|
||||||
"""
|
"""
|
||||||
with self.scanLock:
|
|
||||||
self.eventQueue.put(Signal('scan.start'))
|
|
||||||
cmd = [
|
cmd = [
|
||||||
'sudo', 'scanimage', '-d', 'epkowa', '--format', 'jpeg',
|
'sudo', 'scanimage', '-d', 'epkowa', '--format', 'jpeg',
|
||||||
'--resolution=100', '-l','20','-t','30','-x',str(255),
|
'--resolution=100', '-l','20','-t','30','-x',str(255),
|
||||||
|
@ -317,6 +326,9 @@ class CentralManagement():
|
||||||
]
|
]
|
||||||
self.logger.info(f"{cmd}")
|
self.logger.info(f"{cmd}")
|
||||||
filename = self.currentHit.getImagePath()
|
filename = self.currentHit.getImagePath()
|
||||||
|
|
||||||
|
with self.scanLock:
|
||||||
|
self.eventQueue.put(Signal('scan.start'))
|
||||||
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
# opens connection to scanner, but only starts scanning when output becomes ready:
|
# opens connection to scanner, but only starts scanning when output becomes ready:
|
||||||
o, e = proc.communicate(80)
|
o, e = proc.communicate(80)
|
||||||
|
@ -324,10 +336,16 @@ class CentralManagement():
|
||||||
self.logger.critical(f"Scanner caused: {e.decode()}")
|
self.logger.critical(f"Scanner caused: {e.decode()}")
|
||||||
#TODO: should clear self.isRunning.clear() ?
|
#TODO: should clear self.isRunning.clear() ?
|
||||||
|
|
||||||
|
try:
|
||||||
f = io.BytesIO(o)
|
f = io.BytesIO(o)
|
||||||
img = Image.open(f)
|
img = Image.open(f)
|
||||||
img = img.transpose(Image.ROTATE_90)
|
img = img.transpose(Image.ROTATE_90)
|
||||||
img.save(filename)
|
img.save(filename)
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.critical("Cannot create image from scan. Did scanner work?")
|
||||||
|
self.logger.exception(e)
|
||||||
|
# TODO: create
|
||||||
|
copyfile('www/basic.svg', filename)
|
||||||
|
|
||||||
self.eventQueue.put(Signal('hit.scanned', {'hit_id':self.currentHit.id}))
|
self.eventQueue.put(Signal('hit.scanned', {'hit_id':self.currentHit.id}))
|
||||||
self.eventQueue.put(Signal('scan.finished'))
|
self.eventQueue.put(Signal('scan.finished'))
|
||||||
|
|
Loading…
Reference in a new issue