11
22import argparse , copy , hashlib , json , re , requests , os , shutil
33
4- version = '0.2 .0'
4+ version = '0.1 .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,54 +60,40 @@ 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-
6863def get_platform_data_struct_copy (pkg_index ):
69- return copy .deepcopy (pkg_index ['packages' ][0 ]['platforms' ])
64+ return copy .deepcopy (pkg_index ['packages' ][0 ]['platforms' ][ 0 ] )
7065
71- def set_new_platform_data_fields (platform_data_index , pkg_name , version , repository ):
66+ def set_new_platform_data_fields (platform_data , pkg_name , version ):
7267 semver = strip_prefix_from_version (version )
73- platform_data = platform_data_index ['packages' ][0 ]['platforms' ][0 ]
7468 platform_data ['version' ] = str (semver )
7569 archive_file_name = str (pkg_name ) + ".zip"
7670 platform_data ['archiveFileName' ] = archive_file_name
77- platform_data ['url' ] = "https://github.com/" + str ( repository ) + " /releases/download/" + str (version ) + "/" + str (archive_file_name )
71+ platform_data ['url' ] = "https://github.com/Infineon/XMC-for-Arduino /releases/download/" + str (version ) + "/" + str (archive_file_name )
7872 platform_data ['checksum' ] = "SHA-256:" + str (get_package_sha256 (os .path .join (pkg_assets_build_path , archive_file_name )))
7973 platform_data ['size' ] = str (get_package_size (os .path .join (pkg_assets_build_path , archive_file_name )))
8074
81- def add_platform_to_package_index (pkg_index , platform ):
82- pkg_index ['packages' ][0 ]['platforms' ].insert (1 , platform )
75+ def add_new_platform_to_package_index (pkg_index , new_platform ):
76+ pkg_index ['packages' ][0 ]['platforms' ].insert (0 , new_platform )
8377
8478def make_package_index_file (pkg_index ):
8579 pkg_index_json_obj = json .dumps (pkg_index , indent = 2 )
8680 pkg_index_w_path = os .path .join (pkg_assets_build_path , "package_infineon_index.json" )
8781 with open (pkg_index_w_path , "w" ) as pkg_file :
8882 pkg_file .write (pkg_index_json_obj )
8983
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- os .system ("rm -rf " + pkg_assets_build_path )
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 ):
10692 os .mkdir (pkg_assets_build_path )
10793 pkg_name = mkdir_package_dir (version )
10894 build_package (pkg_name )
10995 zip_package (pkg_name )
110- build_package_index_json (pkg_name , version , repository )
96+ build_package_index_json (pkg_name , version )
11197
11298def parser ():
11399
@@ -119,7 +105,7 @@ def parser_build_release_assets_func(args):
119105 global pkg_build_path
120106 xmc_ino_root_path = args .root_path
121107 pkg_build_path = args .build_path
122- build_release_assets (args .version , args . repository )
108+ build_release_assets (args .version )
123109
124110 class ver_action (argparse .Action ):
125111 def __init__ (self , option_strings , dest , ** kwargs ):
@@ -137,7 +123,6 @@ def __call__(self, parser, namespace, values, option_string, **kwargs):
137123
138124 # Release parser
139125 parser_release = subparser .add_parser ('build-release' , description = 'Build package release assets' )
140- parser_release .add_argument ('repository' , type = str , help = 'Repository name' )
141126 parser_release .add_argument ('version' , type = str , help = 'Package release version (format: Vx.y.z)' )
142127 parser_release .add_argument ('-r' ,'--root-path' , type = str , default = xmc_ino_root_path , help = 'Path to the XMC-for-Arduino root path' )
143128 parser_release .add_argument ('-b' ,'--build-path' , type = str , default = pkg_assets_build_path , help = 'Path to build package' )
0 commit comments