Skip to content

Commit

Permalink
separate deliveries in named directories
Browse files Browse the repository at this point in the history
  • Loading branch information
barn53 committed Oct 5, 2022
1 parent c329ea1 commit c83bcff
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 53 deletions.
12 changes: 6 additions & 6 deletions source/build/deliver.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def preAction():
tools.prepareHTMLFiles(env)
tools.removeBuildBinFiles(env)

tools.prepareSecretFiles(env, withWiFi, withPipedream, withSettings)
tools.createAssetsDirectory(withWiFi, withPipedream, withSettings)

tools.createAssetsDirectory()
tools.createUploadScript(env, withWiFi, withPipedream)
tools.copyHTMLFiles(env)
tools.prepareSecretFiles(env, withWiFi, withPipedream, withSettings)
tools.createUploadScript(env, withWiFi, withPipedream, withSettings)
tools.copyHTMLFiles(env, withWiFi, withPipedream, withSettings)


def postActionBuild(source, target, env):
Expand All @@ -39,7 +39,7 @@ def postActionBuild(source, target, env):
print("#### postActionBuild()")
print("###############################")

tools.copyFirmware(env)
tools.copyFirmware(env, withWiFi, withPipedream, withSettings)


def postActionSpiffs(source, target, env):
Expand All @@ -48,7 +48,7 @@ def postActionSpiffs(source, target, env):
print("#### postActionSpiffs()")
print("###############################")

tools.copySpiffs(env, withWiFi, withPipedream)
tools.copySpiffs(env, withWiFi, withPipedream, withSettings)


preAction()
Expand Down
12 changes: 6 additions & 6 deletions source/build/deliver_wifi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def preAction():
tools.prepareHTMLFiles(env)
tools.removeBuildBinFiles(env)

tools.prepareSecretFiles(env, withWiFi, withPipedream, withSettings)
tools.createAssetsDirectory(withWiFi, withPipedream, withSettings)

tools.createAssetsDirectory()
tools.createUploadScript(env, withWiFi, withPipedream)
tools.copyHTMLFiles(env)
tools.prepareSecretFiles(env, withWiFi, withPipedream, withSettings)
tools.createUploadScript(env, withWiFi, withPipedream, withSettings)
tools.copyHTMLFiles(env, withWiFi, withPipedream, withSettings)


def postActionBuild(source, target, env):
Expand All @@ -39,7 +39,7 @@ def postActionBuild(source, target, env):
print("#### postActionBuild()")
print("###############################")

tools.copyFirmware(env)
tools.copyFirmware(env, withWiFi, withPipedream, withSettings)


def postActionSpiffs(source, target, env):
Expand All @@ -48,7 +48,7 @@ def postActionSpiffs(source, target, env):
print("#### postActionSpiffs()")
print("###############################")

tools.copySpiffs(env, withWiFi, withPipedream)
tools.copySpiffs(env, withWiFi, withPipedream, withSettings)


preAction()
Expand Down
2 changes: 2 additions & 0 deletions source/build/develop.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def preAction():
tools.prepareHTMLFiles(env)
tools.removeBuildBinFiles(env)

tools.createAssetsDirectory(withWiFi, withPipedream, withSettings)

tools.prepareSecretFiles(env, withWiFi, withPipedream, withSettings)


Expand Down
86 changes: 45 additions & 41 deletions source/build/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,31 @@ def removeBuildBinFiles(env):
pass


def getAssetsDirectoryName():
def getAssetsDirectoryName(withWiFi, withPipedream, withSettings):
version = getVersion(True)
path = "assets/" + version + "/"

first = True
if withWiFi:
path += "wifi"
if first:
first = False
if withPipedream:
if first:
first = False
else:
path += "_"
path += "pipedream"
if withSettings:
if first:
first = False
else:
path += "_"
path += "settings"

if not first:
path += "/"

return path


Expand All @@ -69,53 +91,43 @@ def getFirmwareFilename():
return "cointhing_" + version + ".bin"


def getSpiffsFilename(withWiFi, withPipedream):
def getSpiffsFilename():
version = getVersion(True)
name = "spiffs_" + version
if withWiFi:
name += "_wifi"
if withPipedream:
name += "_pipedream"
name += ".bin"
return name
return "spiffs_" + version + ".bin"


def getUploadScriptFilename(withWiFi, withPipedream, sh):
def getUploadScriptFilename(sh):
version = getVersion(True)
name = "cointhing_upload_" + version
if withWiFi:
name += "_wifi"
if withPipedream:
name += "_pipedream"
if sh:
name += ".sh"
else:
name += ".bat"
return name


