more logging - only upload when not already done

This commit is contained in:
Tobias Brunner 2017-12-23 17:16:14 +01:00
parent 68c7c39314
commit 0b065e885a
2 changed files with 13 additions and 4 deletions

View File

@ -17,4 +17,5 @@
* Move processes mail to subfolder
* IMAP idle
* Lodur Connect (Create Einsatzrapport)
* MQTT Publish
* MQTT Publish
* Error Handling

14
main.py
View File

@ -107,12 +107,20 @@ def upload_attachment(file, file_name, f_id):
# upload with webdav
upload_dir = webdav_basedir + "/" + str(datetime.now().year) + "/" + f_id
logger.info('Uploading attachment to ' + upload_dir)
# create directory if not yet there
if not loop.run_until_complete(webdav.exists(upload_dir)):
logger.info('Creating directory ' + upload_dir)
loop.run_until_complete(webdav.mkdir(upload_dir))
loop.run_until_complete(
webdav.upload(file, upload_dir + "/" + file_name)
)
remote_file_path = upload_dir + "/" + file_name
if loop.run_until_complete(webdav.exists(remote_file_path)):
logger.info('File ' + file_name + ' already uploaded')
else:
loop.run_until_complete(
webdav.upload(file, remote_file_path)
)
logger.info('File ' + file_name + ' uploaded')
def main():
""" main """