11
22import argparse , copy , hashlib , json , re , requests , os , shutil
33
4- version = '0.1 .0'
4+ version = '0.2 .0'
55
66xmc_ino_root_path = os .path .relpath (os .path .join (os .path .join (os .getcwd (), os .pardir ), os .pardir ))
77build_dir_name = 'pkg_build'
@@ -60,40 +60,54 @@ def get_package_sha256(pkg):
6060def get_latest_package_index_json ():
6161 return requests .get ('https://github.com/Infineon/XMC-for-Arduino/releases/latest/download/package_infineon_index.json' ).json ()
6262
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+
6368def 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' ])
6570
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 ):
6772 semver = strip_prefix_from_version (version )
73+ platform_data = platform_data_index ['packages' ][0 ]['platforms' ][0 ]
6874 platform_data ['version' ] = str (semver )
6975 archive_file_name = str (pkg_name ) + ".zip"
7076 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 )
7278 platform_data ['checksum' ] = "SHA-256:" + str (get_package_sha256 (os .path .join (pkg_assets_build_path , archive_file_name )))
7379 platform_data ['size' ] = str (get_package_size (os .path .join (pkg_assets_build_path , archive_file_name )))
7480
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 )
7783
7884def make_package_index_file (pkg_index ):
7985 pkg_index_json_obj = json .dumps (pkg_index , indent = 2 )
8086 pkg_index_w_path = os .path .join (pkg_assets_build_path , "package_infineon_index.json" )
8187 with open (pkg_index_w_path , "w" ) as pkg_file :
8288 pkg_file .write (pkg_index_json_obj )
8389
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 )
92106 os .mkdir (pkg_assets_build_path )
93107 pkg_name = mkdir_package_dir (version )
94108 build_package (pkg_name )
95109 zip_package (pkg_name )
96- build_package_index_json (pkg_name , version )
110+ build_package_index_json (pkg_name , version , repository )
97111
98112def parser ():
99113
@@ -105,7 +119,7 @@ def parser_build_release_assets_func(args):
105119 global pkg_build_path
106120 xmc_ino_root_path = args .root_path
107121 pkg_build_path = args .build_path
108- build_release_assets (args .version )
122+ build_release_assets (args .version , args . repository )
109123
110124 class ver_action (argparse .Action ):
111125 def __init__ (self , option_strings , dest , ** kwargs ):
@@ -123,6 +137,7 @@ def __call__(self, parser, namespace, values, option_string, **kwargs):
123137
124138 # Release parser
125139 parser_release = subparser .add_parser ('build-release' , description = 'Build package release assets' )
140+ parser_release .add_argument ('repository' , type = str , help = 'Repository name' )
126141 parser_release .add_argument ('version' , type = str , help = 'Package release version (format: Vx.y.z)' )
127142 parser_release .add_argument ('-r' ,'--root-path' , type = str , default = xmc_ino_root_path , help = 'Path to the XMC-for-Arduino root path' )
128143 parser_release .add_argument ('-b' ,'--build-path' , type = str , default = pkg_assets_build_path , help = 'Path to build package' )
0 commit comments