Fix sftp spaceapi upload, add logging for sftp upload

This commit is contained in:
Ondrej Mikle 2018-07-24 19:55:05 +02:00
parent 43e5ecaab8
commit 71566fac2a

View file

@ -386,7 +386,7 @@ class SpaceAPIUploader(object):
dirname, targetFname = os.path.split(self.config.sftpDestFile)
spaceApiJson = json.load(file("spaceapi_template.json"))
spaceApiJson["state"] = {"open": True, "lastchange": time.time()}
spaceApiJson["state"] = {"open": isOpen, "lastchange": time.time()}
with tempfile.NamedTemporaryFile() as tf:
json.dump(spaceApiJson, tf, indent=4, ensure_ascii=True, encoding='utf-8')
@ -435,8 +435,11 @@ class OpenSwitchThread(threading.Thread):
#this will upload status always upon brmdoor start, which is better than waiting until someone
#changes status with button
if self.config.useStatusUpload:
isOpen = (status == self.openValue)
uploader = SpaceAPIUploader(self.config)
uploader.upload(status == self.openValue)
logging.info("Going to upload spaceAPI status, opened: %s, status: %s", isOpen, status)
uploader.upload(isOpen)
logging.info("SpaceAPI json status upload finished")
except Exception:
#we could use retrying with @retry decorator, but it's likely that it wouldn't help with
#current connection/upload/out of disk space or similar problem