mbed-scli test program

Dependencies:   Scheduler

Committer:
mimi3
Date:
Sat Mar 04 14:46:27 2017 +0900
Revision:
6:7915b5819364
Parent:
5:c3524dc89507
v0.8

Who changed what in which revision?

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