Spiffs file system shortcut/auto upload

Here is a nice script to run pre-build. It builds and uploads the data image only when a file has been changed, added, or deleted.

import os

projDirPath  = '<your project path>'
dataDirPath  = projDirPath + '\\data'
timeFilePath = projDirPath + '\\spiffs-timesum.txt'

if(not os.path.exists(timeFilePath)):
  timeFile = open(timeFilePath, "w")
  timeFile.write("0.0")
  timeFile.close()

timeFile = open(timeFilePath, "r")
oldTime = float(timeFile.read())
timeFile.close()
# print(oldTime)

newTime = float((sum(os.path.getmtime(os.path.join(dataDirPath, file_name)) for file_name in os.listdir(dataDirPath))))
# print(newTime)

if newTime != oldTime:
  print("\nfile updated in data directory -- building/uploading spiffs image\n")
  os.system('pio run -t uploadfs')

timeFile = open(timeFilePath, "w")
timeFile.write(str(newTime))
timeFile.close()

EDIT: Oops, this uploads the data folder and starts a firmware upload, which then runs this script again in an infinite loop. I’ll have to fix this and edit this script to only upload the data folder. Hold tight …

1 Like