@@ -266,7 +266,7 @@ def init(path):
266
266
def clone (url , path = None , depth = None , protocol = None ):
267
267
m = Bld .isurl (url )
268
268
if not m :
269
- raise ProcessException (1 , "Not an mbed library build URL" )
269
+ raise ProcessException (1 , "Not a library build URL" )
270
270
271
271
try :
272
272
Bld .init (path )
@@ -275,61 +275,61 @@ def clone(url, path=None, depth=None, protocol=None):
275
275
except Exception as e :
276
276
error (e [1 ], e [0 ])
277
277
278
+ def cleanup ():
279
+ info ("Cleaning up library build folder" )
280
+ for fl in os .listdir ('.' ):
281
+ if not fl .startswith ('.' ):
282
+ if os .path .isfile (fl ):
283
+ os .remove (fl )
284
+ else :
285
+ shutil .rmtree (fl )
286
+
278
287
def fetch_rev (url , rev ):
279
- tmp_file = os .path .join ('.' + Bld .name , '.rev-' + rev + '.zip' )
280
- arch_dir = 'mbed-' + rev
288
+ rev_file = os .path .join ('.' + Bld .name , '.rev-' + rev + '.zip' )
281
289
try :
282
- if not os .path .exists (tmp_file ):
283
- action ("Downloading mbed library build \" %s\" (might take a minute)" % rev )
290
+ if not os .path .exists (rev_file ):
291
+ action ("Downloading library build \" %s\" (might take a minute)" % rev )
284
292
outfd = open (tmp_file , 'wb' )
285
293
inurl = urllib2 .urlopen (url )
286
294
outfd .write (inurl .read ())
287
295
outfd .close ()
288
296
except :
289
- if os .path .isfile (tmp_file ):
290
- os .remove (tmp_file )
297
+ if os .path .isfile (rev_file ):
298
+ os .remove (rev_file )
291
299
raise Exception (128 , "Download failed!\n Please try again later." )
292
300
301
+ def unpack_rev (rev ):
302
+ rev_file = os .path .join ('.' + Bld .name , '.rev-' + rev + '.zip' )
293
303
try :
294
- with zipfile .ZipFile (tmp_file ) as zf :
295
- action ("Unpacking mbed library build \" %s\" in \" %s\" " % (rev , os .getcwd ()))
296
- zf .extractall ()
304
+ with zipfile .ZipFile (rev_file ) as zf :
305
+ action ("Unpacking library build \" %s\" in \" %s\" " % (rev , os .getcwd ()))
306
+ zf .extractall ('.' )
297
307
except :
298
- if os .path .isfile (tmp_file ):
299
- os .remove (tmp_file )
300
- if os .path .isfile (arch_dir ):
301
- rmtree_readonly (arch_dir )
302
- raise Exception (128 , "An error occurred while unpacking mbed library archive \" %s\" in \" %s\" " % (tmp_file , os .getcwd ()))
308
+ if os .path .isfile (rev_file ):
309
+ os .remove (rev_file )
310
+ raise Exception (128 , "An error occurred while unpacking library archive \" %s\" in \" %s\" " % (rev_file , os .getcwd ()))
303
311
304
312
def checkout (rev , clean = False ):
305
313
url = Bld .geturl ()
306
314
m = Bld .isurl (url )
307
315
if not m :
308
- raise ProcessException (1 , "Not an mbed library build URL" )
316
+ raise ProcessException (1 , "Not a library build URL" )
309
317
rev = Hg .remoteid (m .group (1 ), rev )
310
318
if not rev :
311
- error ("Unable to fetch late mbed library revision" )
312
-
313
- if rev != Bld .getrev ():
314
- info ("Cleaning up library build folder" )
315
- for fl in os .listdir ('.' ):
316
- if not fl .startswith ('.' ):
317
- if os .path .isfile (fl ):
318
- os .remove (fl )
319
- else :
320
- shutil .rmtree (fl )
319
+ error ("Unable to fetch library build information" )
320
+
321
+ arch_url = m .group (1 ) + '/archive/' + rev + '.zip'
322
+ Bld .fetch_rev (arch_url , rev )
323
+
324
+ if rev != Bld .getrev () or clean :
325
+ Bld .cleanup ()
321
326
322
327
info ("Checkout \" %s\" in %s" % (rev , os .path .basename (os .getcwd ())))
323
- arch_url = m .group (1 ) + '/archive/' + rev + '.zip'
324
- arch_dir = m .group (7 ) + '-' + rev
325
328
try :
326
- if not os . path . exists ( arch_dir ):
327
- Bld .fetch_rev ( arch_url , rev )
329
+ Bld . unpack_rev ( rev )
330
+ Bld .seturl ( url + '/' + rev )
328
331
except Exception as e :
329
- if os .path .exists (arch_dir ):
330
- rmtree_readonly (arch_dir )
331
332
error (e [1 ], e [0 ])
332
- Bld .seturl (url + '/' + rev )
333
333
334
334
def update (rev = None , clean = False , clean_files = False , is_local = False ):
335
335
return Bld .checkout (rev , clean )
0 commit comments