mbed-scli test program

Dependencies:   Scheduler

Revision:
8:f1c7a11d0670
Parent:
7:9df443d2570b
--- a/mlib.py	Sat Mar 04 16:08:32 2017 +0900
+++ b/mlib.py	Sat Mar 04 19:01:33 2017 +0900
@@ -1,5 +1,5 @@
-####  lib.py for mbed ####
-# v0.8 # 2017/03 made by dinau
+####  mlib.py for mbed ####
+# v0.9 # 2017/03 made by dinau
 #
 # Notice: Unsupported libraries.
 #         These libraries must be specified in Makefile.
@@ -8,9 +8,14 @@
 
 
 # Usage:
+# Download the dependency libraries from web.
 #   $ make lib
 # or
-#   $ python makelib.py
+#   $ python mlib.py
+# Specify URL of a particular library to get it.
+#   $ python mlib.py http://...
+# Checkout mbed library with specified revision number.
+#   $ python mlib.py 136
 #
 
 import os,sys
@@ -104,25 +109,37 @@
 else:
     url = param1 = sys.argv[1]
     try:
+        # Number or URL
         revNum = int(param1)
     except:
+        # if URL of string
+        # Down load mbed library from URL
         p = urlparse( url )
-        path = p.path
-        if path[-1:] == '/':
-            path = path[:-1]
-        libdir  = os.path.basename(path)
-        libname = libdir + '.lib'
-        if not os.path.isdir( libdir ):
-            with open( libname,'w') as fp:
-                fp.write( url )
-            print '--- Getting libraries ----'
-            getLibs('.')
-            print '--- end ---'
+        if not("http" in p.scheme ) and not("https" in p.scheme ):
+            print "URL error !"
+        else:
+            path = p.path
+            if path[-1:] == '/':
+                path = path[:-1]
+            libdir  = os.path.basename(path)
+            libname = libdir + '.lib'
+            if not os.path.isdir( libdir ):
+                with open( libname,'w') as fp:
+                    fp.write( url )
+                print '--- Getting libraries ----'
+                getLibs('.')
+                print '--- end ---'
     else:
+        # if Number of string
+        # get mbed library of specified revsion
         mbed_root_file ='mbed-root.txt'
-        mbedRoot = open(mbed_root_file).read()
-        os.chdir( mbedRoot.strip() )
-        gitCheckout( 'mbed_lib_rev' + str( revNum ), True )
+        try:
+            mbedRoot = open(mbed_root_file).read()
+            os.chdir( mbedRoot.strip() )
+            gitCheckout( 'mbed_lib_rev' + str( revNum ), True )
+        except:
+            print  "First, at least execute 'make' command !"
 
 
 
+