Add file rename to ease OTA upload

Add file rename to ease OTA upload
This commit is contained in:
arendst 2018-01-10 12:14:37 +01:00
parent 1ce4e75dd8
commit 594f465f71
1 changed files with 7 additions and 1 deletions

View File

@ -18,13 +18,19 @@ import pycurl
HOST_URL = "domus1:80/api/upload-arduino.php" HOST_URL = "domus1:80/api/upload-arduino.php"
def upload(hostUrl, filename): def upload(hostUrl, filename):
tname = os.path.normpath(os.path.dirname(filename))
new_filename = tname + os.sep + os.path.basename(tname) + '.bin'
if os.path.exists(new_filename):
os.remove(new_filename)
os.rename(filename, new_filename)
url = 'http://%s' % (hostUrl) url = 'http://%s' % (hostUrl)
c = pycurl.Curl() c = pycurl.Curl()
c.setopt(c.URL, url) c.setopt(c.URL, url)
# The "Expect:" is there to suppress "Expect: 100-continue" behaviour that is # The "Expect:" is there to suppress "Expect: 100-continue" behaviour that is
# the default in libcurl when posting large bodies (and fails on lighttpd). # the default in libcurl when posting large bodies (and fails on lighttpd).
c.setopt(c.HTTPHEADER, ["Expect:"]) c.setopt(c.HTTPHEADER, ["Expect:"])
c.setopt(c.HTTPPOST, [('file', (c.FORM_FILE, filename, )), ]) c.setopt(c.HTTPPOST, [('file', (c.FORM_FILE, new_filename, )), ])
c.perform() c.perform()
c.close() c.close()