59 lines
No EOL
1.9 KiB
Python
59 lines
No EOL
1.9 KiB
Python
import json
|
|
import collections
|
|
import sys
|
|
|
|
def updateFwVer (jsonFileName, buildStamp):
|
|
|
|
print("* JSON file to update: {0}\n* with Stamp: {1}".format(jsonFileName,buildStamp))
|
|
# extract the 4 version numbers from the buildStamp
|
|
|
|
buildStampList = buildStamp.split(".")
|
|
if (len(buildStampList) != 4) :
|
|
buildStampList=['1','30000','0','0'] #default implies local build
|
|
print("Unable to parse buildStamp correctly - use default values")
|
|
|
|
print("Build Stamp Values {0}".format(buildStampList))
|
|
|
|
try :
|
|
jsonFile = open(jsonFileName)
|
|
jsonStr = jsonFile.read()
|
|
jsonFile.close()
|
|
except :
|
|
print('Error accessing ' + jsonFileName + '\n')
|
|
return 1
|
|
|
|
# Load in the JSON data, and use ordered dictionaries from collections package
|
|
# in place of built-in dictionaries, to ensure registers and fields are not
|
|
# presented in random order when iterating through entries
|
|
try :
|
|
jsonData = json.loads(jsonStr, object_pairs_hook=collections.OrderedDict)
|
|
except ValueError as err:
|
|
sys.stdout.write('Error in JSON file while parsing ' + blockName + ': ')
|
|
print(err)
|
|
return 1
|
|
|
|
jsonDict = jsonData[0]
|
|
|
|
jsonData[0]['registers']['FW_VER_ZERO']['reset'] = buildStampList[0]
|
|
jsonData[0]['registers']['FW_VER_ONE']['reset'] = buildStampList[1]
|
|
jsonData[0]['registers']['FW_VER_TWO']['reset'] = buildStampList[2]
|
|
jsonData[0]['registers']['FW_VER_THREE']['reset'] = buildStampList[3]
|
|
|
|
jsonFile = open(jsonFileName, 'w')
|
|
json.dump(jsonData, jsonFile, indent=4)
|
|
jsonFile.close()
|
|
return 0
|
|
|
|
# ###############################################################
|
|
# Only run if not imported (to test)
|
|
#
|
|
if __name__ == '__main__':
|
|
print(len(sys.argv))
|
|
if len(sys.argv) != 3 :
|
|
print('***Error: expecting a JSON filename followed by a buildStamp value')
|
|
sys.exit(1)
|
|
|
|
jsonFileName = sys.argv[1]
|
|
buildStamp = sys.argv[2]
|
|
rtnStatus = updateFwVer (jsonFileName, buildStamp)
|
|
sys.exit(rtnStatus) |