def createAssetsDirectory():
path = getAssetsDirectoryName()
def createAssetsDirectory(withWiFi, withPipedream, withSettings):
path = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)
try:
os.mkdir(path)
os.makedirs(path)
except:
pass
return path


def createUploadScript(env, withWiFi, withPipedream):
assets = getAssetsDirectoryName()
filename = assets + "/" + getUploadScriptFilename(withWiFi, withPipedream, False)
def createUploadScript(env, withWiFi, withPipedream, withSettings):
assets = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)
filename = assets + "/" + getUploadScriptFilename(False)
firmware = getFirmwareFilename()
spiffs = getSpiffsFilename(withWiFi, withPipedream)
spiffs = getSpiffsFilename()

f = open(filename, "w")
f.write("python -m esptool erase_flash\n")
f.write("python -m esptool --before default_reset --after hard_reset --chip esp8266 --baud 921600 write_flash 0x0 .\{0} 0x200000 .\{1} \n\n".format(firmware, spiffs))
f.write("pio device monitor -b 115200\n")
f.close()

filename = assets + "/" + getUploadScriptFilename(withWiFi, withPipedream, True)
filename = assets + "/" + getUploadScriptFilename(True)

f = open(filename, "w")
f.write("export PATH={0}\n".format(env["ENV"]["Path"]))
Expand All @@ -126,31 +138,20 @@ def createUploadScript(env, withWiFi, withPipedream):
os.chmod(filename, 0o777)


def moveFirmware(env):
assets = getAssetsDirectoryName()

shutil.move(env["PROJECT_BUILD_DIR"] + "/" + env["PIOENV"] + "/firmware.bin", assets + "/" + getFirmwareFilename())


def copyFirmware(env):
assets = getAssetsDirectoryName()
def copyFirmware(env, withWiFi, withPipedream, withSettings):
assets = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)

shutil.copyfile(env["PROJECT_BUILD_DIR"] + "/" + env["PIOENV"] + "/firmware.bin", assets + "/" + getFirmwareFilename())


def moveSpiffs(env, withWiFi, withPipedream):
assets = getAssetsDirectoryName()
def copySpiffs(env, withWiFi, withPipedream, withSettings):
assets = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)

shutil.move(env["PROJECT_BUILD_DIR"] + "/" + env["PIOENV"] + "/spiffs.bin", assets + "/" + getSpiffsFilename(withWiFi, withPipedream))


def copySpiffs(env, withWiFi, withPipedream):
assets = getAssetsDirectoryName()

shutil.copyfile(env["PROJECT_BUILD_DIR"] + "/" + env["PIOENV"] + "/spiffs.bin", assets + "/" + getSpiffsFilename(withWiFi, withPipedream))
shutil.copyfile(env["PROJECT_BUILD_DIR"] + "/" + env["PIOENV"] + "/spiffs.bin", assets + "/" + getSpiffsFilename())


def prepareSecretFiles(env, withWiFi, withPipedream, withSettings):
assets = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)
try:
os.remove(env["PROJECT_DATA_DIR"] + "/secrets.json")
except OSError:
Expand All @@ -173,10 +174,13 @@ def prepareSecretFiles(env, withWiFi, withPipedream, withSettings):
with open(env["PROJECT_DATA_DIR"] + "/secrets.json", "w") as f:
json.dump(secrets, f, indent=2, separators=(',', ':'))

shutil.copyfile(env["PROJECT_DATA_DIR"] + "/secrets.json", assets + "/secrets.json")

# settings.json only if avaiable
if withSettings:
try:
shutil.copyfile("secrets/settings.json", env["PROJECT_DATA_DIR"] + "/settings.json")
shutil.copyfile("secrets/settings.json", assets + "/settings.json")
except OSError:
pass

Expand All @@ -201,8 +205,8 @@ def prepareHTMLFiles(env):
os.replace(env["PROJECT_DATA_DIR"] + "/../html/style.css.gz", env["PROJECT_DATA_DIR"] + "/style.css.gz")


def copyHTMLFiles(env):
assets = getAssetsDirectoryName()
def copyHTMLFiles(env, withWiFi, withPipedream, withSettings):
assets = getAssetsDirectoryName(withWiFi, withPipedream, withSettings)

shutil.copyfile(env["PROJECT_DATA_DIR"] + "/settings.html.gz", assets + "/settings.html.gz")
shutil.copyfile(env["PROJECT_DATA_DIR"] + "/about.html.gz", assets + "/about.html.gz")
Expand Down

0 comments on commit c83bcff

Please sign in to comment.