1
1
2
2
import argparse , copy , hashlib , json , re , requests , os , shutil
3
3
4
- version = '0.1 .0'
4
+ version = '0.2 .0'
5
5
6
6
xmc_ino_root_path = os .path .relpath (os .path .join (os .path .join (os .getcwd (), os .pardir ), os .pardir ))
7
7
build_dir_name = 'pkg_build'
@@ -60,40 +60,54 @@ def get_package_sha256(pkg):
60
60
def get_latest_package_index_json ():
61
61
return requests .get ('https://github.com/Infineon/XMC-for-Arduino/releases/latest/download/package_infineon_index.json' ).json ()
62
62
63
+ def get_local_package_index_json ():
64
+ with open (os .path .join (xmc_ino_root_path , 'package/package_infineon_index.template.json' ), 'r' ) as f :
65
+ data = json .load (f )
66
+ return data
67
+
63
68
def get_platform_data_struct_copy (pkg_index ):
64
- return copy .deepcopy (pkg_index ['packages' ][0 ]['platforms' ][ 0 ] )
69
+ return copy .deepcopy (pkg_index ['packages' ][0 ]['platforms' ])
65
70
66
- def set_new_platform_data_fields (platform_data , pkg_name , version ):
71
+ def set_new_platform_data_fields (platform_data_index , pkg_name , version , repository ):
67
72
semver = strip_prefix_from_version (version )
73
+ platform_data = platform_data_index ['packages' ][0 ]['platforms' ][0 ]
68
74
platform_data ['version' ] = str (semver )
69
75
archive_file_name = str (pkg_name ) + ".zip"
70
76
platform_data ['archiveFileName' ] = archive_file_name
71
- platform_data ['url' ] = "https://github.com/Infineon/XMC-for-Arduino /releases/download/" + str (version ) + "/" + str (archive_file_name )
77
+ platform_data ['url' ] = "https://github.com/" + str ( repository ) + " /releases/download/" + str (version ) + "/" + str (archive_file_name )
72
78
platform_data ['checksum' ] = "SHA-256:" + str (get_package_sha256 (os .path .join (pkg_assets_build_path , archive_file_name )))
73
79
platform_data ['size' ] = str (get_package_size (os .path .join (pkg_assets_build_path , archive_file_name )))
74
80
75
- def add_new_platform_to_package_index (pkg_index , new_platform ):
76
- pkg_index ['packages' ][0 ]['platforms' ].insert ( 0 , new_platform )
81
+ def add_platform_to_package_index (pkg_index , platform ):
82
+ pkg_index ['packages' ][0 ]['platforms' ].extend ( platform )
77
83
78
84
def make_package_index_file (pkg_index ):
79
85
pkg_index_json_obj = json .dumps (pkg_index , indent = 2 )
80
86
pkg_index_w_path = os .path .join (pkg_assets_build_path , "package_infineon_index.json" )
81
87
with open (pkg_index_w_path , "w" ) as pkg_file :
82
88
pkg_file .write (pkg_index_json_obj )
83
89
84
- def build_package_index_json (pkg_name , version ):
85
- package_index = get_latest_package_index_json ()
86
- new_platform_data = get_platform_data_struct_copy (package_index )
87
- set_new_platform_data_fields (new_platform_data , pkg_name , version )
88
- add_new_platform_to_package_index (package_index , new_platform_data )
89
- make_package_index_file (package_index )
90
-
91
- def build_release_assets (version ):
90
+ def build_package_index_json (pkg_name , version , repository ):
91
+ # get online package index json
92
+ latest_package_index = get_latest_package_index_json ()
93
+ # get local package index template
94
+ local_package_index = get_local_package_index_json ()
95
+ # set data field in local template for newest package
96
+ set_new_platform_data_fields (local_package_index , pkg_name , version , repository )
97
+ # get old package array
98
+ old_platform_data = get_platform_data_struct_copy (latest_package_index )
99
+ # append to local package index
100
+ add_platform_to_package_index (local_package_index , old_platform_data )
101
+ make_package_index_file (local_package_index )
102
+
103
+ def build_release_assets (version , repository ):
104
+ if os .path .exists (pkg_assets_build_path ):
105
+ shutil .rmtree (pkg_assets_build_path )
92
106
os .mkdir (pkg_assets_build_path )
93
107
pkg_name = mkdir_package_dir (version )
94
108
build_package (pkg_name )
95
109
zip_package (pkg_name )
96
- build_package_index_json (pkg_name , version )
110
+ build_package_index_json (pkg_name , version , repository )
97
111
98
112
def parser ():
99
113
@@ -105,7 +119,7 @@ def parser_build_release_assets_func(args):
105
119
global pkg_build_path
106
120
xmc_ino_root_path = args .root_path
107
121
pkg_build_path = args .build_path
108
- build_release_assets (args .version )
122
+ build_release_assets (args .version , args . repository )
109
123
110
124
class ver_action (argparse .Action ):
111
125
def __init__ (self , option_strings , dest , ** kwargs ):
@@ -123,6 +137,7 @@ def __call__(self, parser, namespace, values, option_string, **kwargs):
123
137
124
138
# Release parser
125
139
parser_release = subparser .add_parser ('build-release' , description = 'Build package release assets' )
140
+ parser_release .add_argument ('repository' , type = str , help = 'Repository name' )
126
141
parser_release .add_argument ('version' , type = str , help = 'Package release version (format: Vx.y.z)' )
127
142
parser_release .add_argument ('-r' ,'--root-path' , type = str , default = xmc_ino_root_path , help = 'Path to the XMC-for-Arduino root path' )
128
143
parser_release .add_argument ('-b' ,'--build-path' , type = str , default = pkg_assets_build_path , help = 'Path to build package' )
0 commit comments