mbed-scli test program

Dependencies:   Scheduler

Committer:
mimi3
Date:
Mon Feb 27 22:51:57 2017 +0900
Revision:
4:85e9057db7a6
Parent:
3:60330a83318b
Child:
5:c3524dc89507
update: to v0.6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mimi3 0:b54fab1223b5 1 #### lib.py for mbed ####
mimi3 4:85e9057db7a6 2 # v0.6
mimi3 0:b54fab1223b5 3 # 2017/02 made by dinau
mimi3 0:b54fab1223b5 4 #
mimi3 0:b54fab1223b5 5 # Notice: Unsupported libraries.
mimi3 0:b54fab1223b5 6 # These libraries must be specified in Makefile.
mimi3 0:b54fab1223b5 7 # mbed-os
mimi3 0:b54fab1223b5 8 # mbed-dev
mimi3 0:b54fab1223b5 9
mimi3 0:b54fab1223b5 10
mimi3 0:b54fab1223b5 11 # Usage:
mimi3 0:b54fab1223b5 12 # $ make lib
mimi3 0:b54fab1223b5 13 # or
mimi3 0:b54fab1223b5 14 # $ python makelib.py
mimi3 0:b54fab1223b5 15 #
mimi3 0:b54fab1223b5 16
mimi3 0:b54fab1223b5 17 import os,sys
mimi3 0:b54fab1223b5 18 import commands
mimi3 0:b54fab1223b5 19 from urlparse import urlparse
mimi3 0:b54fab1223b5 20
mimi3 0:b54fab1223b5 21 HG = 1
mimi3 0:b54fab1223b5 22 GIT = 2
mimi3 0:b54fab1223b5 23 MBEDOS = 3
mimi3 0:b54fab1223b5 24 CMD_HG_CLONE = 'hg clone -q '
mimi3 0:b54fab1223b5 25 CMD_GIT_CLONE = 'git clone -q '
mimi3 0:b54fab1223b5 26 CMD_GIT_CHECKOUT= 'git checkout -q '
mimi3 0:b54fab1223b5 27
mimi3 0:b54fab1223b5 28 def hgClone(param):
mimi3 0:b54fab1223b5 29 cmd = CMD_HG_CLONE + param
mimi3 0:b54fab1223b5 30 return os.system( cmd )
mimi3 0:b54fab1223b5 31
mimi3 0:b54fab1223b5 32 def gitClone(param):
mimi3 0:b54fab1223b5 33 cmd = CMD_GIT_CLONE + param
mimi3 0:b54fab1223b5 34 return os.system( cmd )
mimi3 0:b54fab1223b5 35
mimi3 0:b54fab1223b5 36 def gitCheckout(param):
mimi3 0:b54fab1223b5 37 cmd = CMD_GIT_CHECKOUT + param
mimi3 0:b54fab1223b5 38 return os.system( cmd )
mimi3 0:b54fab1223b5 39 def getDvcs(url):
mimi3 4:85e9057db7a6 40 p = urlparse( url )
mimi3 4:85e9057db7a6 41 print p
mimi3 0:b54fab1223b5 42 if ('developer.mbed.org' in url) or ('mbed.org' in url) or ('bitbucke.org' in url):
mimi3 0:b54fab1223b5 43 return HG;
mimi3 0:b54fab1223b5 44 elif 'mbed-os' in url:
mimi3 0:b54fab1223b5 45 return MBEDOS
mimi3 0:b54fab1223b5 46 elif 'github.com' in url:
mimi3 0:b54fab1223b5 47 return GIT
mimi3 0:b54fab1223b5 48 else:
mimi3 0:b54fab1223b5 49 return 0
mimi3 0:b54fab1223b5 50
mimi3 0:b54fab1223b5 51 def getLibs(target_dir):
mimi3 0:b54fab1223b5 52 savedir = os.getcwd()
mimi3 0:b54fab1223b5 53 os.chdir(target_dir)
mimi3 0:b54fab1223b5 54 liblist=[]
mimi3 0:b54fab1223b5 55 for fname in os.listdir('.'):
mimi3 0:b54fab1223b5 56 if os.path.isfile(fname):
mimi3 0:b54fab1223b5 57 name, ext = os.path.splitext(fname)
mimi3 0:b54fab1223b5 58 if ext == '.lib':
mimi3 0:b54fab1223b5 59 if name != 'mbed-os':
mimi3 0:b54fab1223b5 60 liblist.append(fname)
mimi3 0:b54fab1223b5 61 if len( liblist ) > 0:
mimi3 0:b54fab1223b5 62 #print liblist
mimi3 0:b54fab1223b5 63 for libfile in liblist:
mimi3 0:b54fab1223b5 64 subdir, ext = os.path.splitext(libfile)
mimi3 4:85e9057db7a6 65 if os.path.isdir( subdir ):
mimi3 4:85e9057db7a6 66 print "%s :: already exists !" % (subdir)
mimi3 4:85e9057db7a6 67 continue
mimi3 0:b54fab1223b5 68 print subdir
mimi3 0:b54fab1223b5 69 url = open(libfile).read()
mimi3 0:b54fab1223b5 70 print url
mimi3 0:b54fab1223b5 71 sys.stdout.flush()
mimi3 0:b54fab1223b5 72 dvcs = getDvcs(url)
mimi3 0:b54fab1223b5 73 if dvcs == HG:
mimi3 0:b54fab1223b5 74 hgClone( url )
mimi3 0:b54fab1223b5 75 getLibs(subdir)
mimi3 0:b54fab1223b5 76 elif dvcs == MBEDOS:
mimi3 0:b54fab1223b5 77 # Nothing is downloaded if mbed-os lib be.
mimi3 0:b54fab1223b5 78 print 'mbed-os'
mimi3 0:b54fab1223b5 79 sys.stdout.flush()
mimi3 0:b54fab1223b5 80 elif dvcs == GIT:
mimi3 0:b54fab1223b5 81 params = url.split('#')
mimi3 0:b54fab1223b5 82 if len(params) == 1:
mimi3 0:b54fab1223b5 83 gitClone( params[0] )
mimi3 0:b54fab1223b5 84 getLibs(subdir)
mimi3 0:b54fab1223b5 85 elif len(params) == 2:
mimi3 0:b54fab1223b5 86 gitClone( params[0] )
mimi3 0:b54fab1223b5 87 os.chdir(subdir)
mimi3 0:b54fab1223b5 88 print 'cd %s' % (subdir)
mimi3 0:b54fab1223b5 89 sys.stdout.flush()
mimi3 0:b54fab1223b5 90 gitCheckout( params[1] )
mimi3 0:b54fab1223b5 91 getLibs(subdir)
mimi3 0:b54fab1223b5 92 os.chdir(savedir)
mimi3 0:b54fab1223b5 93
mimi3 0:b54fab1223b5 94 ###################
mimi3 0:b54fab1223b5 95 # main prog
mimi3 0:b54fab1223b5 96 ###################
mimi3 4:85e9057db7a6 97 if len(sys.argv) == 1:
mimi3 0:b54fab1223b5 98 print '--- Getting libraries ----'
mimi3 0:b54fab1223b5 99 getLibs('.')
mimi3 0:b54fab1223b5 100 print '--- end ---'
mimi3 4:85e9057db7a6 101 else:
mimi3 4:85e9057db7a6 102 url = sys.argv[1]
mimi3 4:85e9057db7a6 103 p = urlparse( url )
mimi3 4:85e9057db7a6 104 path = p.path
mimi3 4:85e9057db7a6 105 if path[-1:] == '/':
mimi3 4:85e9057db7a6 106 path = path[:-1]
mimi3 4:85e9057db7a6 107 libdir = os.path.basename(path)
mimi3 4:85e9057db7a6 108 libname = libdir + '.lib'
mimi3 4:85e9057db7a6 109 if not os.path.isdir( libdir ):
mimi3 4:85e9057db7a6 110 with open( libname,'w') as fp:
mimi3 4:85e9057db7a6 111 fp.write( url )
mimi3 4:85e9057db7a6 112 print '--- Getting libraries ----'
mimi3 4:85e9057db7a6 113 getLibs('.')
mimi3 4:85e9057db7a6 114 print '--- end ---'