21
21
"""
22
22
import sys
23
23
from copy import copy
24
- from os import walk , remove , makedirs
25
- from os .path import join , abspath , dirname , relpath , exists , isfile
24
+ from os import walk , remove , makedirs , getcwd , rmdir , listdir
25
+ from os .path import join , abspath , dirname , relpath , exists , isfile , normpath , isdir
26
26
from shutil import copyfile
27
27
from optparse import OptionParser
28
28
import re
46
46
# Code that does have a mirror in the mbed SDK
47
47
# Tuple data: (repo_name, list_of_code_dirs, [team])
48
48
# team is optional - if not specified, the code is published under mbed_official
49
- OFFICIAL_CODE = (
50
- ("mbed-dev" , [MBED_DRIVERS , MBED_PLATFORM , MBED_HAL ]),
51
- ("mbed-rtos" , RTOS ),
52
- ("mbed-dsp" , DSP ),
53
- ("mbed-rpc" , MBED_RPC ),
54
-
55
- ("lwip" , LWIP_SOURCES + "/lwip" ),
56
- ("lwip-sys" , LWIP_SOURCES + "/lwip-sys" ),
57
- ("Socket" , LWIP_SOURCES + "/Socket" ),
58
-
59
- ("lwip-eth" , ETH_SOURCES + "/lwip-eth" ),
60
- ("EthernetInterface" , ETH_SOURCES + "/EthernetInterface" ),
61
-
62
- ("USBDevice" , USB ),
63
- ("USBHost" , USB_HOST ),
64
-
65
- ("CellularModem" , CELLULAR_SOURCES ),
66
- ("CellularUSBModem" , CELLULAR_USB_SOURCES ),
67
- ("UbloxUSBModem" , UBLOX_SOURCES ),
68
- ("UbloxModemHTTPClientTest" , [TEST_DIR + "/net/cellular/http/common" , TEST_DIR + "/net/cellular/http/ubloxusb" ]),
69
- ("UbloxModemSMSTest" , [TEST_DIR + "/net/cellular/sms/common" , TEST_DIR + "/net/cellular/sms/ubloxusb" ]),
70
- ("FATFileSystem" , FAT_FS , "mbed-official" ),
71
- )
72
-
49
+ OFFICIAL_CODE = {"mbed-dev" : ["cmsis" , "drivers" , "hal" , "platform" , "targets" , "mbed.h" ]}
73
50
74
- # Code that does have dependencies to libraries should point to
75
- # the latest revision. By default, they point to a specific revision.
76
- CODE_WITH_DEPENDENCIES = (
77
- # Libraries
78
- "EthernetInterface" ,
79
-
80
- # RTOS Examples
81
- "rtos_basic" ,
82
- "rtos_isr" ,
83
- "rtos_mail" ,
84
- "rtos_mutex" ,
85
- "rtos_queue" ,
86
- "rtos_semaphore" ,
87
- "rtos_signals" ,
88
- "rtos_timer" ,
89
-
90
- # Net Examples
91
- "TCPEchoClient" ,
92
- "TCPEchoServer" ,
93
- "TCPSocket_HelloWorld" ,
94
- "UDPSocket_HelloWorld" ,
95
- "UDPEchoClient" ,
96
- "UDPEchoServer" ,
97
- "BroadcastReceive" ,
98
- "BroadcastSend" ,
99
-
100
- # mbed sources
101
- "mbed-src-program" ,
102
- )
103
51
104
52
# A list of regular expressions that will be checked against each directory
105
53
# name and skipped if they match.
@@ -125,13 +73,11 @@ def run_and_print(command, cwd):
125
73
stdout , _ , _ = run_cmd (command , work_dir = cwd , redirect = True )
126
74
print (stdout )
127
75
128
- def __init__ (self , name , team = None ):
76
+ def __init__ (self , name ):
129
77
self .name = name
130
78
self .path = join (MBED_ORG_PATH , name )
131
- if team is None :
132
- self .url = "http://" + MBED_URL + "/users/" + MBED_USER + "/code/%s/"
133
- else :
134
- self .url = "http://" + MBED_URL + "/teams/" + team + "/code/%s/"
79
+ self .url = "http://" + MBED_URL + "/users/" + MBED_ORG_USER + "/code/%s/"
80
+
135
81
if not exists (self .path ):
136
82
# Checkout code
137
83
if not exists (MBED_ORG_PATH ):
@@ -158,6 +104,9 @@ def publish(self):
158
104
commit = raw_input (push_remote and "Do you want to commit and push? Y/N: " or "Do you want to commit? Y/N: " )
159
105
if commit == 'Y' :
160
106
args = ['hg' , 'commit' , '-u' , MBED_ORG_USER ]
107
+
108
+
109
+ # NOTE commit_msg should always come from the relevant mbed 2 release text
161
110
if commit_msg :
162
111
args = args + ['-m' , commit_msg ]
163
112
self .run_and_print (args , cwd = self .path )
@@ -229,7 +178,7 @@ def copy_with_line_endings(sdk_file, repo_file):
229
178
f .close ()
230
179
231
180
def visit_files (path , visit ):
232
- for root , dirs , files in walk (path ):
181
+ for root , dirs , files in walk (path ):
233
182
# Ignore hidden directories
234
183
for d in copy (dirs ):
235
184
full = join (root , d )
@@ -245,91 +194,122 @@ def visit_files(path, visit):
245
194
246
195
visit (join (root , file ))
247
196
197
+ def visit_dirs (path , visit ):
198
+
199
+ for root , dirs , files in walk (path , topdown = False ):
200
+ for d in dirs :
201
+ full = join (root , d )
202
+
203
+ # We don't want to remove the .hg directory
204
+ if not '.hg' in full :
205
+ visit (full )
206
+
248
207
249
- def update_repo (repo_name , sdk_paths , team_name ):
250
- repo = MbedRepository (repo_name , team_name )
208
+ def update_repo (repo_name , sdk_paths , lib = False ):
209
+ repo = MbedRepository (repo_name )
210
+
251
211
# copy files from mbed SDK to mbed_official repository
252
212
def visit_mbed_sdk (sdk_file ):
253
- repo_file = join (repo .path , relpath (sdk_file , sdk_path ))
254
213
214
+ # Source files structure is different for the compiled binary lib
215
+ # compared to the mbed-dev sources
216
+ if lib :
217
+ repo_file = join (repo .path , relpath (sdk_file , sdk_path ))
218
+ else :
219
+ repo_file = join (repo .path , sdk_file )
255
220
repo_dir = dirname (repo_file )
256
221
if not exists (repo_dir ):
222
+ print ("CREATING: %s" % repo_dir )
257
223
makedirs (repo_dir )
258
224
259
225
copy_with_line_endings (sdk_file , repo_file )
226
+
227
+ # Go through each path specified in the mbed structure
260
228
for sdk_path in sdk_paths :
261
- visit_files (sdk_path , visit_mbed_sdk )
229
+
230
+ if isfile (sdk_path ):
231
+ # Single file so just copy directly across
232
+ visit_mbed_sdk (sdk_path )
233
+ else :
234
+ visit_files (sdk_path , visit_mbed_sdk )
235
+
236
+ def sdk_remove (repo_path ):
237
+
238
+ print ("REMOVING: %s" % repo_path )
239
+
240
+ # Check if this is an empty directory or a file before determining how to
241
+ # delete it. As this function should only be called with a directory list
242
+ # after being called with a file list, the directory should automatically
243
+ # be either valid or empty .
244
+ if isfile (repo_path ):
245
+ remove (repo_path )
246
+ elif isdir (repo_path ) and not listdir (repo_path ):
247
+ rmdir (repo_path )
248
+ else :
249
+ print ("ERROR: %s is not empty, please remove manually." % repo_path )
250
+ print listdir (repo_path )
251
+ exit (1 )
262
252
263
253
# remove repository files that do not exist in the mbed SDK
264
- def visit_repo ( repo_file ):
254
+ def visit_lib_repo ( repo_path ):
265
255
for sdk_path in sdk_paths :
266
- sdk_file = join (sdk_path , relpath (repo_file , repo .path ))
267
- if exists (sdk_file ):
268
- break
269
- else :
270
- remove (repo_file )
271
- print "remove: %s" % repo_file
272
- visit_files (repo .path , visit_repo )
256
+ sdk_file = join (sdk_path , relpath (repo_path , repo .path ))
257
+ if not exists (sdk_file ):
258
+ sdk_remove (repo_path )
273
259
274
- if repo . publish ():
275
- changed . append ( repo_name )
260
+ # remove repository files that do not exist in the mbed SDK source
261
+ def visit_repo ( repo_path ):
276
262
263
+ # work out equivalent sdk path from repo file
264
+ sdk_path = join (getcwd (), relpath (repo_path , repo .path ))
277
265
278
- def update_code (repositories ):
279
- for r in repositories :
280
- repo_name , sdk_dir = r [0 ], r [1 ]
281
- team_name = r [2 ] if len (r ) == 3 else None
282
- print '\n === Updating "%s" ===' % repo_name
283
- sdk_dirs = [sdk_dir ] if type (sdk_dir ) != type ([]) else sdk_dir
284
- update_repo (repo_name , sdk_dirs , team_name )
266
+ if not exists (sdk_path ):
267
+ sdk_remove (repo_path )
268
+
269
+ # Go through each path specified in the mbed structure
270
+ # Check if there are any files in any of those paths that are no longer part of the SDK
285
271
286
- def update_single_repo (repo ):
287
- repos = [r for r in OFFICIAL_CODE if r [0 ] == repo ]
288
- if not repos :
289
- print "Repository '%s' not found" % repo
272
+ if lib :
273
+ visit_files (repo .path , visit_lib_repo )
274
+ # Now do the same for directories that may need to be removed. This needs to be done
275
+ # bottom up to ensure any lower nested directories can be deleted first
276
+ visit_dirs (repo .path , visit_lib_repo )
277
+
290
278
else :
291
- update_code ( repos )
279
+ visit_files ( repo . path , visit_repo )
292
280
293
- def update_dependencies (repositories ):
294
- for repo_name in repositories :
295
- print '\n === Updating "%s" ===' % repo_name
296
- repo = MbedRepository (repo_name )
281
+ # Now do the same for directories that may need to be removed. This needs to be done
282
+ # bottom up to ensure any lower nested directories can be deleted first
283
+ visit_dirs (repo .path , visit_repo )
284
+
285
+ if repo .publish ():
286
+ changed .append (repo_name )
297
287
298
- # point to the latest libraries
299
- def visit_repo (repo_file ):
300
- with open (repo_file , "r" ) as f :
301
- url = f .read ()
302
- with open (repo_file , "w" ) as f :
303
- f .write (url [:(url .rindex ('/' )+ 1 )])
304
- visit_files (repo .path , visit_repo , None , MBED_REPO_EXT )
305
288
306
- if repo .publish ():
307
- changed .append (repo_name )
289
+ def update_code (repositories ):
290
+ for repo_name in repositories .keys ():
291
+ sdk_dirs = repositories [repo_name ]
292
+ print '\n === Updating "%s" ===' % repo_name
293
+ update_repo (repo_name , sdk_dirs )
308
294
309
295
310
296
def update_mbed ():
311
- update_repo ("mbed" , [join (BUILD_DIR , "mbed" )], None )
297
+ update_repo ("mbed" , [join (BUILD_DIR , "mbed" )], lib = True )
312
298
313
299
def do_sync (options ):
314
300
global push_remote , quiet , commit_msg , changed
315
301
316
302
push_remote = not options .nopush
317
303
quiet = options .quiet
318
304
commit_msg = options .msg
319
- chnaged = []
305
+ changed = []
320
306
321
307
if options .code :
322
308
update_code (OFFICIAL_CODE )
323
309
324
- if options .dependencies :
325
- update_dependencies (CODE_WITH_DEPENDENCIES )
326
-
327
310
if options .mbed :
328
311
update_mbed ()
329
312
330
- if options .repo :
331
- update_single_repo (options .repo )
332
-
333
313
if changed :
334
314
print "Repositories with changes:" , changed
335
315
@@ -342,10 +322,6 @@ def do_sync(options):
342
322
action = "store_true" , default = False ,
343
323
help = "Update the mbed_official code" )
344
324
345
- parser .add_option ("-d" , "--dependencies" ,
346
- action = "store_true" , default = False ,
347
- help = "Update the mbed_official code dependencies" )
348
-
349
325
parser .add_option ("-m" , "--mbed" ,
350
326
action = "store_true" , default = False ,
351
327
help = "Release a build of the mbed library" )
@@ -358,10 +334,6 @@ def do_sync(options):
358
334
action = "store" , type = "string" , default = '' , dest = 'msg' ,
359
335
help = "Commit message to use for all the commits" )
360
336
361
- parser .add_option ("-r" , "--repository" ,
362
- action = "store" , type = "string" , default = '' , dest = 'repo' ,
363
- help = "Synchronize only the given repository" )
364
-
365
337
parser .add_option ("-q" , "--quiet" ,
366
338
action = "store_true" , default = False ,
367
339
help = "Don't ask for confirmation before commiting or pushing" )
0 commit comments