Extended platformio to create gzipped version of SPIFF contents.

This commit is contained in:
Dirk Jahnke 2019-01-30 16:12:46 +01:00
parent 2588d8beb5
commit 79bc78b511
4 changed files with 261 additions and 8 deletions

69
build_files.py Normal file
View File

@ -0,0 +1,69 @@
# Copyright (c) 2019-present Dirk Jahnke (dirk.jahnke@mailbox.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 os
import requests
from platformio import util
import shutil
import gzip
Import('env')
#print env
#print env.Dump()
project_config = util.load_project_config()
version = project_config.get("common", "app_version")
#
# Transfer and gzip files to proj/data directory
#
def transfer_file(source, target):
""" copy and compress the file """
try:
with gzip.open(target + '.gz', 'wb') as target_fid:
with open(source, 'rb') as source_fid:
target_fid.writelines(source_fid)
print('Compress {}'.format(source))
except FileNotFoundError:
os.makedirs(os.path.dirname(target))
transfer_file(source, target)
def build_files(source, target, env):
# copy & gzip files from src/data to data
#firmware_path = str(source[0])
#firmware_name = os.path.basename(firmware_path)
source_path = os.path.join(env['PROJECTSRC_DIR'], "data")
destination_path = env['PROJECTDATA_DIR']
print("========= Preparing file system (SPIFF) files from " + source_path)
print("=== Destination: " + destination_path)
print("Cleanup destination path " + destination_path)
shutil.rmtree(destination_path)
os.mkdir(destination_path)
for path, _, files in os.walk(source_path):
for file in files:
source = os.path.join(path, file)
target = os.path.join(destination_path, file)
print("Copy " + source + " to " + target)
transfer_file(source, target)
# Custom upload command and program name
#env.AddPreAction("$BUILD_DIR/spiffs.bin", build_files)
#env.AddPreAction("$BUILD_DIR/firmware.bin", build_files)
env.AddPreAction("buildprog", build_files)

View File

@ -8,19 +8,68 @@
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:d1_mini]
platform = espressif8266
board = d1_mini
framework = arduino
[platformio]
env_default = debug_wlan
[common]
app_version = 0.2.22
platform = espressif8266
lib_deps =
# Using a library name
MD_Parola
MD_MAX72XX
IOTAppStory-ESP
NTPClient
ESPAsyncTCP
ESP Async WebServer
IOTAppStory-ESP
build_flags =
'-DAPP_VERSION="{$common.app_version}"'
'-DFS_UPDATE_BASE_URL="{$iotjunkie.baseurl}/{$iotjunkie.repository}"'
'-DFS_UPDATE_AUTH_USER="{$iotjunkie.user}"'
'-DFS_UPDATE_AUTH_PASSWORD="{$iotjunkie.password}"'
[env:debug_usb]
platform = ${common.platform}
board = d1_mini
framework = arduino
build_flags =
${common.build_flags}
lib_deps =
${common.lib_deps}
MD_Parola
MD_MAX72XX
upload_port = /dev/cu.wchusbserial1420
upload_speed = 921600
monitor_speed = 115200
[env:debug_wlan]
platform = ${common.platform}
board = d1_mini
framework = arduino
build_flags =
${common.build_flags}
lib_deps =
${common.lib_deps}
MD_Parola
MD_MAX72XX
;upload_port = /dev/cu.wchusbserial1420
;upload_speed = 921600
monitor_speed = 115200
upload_protocol = custom
;upload_port = 192.168.89.72
extra_scripts =
build_files.py
;post:publish_firmware.py
[env:build]
;extra_scripts = pre:build_files.py
[env:uploadfs]
;extra_scripts = pre:publish_files.py
[iotjunkie]
user = fcclient
password = 63Gs59PWveT6uQSh
baseurl = http://ota.iotjunkie.org
repository = fcclient
;package = bintray-secure-ota
; api_token = ***
;api_token = ${sysenv.BINTRAY_API_TOKEN}

67
publish_files.py Normal file
View File

@ -0,0 +1,67 @@
# Copyright (c) 2019-present Dirk Jahnke (dirk.jahnke@mailbox.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
Import('env')
project_config = util.load_project_config()
iotjunkie_config = {k: v for k, v in project_config.items("iotjunkie")}
version = project_config.get("common", "app_version")
#
# Push new firmware to the iojunkie storage using API
#
def publish_files(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
print("Uploading {0} to IOTJunkie. Version: {1}".format(
firmware_name, version))
url = "/".join([
"https://api.iotjunkie.org", "content",
iotjunkie_config.get("user"),
iotjunkie_config.get("repository"),
version, firmware_name
])
headers = {
"Content-type": "application/octet-stream",
"X-IOTJunkie-Publish": "1",
"X-IOTJunkie-Override": "1"
}
r = requests.put(
url,
data=open(firmware_path, "rb"),
headers=headers,
auth=(iotjunkie_config.get("user"), iotjunkie_config['password']))
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
env.Replace(
PROGNAME="firmware_v_%s" % version,
UPLOADCMD=publish_files
)

68
publish_firmware.py Normal file
View File

@ -0,0 +1,68 @@
# Copyright (c) 2019-present Dirk Jahnke (dirk.jahnke@mailbox.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
Import('env')
project_config = util.load_project_config()
iotjunkie_config = {k: v for k, v in project_config.items("iotjunkie")}
version = project_config.get("common", "app_version")
#
# Push new firmware to the iojunkie storage using API
#
print("======== Publish firmware")
print("Script does not do anything for now")
def publish_firmware(source, target, env):
firmware_path = str(source[0])
firmware_name = basename(firmware_path)
print("Uploading {0} to IOTJunkie. Version: {1}".format(
firmware_name, version))
url = "/".join([
"https://api.iotjunkie.org", "content",
iotjunkie_config.get("user"),
iotjunkie_config.get("repository"),
version, firmware_name
])
headers = {
"Content-type": "application/octet-stream",
"X-IOTJunkie-Publish": "1",
"X-IOTJunkie-Override": "1"
}
r = requests.put(
url,
data=open(firmware_path, "rb"),
headers=headers,
auth=(iotjunkie_config.get("user"), iotjunkie_config['password']))
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
env.Replace(
PROGNAME="firmware_v_%s" % version,
UPLOADCMD=publish_firmware
)