mirror of
https://github.com/google/blockly.git
synced 2025-12-13 12:50:07 +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
|
||||
def getFileInfo():
|
||||
from pathlib import Path
|
||||
if (len(sys.argv) < 2):
|
||||
print("Please provide a filename")
|
||||
sys.exit()
|
||||
fileName = sys.argv[1]
|
||||
try:
|
||||
jsonFile = open(fileName).read()
|
||||
fileName = str(Path(fileName).parent / f"new_{Path(fileName).stem}.json")
|
||||
fileName = Path(fileName)
|
||||
except IOError as err:
|
||||
print('Could not find that file name')
|
||||
sys.exit()
|
||||
@@ -174,7 +177,7 @@ def createColourMap():
|
||||
for key in jsonData.keys():
|
||||
rgbVal = findRgbVal(jsonData[key])
|
||||
colourObj[key] = findOtherColours(rgbVal)
|
||||
f= open("new_" + fileName,"w+")
|
||||
f= open(fileName,"w+")
|
||||
f.write(json.dumps(colourObj, indent=2, sort_keys=True))
|
||||
f.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user