35
35
'\s*\(cherry picked from commit (([0-9]|[a-f]|[A-F])+)\)' )
36
36
37
37
38
+ class StoreDir (argparse .Action ):
39
+ def __call__ (self , parser , namespace , values , option_string = None ):
40
+ directory = os .path .abspath (values )
41
+ if not os .path .isdir (directory ):
42
+ raise argparse .ArgumentError (
43
+ None , "The directory %s does not exist!" % directory )
44
+ setattr (namespace , self .dest , directory )
45
+
46
+
47
+ class StoreValidFile (argparse .Action ):
48
+ def __call__ (self , parser , namespace , values , option_string = None ):
49
+ fn = os .path .abspath (values )
50
+ if not os .path .isfile (fn ):
51
+ raise argparse .ArgumentError (
52
+ None , "The file %s does not exist!" % fn )
53
+ setattr (namespace , self .dest , fn )
54
+
55
+
38
56
def del_file (name ):
39
57
""" Delete the file in RTOS/CMSIS/features directory of mbed-os
40
58
Args:
@@ -170,19 +188,22 @@ def normalize_commit_sha(sha_lst):
170
188
171
189
if __name__ == "__main__" :
172
190
173
- parser = argparse .ArgumentParser (description = __doc__ ,
174
- formatter_class = argparse .RawDescriptionHelpFormatter )
191
+ parser = argparse .ArgumentParser (
192
+ description = __doc__ ,
193
+ formatter_class = argparse .RawDescriptionHelpFormatter )
194
+
175
195
parser .add_argument ('-l' , '--log-level' ,
176
196
help = "Level for providing logging output" ,
177
197
default = 'INFO' )
178
198
parser .add_argument ('-r' , '--repo-path' ,
179
199
help = "Git Repository to be imported" ,
180
- default = None ,
181
- required = True )
200
+ required = True ,
201
+ action = StoreDir )
182
202
parser .add_argument ('-c' , '--config-file' ,
183
203
help = "Configuration file" ,
184
- default = None ,
185
- required = True )
204
+ required = True ,
205
+ action = StoreValidFile )
206
+
186
207
args = parser .parse_args ()
187
208
level = getattr (logging , args .log_level .upper ())
188
209
@@ -194,33 +215,13 @@ def normalize_commit_sha(sha_lst):
194
215
logging .basicConfig (level = level )
195
216
rel_log = logging .getLogger ("Importer" )
196
217
197
- if (args .repo_path is None ) or (args .config_file is None ):
198
- rel_log .error (
199
- "Repository path and config file required as input. "
200
- "Use \" --help\" for more info." )
201
- sys .exit (1 )
202
-
203
- json_file = abspath (args .config_file )
204
- if not os .path .isfile (json_file ):
205
- rel_log .error ("%s not found." , args .config_file )
206
- sys .exit (1 )
207
-
208
- repo = abspath (args .repo_path )
209
- if not os .path .exists (repo ):
210
- rel_log .error ("%s not found." , args .repo_path )
211
- sys .exit (1 )
212
-
213
- sha = get_curr_sha (repo )
214
- if not sha :
215
- rel_log .error ("Could not obtain latest SHA" )
216
- sys .exit (1 )
217
- rel_log .info ("%s SHA = %s" , os .path .basename (repo ), sha )
218
-
219
- branch = 'feature_' + os .path .basename (repo ) + '_' + sha
220
- commit_msg = "[" + os .path .basename (repo ) + "]" + ": Updated to " + sha
218
+ sha = get_curr_sha (args .repo_path )
219
+ repo_dir = os .path .basename (args .repo_path )
220
+ branch = 'feature_' + repo_dir + '_' + sha
221
+ commit_msg = "[" + repo_dir + "]" + ": Updated to " + sha
221
222
222
223
# Read configuration data
223
- with open (json_file , 'r' ) as config :
224
+ with open (args . config_file , 'r' ) as config :
224
225
json_data = json .load (config )
225
226
226
227
'''
@@ -252,15 +253,15 @@ def normalize_commit_sha(sha_lst):
252
253
253
254
# Copy all the files listed in json file to mbed-os
254
255
for fh in data_files :
255
- repo_file = join (repo , fh ['src_file' ])
256
+ repo_file = join (args . repo_path , fh ['src_file' ])
256
257
mbed_path = join (ROOT , fh ['dest_file' ])
257
258
mkdir (dirname (mbed_path ))
258
259
copy_file (repo_file , mbed_path )
259
260
rel_log .debug ("Copied %s to %s" , normpath (repo_file ),
260
261
normpath (mbed_path ))
261
262
262
263
for folder in data_folders :
263
- repo_folder = join (repo , folder ['src_folder' ])
264
+ repo_folder = join (args . repo_path , folder ['src_folder' ])
264
265
mbed_path = join (ROOT , folder ['dest_folder' ])
265
266
copy_folder (repo_folder , mbed_path )
266
267
rel_log .debug ("Copied %s to %s" , normpath (repo_folder ),
0 commit comments