Skip to content

Commit 91d5b00

Browse files
authored
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
1 parent b5f2d57 commit 91d5b00

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

scripts/themes/create_blockStyles.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,15 @@ def findRgbVal(colour):
154154

155155
# Get info on the input file
156156
def getFileInfo():
157+
from pathlib import Path
157158
if (len(sys.argv) < 2):
158159
print("Please provide a filename")
159160
sys.exit()
160161
fileName = sys.argv[1]
161162
try:
162163
jsonFile = open(fileName).read()
164+
fileName = str(Path(fileName).parent / f"new_{Path(fileName).stem}.json")
165+
fileName = Path(fileName)
163166
except IOError as err:
164167
print('Could not find that file name')
165168
sys.exit()
@@ -174,7 +177,7 @@ def createColourMap():
174177
for key in jsonData.keys():
175178
rgbVal = findRgbVal(jsonData[key])
176179
colourObj[key] = findOtherColours(rgbVal)
177-
f= open("new_" + fileName,"w+")
180+
f= open(fileName,"w+")
178181
f.write(json.dumps(colourObj, indent=2, sort_keys=True))
179182
f.close()
180183

0 commit comments

Comments
 (0)