mirror of
https://github.com/google/blockly.git
synced 2025-12-16 06:10:12 +01:00
fix: improve file path handling in theme generator script (#9426)
- Use Path objects from pathlib to handle file paths properly - Generate output files in the same directory as input file - Create output filenames with "new_" prefix while preserving original stem name - Ensure script works with files from any location in the filesystem
This commit is contained in:
committed by
GitHub
parent
b5f2d576fa
commit
91d5b00c55
@@ -154,12 +154,15 @@ def findRgbVal(colour):
|
|||||||
|
|
||||||
# Get info on the input file
|
# Get info on the input file
|
||||||
def getFileInfo():
|
def getFileInfo():
|
||||||
|
from pathlib import Path
|
||||||
if (len(sys.argv) < 2):
|
if (len(sys.argv) < 2):
|
||||||
print("Please provide a filename")
|
print("Please provide a filename")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
fileName = sys.argv[1]
|
fileName = sys.argv[1]
|
||||||
try:
|
try:
|
||||||
jsonFile = open(fileName).read()
|
jsonFile = open(fileName).read()
|
||||||
|
fileName = str(Path(fileName).parent / f"new_{Path(fileName).stem}.json")
|
||||||
|
fileName = Path(fileName)
|
||||||
except IOError as err:
|
except IOError as err:
|
||||||
print('Could not find that file name')
|
print('Could not find that file name')
|
||||||
sys.exit()
|
sys.exit()
|
||||||
@@ -174,7 +177,7 @@ def createColourMap():
|
|||||||
for key in jsonData.keys():
|
for key in jsonData.keys():
|
||||||
rgbVal = findRgbVal(jsonData[key])
|
rgbVal = findRgbVal(jsonData[key])
|
||||||
colourObj[key] = findOtherColours(rgbVal)
|
colourObj[key] = findOtherColours(rgbVal)
|
||||||
f= open("new_" + fileName,"w+")
|
f= open(fileName,"w+")
|
||||||
f.write(json.dumps(colourObj, indent=2, sort_keys=True))
|
f.write(json.dumps(colourObj, indent=2, sort_keys=True))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user