mbed-scli test program
makelib.py
- Committer:
- mimi3
- Date:
- 2017-02-28
- Revision:
- 5:c3524dc89507
- Parent:
- 4:85e9057db7a6
- Child:
- 6:7915b5819364
File content as of revision 5:c3524dc89507:
#### lib.py for mbed #### # v0.7 # 2017/02 made by dinau # # Notice: Unsupported libraries. # These libraries must be specified in Makefile. # mbed-os # mbed-dev # Usage: # $ make lib # or # $ python makelib.py # import os,sys import commands from urlparse import urlparse HG = 1 GIT = 2 MBEDOS = 3 CMD_HG_CLONE = 'hg clone -q ' CMD_GIT_CLONE = 'git clone -q ' CMD_GIT_CHECKOUT= 'git checkout -q ' def hgClone(param): cmd = CMD_HG_CLONE + param return os.system( cmd ) def gitClone(param): cmd = CMD_GIT_CLONE + param return os.system( cmd ) def gitCheckout(param): cmd = CMD_GIT_CHECKOUT + param return os.system( cmd ) def getDvcs(url): p = urlparse( url ) print p if ('developer.mbed.org' in url) or ('mbed.org' in url) or ('bitbucke.org' in url): return HG; elif 'mbed-os' in url: return MBEDOS elif 'github.com' in url: return GIT else: return 0 def getLibs(target_dir): savedir = os.getcwd() os.chdir(target_dir) liblist=[] for fname in os.listdir('.'): if os.path.isfile(fname): name, ext = os.path.splitext(fname) if ext == '.lib': if name != 'mbed-os': liblist.append(fname) if len( liblist ) > 0: #print liblist for libfile in liblist: subdir, ext = os.path.splitext(libfile) if os.path.isdir( subdir ): print "%s :: already exists !" % (subdir) continue print subdir url = open(libfile).read() print url sys.stdout.flush() dvcs = getDvcs(url) if dvcs == HG: hgClone( url ) getLibs(subdir) elif dvcs == MBEDOS: # Nothing is downloaded if mbed-os lib be. print 'mbed-os' sys.stdout.flush() elif dvcs == GIT: params = url.split('#') if len(params) == 1: gitClone( params[0] ) getLibs(subdir) elif len(params) == 2: gitClone( params[0] ) os.chdir(subdir) print 'cd %s' % (subdir) sys.stdout.flush() gitCheckout( params[1] ) getLibs(subdir) os.chdir(savedir) ################### # main prog ################### if len(sys.argv) == 1: print '--- Getting libraries ----' getLibs('.') print '--- end ---' else: url = sys.argv[1] 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 ---'