ESP32-PaxCounter/publish_firmware.py

71 lines
2.0 KiB
Python
Raw Normal View History

2018-09-15 14:47:13 +02:00
# Copyright (c) 2014-present PlatformIO <contact@platformio.org>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import requests
from os.path import basename
from platformio import util
2018-09-17 17:23:02 +02:00
Import("env")
2018-09-15 14:47:13 +02:00
project_config = util.load_project_config()
bintray_config = {k: v for k, v in project_config.items("bintray")}
2018-09-17 17:23:02 +02:00
version = project_config.get("ota", "release_version")
package = env.get("PIOENV")
2018-09-15 14:47:13 +02:00
#
# Push new firmware to the Bintray storage using API
#
2018-09-17 17:23:02 +02:00
def publish_bintray(source, target, env):
2018-09-15 14:47:13 +02:00
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
print("Uploading {0} to Bintray. Version: {1}".format(
firmware_name, version))
url = "/".join([
"https://api.bintray.com", "content",
bintray_config.get("user"),
bintray_config.get("repository"),
2018-09-17 17:23:02 +02:00
package, version, firmware_name
2018-09-15 14:47:13 +02:00
])
print(url)
headers = {
"Content-type": "application/octet-stream",
"X-Bintray-Publish": "1",
"X-Bintray-Override": "1"
}
r = requests.put(
url,
data=open(firmware_path, "rb"),
headers=headers,
auth=(bintray_config.get("user"), bintray_config['api_token']))
if r.status_code != 201:
print("Failed to submit package: {0}\n{1}".format(
r.status_code, r.text))
else:
print("The firmware has been successfuly published at Bintray.com!")
# Custom upload command and program name
2018-09-17 17:23:02 +02:00
2018-09-15 14:47:13 +02:00
env.Replace(
2018-09-17 17:23:02 +02:00
PROGNAME="firmware_" + package + "_v%s" % version,
UPLOADCMD=publish_bintray
2018-09-15 14:47:13 +02:00
)