@@ -18,104 +18,124 @@ def __init__(self, chain_id: int, name: str, ticker: str):
18
18
self .ticker = ticker
19
19
20
20
21
- def get_network_glyph_name (net : Network ) -> str :
22
- return "stax_chain_%u_64px" % (net .chain_id )
21
+ def get_network_glyph_name (net : Network , small : bool ) -> str :
22
+ if small :
23
+ return f"stax_app_chain_{ net .chain_id } "
24
+ return f"stax_chain_{ net .chain_id } _64px"
23
25
24
26
25
27
def get_header () -> str :
26
- return """\
28
+ return f """\
27
29
/*
28
- * Generated by %s
30
+ * Generated by { sys . argv [ 0 ] }
29
31
*/
30
32
31
- """ % ( sys . argv [ 0 ])
33
+ """
32
34
33
35
34
- def gen_icons_array_inc (networks : list [ Network ], path : str ) -> bool :
35
- with open (path + ".h" , "w" ) as out :
36
- print (get_header () + """\
36
+ def gen_icons_array_inc (networks : int , small_networks : int , path : str ) -> None :
37
+ with open (path + ".h" , "w" , encoding = "utf-8" ) as out :
38
+ print (get_header () + f """\
37
39
#ifndef NETWORK_ICONS_GENERATED_H_
38
40
#define NETWORK_ICONS_GENERATED_H_
39
41
40
42
#include <stdint.h>
41
43
#include "nbgl_types.h"
42
44
43
- typedef struct {
45
+ typedef struct {{
44
46
uint64_t chain_id;
45
47
const nbgl_icon_details_t *icon;
46
- } network_icon_t;
48
+ }} network_icon_t;
47
49
48
- extern const network_icon_t g_network_icons[%u];
50
+ extern const network_icon_t g_network_icons[{ networks } ];
51
+ extern const network_icon_t g_network_small_icons[{ small_networks } ];
49
52
50
53
#endif // NETWORK_ICONS_GENERATED_H_ \
51
- """ % (len (networks )), file = out )
52
- return True
54
+ """ , file = out )
53
55
54
56
55
- def gen_icons_array_src (networks : list [Network ], path : str ) -> bool :
56
- with open (path + ".c" , "w" ) as out :
57
- print (get_header () + """\
57
+ def gen_network_array_src (networks : list [Network ], small : bool , out ) -> None :
58
+
59
+ if small :
60
+ print (f"const network_icon_t g_network_small_icons[{ len (networks )} ] = {{" , file = out )
61
+ else :
62
+ print (f"const network_icon_t g_network_icons[{ len (networks )} ] = {{" , file = out )
63
+
64
+ for net in networks :
65
+ glyph_name = get_network_glyph_name (net , small )
66
+ glyph_file = f"glyphs/{ glyph_name } .gif"
67
+ if os .path .isfile (glyph_file ):
68
+ if os .path .islink (glyph_file ):
69
+ glyph_name = Path (os .path .realpath (glyph_file )).stem
70
+ print (f" {{.chain_id = { net .chain_id } , .icon = &C_{ glyph_name } }}, // { net .name } " ,
71
+ file = out )
72
+
73
+ print ("};" , file = out )
74
+
75
+
76
+ def gen_icons_array_src (networks : list [Network ], small_networks : list [Network ], path : str ) -> None :
77
+ with open (path + ".c" , "w" , encoding = "utf-8" ) as out :
78
+ print (get_header () + f"""\
58
79
#include "glyphs.h"
59
- #include "%s.h"
80
+ #include "{ os .path .basename (path )} .h"
81
+ """ , file = out )
82
+ # const network_icon_t g_network_icons[{len(networks)}] = {{""", file=out)
60
83
61
- const network_icon_t g_network_icons[%u] = { \
62
- """ % ( os . path . basename ( path ), len ( networks )), file = out )
84
+ gen_network_array_src ( networks , False , out )
85
+ gen_network_array_src ( small_networks , True , out )
63
86
64
- for net in networks :
65
- glyph_name = get_network_glyph_name (net )
66
- glyph_file = "glyphs/%s.gif" % (glyph_name )
67
- if os .path .isfile (glyph_file ):
68
- if os .path .islink (glyph_file ):
69
- glyph_name = Path (os .path .realpath (glyph_file )).stem
70
- print (" " * 4 , end = "" , file = out )
71
- print ("{.chain_id = %u, .icon = &C_%s}, // %s" % (net .chain_id ,
72
- glyph_name ,
73
- net .name ),
74
- file = out )
87
+ # for net in networks:
88
+ # glyph_name = get_network_glyph_name(net, False)
89
+ # glyph_file = f"glyphs/{glyph_name}.gif"
90
+ # if os.path.isfile(glyph_file):
91
+ # if os.path.islink(glyph_file):
92
+ # glyph_name = Path(os.path.realpath(glyph_file)).stem
93
+ # print(f" {{.chain_id = {net.chain_id}, .icon = &C_{glyph_name}}}, // {net.name}",
94
+ # file=out)
75
95
76
- print ("};" , file = out )
77
- return True
96
+ # print("};", file=out)
78
97
79
98
80
- def gen_icons_array (networks : list [Network ], path : str ) -> bool :
99
+ def gen_icons_array (networks : list [Network ], small_networks : list [ Network ], path : str ) -> None :
81
100
path += "/net_icons.gen"
82
- if not gen_icons_array_inc (networks , path ) or \
83
- not gen_icons_array_src (networks , path ):
84
- return False
85
- return True
101
+ gen_icons_array_inc (len (networks ), len (small_networks ), path )
102
+ gen_icons_array_src (networks , small_networks , path )
86
103
87
104
88
105
def network_icon_exists (net : Network ) -> bool :
89
- return os .path .isfile ("glyphs/%s.gif" % (get_network_glyph_name (net )))
106
+ return os .path .isfile (f"glyphs/{ get_network_glyph_name (net , False )} .gif" )
107
+
108
+
109
+ def network_small_icon_exists (net : Network ) -> bool :
110
+ return os .path .isfile (f"glyphs/{ get_network_glyph_name (net , True )} .gif" )
90
111
91
112
92
113
def main (output_dir : str ) -> bool :
93
- networks : list [Network ] = list ()
114
+ networks : list [Network ] = []
94
115
95
116
# get chain IDs and network names
96
117
expr = r"{\.chain_id = ([0-9]*), \.name = \"(.*)\", \.ticker = \"(.*)\"},"
97
- with open ("src/network.c" ) as f :
118
+ with open ("src/network.c" , encoding = "utf-8" ) as f :
98
119
for line in f .readlines ():
99
120
line = line .strip ()
100
121
if line .startswith ("{" ) and line .endswith ("}," ):
101
122
m = re .search (expr ,
102
123
line )
103
- assert ( m .lastindex == 3 )
124
+ assert m .lastindex == 3
104
125
networks .append (Network (int (m .group (1 )),
105
126
m .group (2 ),
106
127
m .group (3 )))
107
128
108
129
networks .sort (key = lambda x : x .chain_id )
109
130
110
- if not gen_icons_array (list (filter (network_icon_exists , networks )),
111
- output_dir ):
112
- return False
113
- return True
131
+ gen_icons_array (list (filter (network_icon_exists , networks )),
132
+ list (filter (network_small_icon_exists , networks )),
133
+ output_dir )
114
134
115
135
116
136
if __name__ == "__main__" :
117
137
parser = argparse .ArgumentParser ()
118
138
parser .add_argument ("OUTPUT_DIR" )
119
139
args = parser .parse_args ()
120
140
assert os .path .isdir (args .OUTPUT_DIR )
121
- quit ( 0 if main (args .OUTPUT_DIR ) else 1 )
141
+ main (args .OUTPUT_DIR )
0 commit comments