Better upload error handling

This commit is contained in:
Sebastian 2018-10-20 20:35:48 +02:00
parent 22646244ed
commit d16c1b5e91
2 changed files with 13 additions and 7 deletions

View File

@ -8,7 +8,7 @@ BAUD_RATE = 4800
SFTP_HOST = 'rc-club-albersweiler.de'
SFTP_PORT = 22
SFTP_USER = 'sftprcclub'
SFTP_KEY = '/home/sebastian/.ssh/id_rsa'
SFTP_KEY = '/home/pi/.ssh/id_rsa'
DATA_FILE = './test.rrd'

View File

@ -103,8 +103,14 @@ def update_graphs():
print("Failed to render archive data")
def upload_graphs():
def _do_upload(sftp, src, dest):
try:
sftp.put(src, dest)
except:
print("Unexpected error while uploading:", sys.exc_info()[1])
def upload_graphs():
key = paramiko.RSAKey.from_private_key_file(SFTP_KEY)
transport = paramiko.Transport((SFTP_HOST, SFTP_PORT))
transport.connect()
@ -112,14 +118,14 @@ def upload_graphs():
sftp = paramiko.SFTPClient.from_transport(transport)
for name, _ in GRAPHS.items():
sftp.put('%s.png' % name, 'solar/%s.png' % name)
sftp.put('%s_archive.png' % name, 'solar/%s_archive.png' % name)
sftp.put('index.html', 'solar/index.html')
_do_upload(sftp, '%s.png' % name, 'solar/%s.png' % name)
_do_upload(sftp, '%s_archive.png' % name, 'solar/%s_archive.png' % name)
_do_upload(sftp, 'index.html', 'solar/index.html')
sftp.close()
transport.close()
except:
print("Unexpected error while uploading:", sys.exc_info()[1])
def main():
ser = serial.Serial(SERIAL, BAUD_RATE, timeout=10.0)