-
Notifications
You must be signed in to change notification settings - Fork 498
/
Copy pathadd_icon_paths.py
executable file
·71 lines (51 loc) · 2.35 KB
/
add_icon_paths.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# Copyright 2024 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import sys
def add_image_to_config(image_name):
"""
Adds required image paths to the devtools_grd_files.gni and devtools_image_files.gni.
Args:
image_name: The name of the image file (e.g., "palette").
"""
grd_files_path = "config/gni/devtools_grd_files.gni"
image_files_path = "config/gni/devtools_image_files.gni"
grd_files_line = f' "front_end/Images/{image_name}.svg",'
image_files_line = f' "{image_name}.svg",'
# --- Update devtools-frontend/config/gni/devtools_grd_files.gni ---
with open(grd_files_path, "r") as f:
grd_files_lines = f.readlines()
start_index = grd_files_lines.index("grd_files_release_sources = [\n") + 1
end_index = grd_files_lines.index("]\n", start_index)
for i in range(start_index, end_index):
current_file_name = grd_files_lines[i].strip().strip('",')
if current_file_name.startswith("front_end/Images/"):
current_file_name = current_file_name[len("front_end/Images/"):]
if current_file_name > f"{image_name}.svg":
grd_files_lines.insert(i, grd_files_line + "\n")
break
else:
grd_files_lines.insert(end_index, grd_files_line + "\n")
with open(grd_files_path, "w") as f:
f.writelines(grd_files_lines)
# --- Update devtools-frontend/config/gni/devtools_image_files.gni ---
with open(image_files_path, "r") as f:
image_files_lines = f.readlines()
start_index = image_files_lines.index("devtools_svg_sources = [\n") + 1
end_index = image_files_lines.index("]\n", start_index)
for i in range(start_index, end_index):
if image_files_lines[i] > image_files_line:
image_files_lines.insert(i, image_files_line + "\n")
break
else:
image_files_lines.insert(end_index, image_files_line + "\n")
with open(image_files_path, "w") as f:
f.writelines(image_files_lines)
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python add_icon_paths.py <image_name>")
sys.exit(1)
image_name = sys.argv[1]
add_image_to_config(image_name)
print(f"Successfully added {image_name} to the configuration files.")