脚本在搭建OMS开发环境中的应用

OMS 平台开发环境相比普通的 PC 应用开发要麻烦很多,原因有:  
  1. 开发主要是在 linux 环境下,系统本身开发工具不完善,虽然上层应用开发可以依赖 SDK, 借助 eclipse IDE ,给开发带来很大的方便,但整个平台一层的开发在 SDK 之下,所以更多的采用控制台下开发,随之而来的是大量多变的命令行,让人望而生畏
 
  1. 编译和运行分布在不同的系统环境中(桌面电脑和手机),调试,更新程序都不同于单机开发,环境更多,命令更多
 
 
  1. 手机多样,不同的硬件配置意味着相应的程序也要做相应的调整,因而会出现针对不同手机种类而出的不同版本的系统平台
 
 

在同时进行多个平台版本的开发的时候,麻烦尤其突出:

场景一:目录的频繁切换:

  1. 开发时,不同目录下的几个源码需要同步改动
  2. 几个平台之间代码有差异但也有相同的部分,需要在改动一个平台的时候兼顾其它平台
  3. 编译时,需要切换到平台代码的根下,设置环境变量,不同平台,根目录不同
  4. 生成的运行文件需要放入测试手机时候,这些运行文件分布在不同的目录下
 

场景二:代码频繁交叉改动:

  1. 多个需求交替而至,一个完整的功能还没有完成,又有其他的改动进入代码
  2. 为测试方便,添加了一些不能公开的代码,每次提交代码时又需要把这些代码剔除掉
 

场景三:更新手机的运行文件麻烦:

  1. 需要设置环境变量,传输命令需要给出正确的文件文件路径,关键的平台库上传后还需要重启手机系统
  2. 重新打包成 image 文件,再做成烧手机文件,烧手机过程冗长,对于频繁改动的情况无法忍受
 

场景四:本地库崩溃调试麻烦:

  •       对于一般的 java 层代码出现异常, davlink 给出了很好的现场信息提示,往往不用分析 log 就可以直接定位问题所在,而本地库只有一些晦涩的 16 进制代码地址串组成的崩溃栈信息,需要进行分析

   以上列举了几种很烦人却又很常见的场景,接下来将要针对以上的问题给出一些能够提高工作效率的脚本代码,希望能给大家在工作中带来帮助,同时起到抛砖引玉的作用:

  • c
  • 使用说明:

  • c +    è 将当前目录加入目录快速切换列表中

  • c -      è 将当前目录从目录快速切换列表中删除

  • c – [a~z] è 从目录快速切换列表删除标记为某个字母的目录项

  • c [1~9]   è 后退 n 级目录,如 c 2 == cd ../../

  • c     è 列出所有目录快速切换列表的内容,根据左方标记作出目录切换选择

  • c [a~z]   è 直接根据标记进行目录切换

  • c [string] è string 作为关键字在快速目录中查找并列出结果

  • ( 该目录列表中保存有两类路径,绝对和相对,对于某平台内路径,则保存为相对路径,并根据当前所在平台,自动切入该平台的该相对路径。 )

  • 例子

  • c framework

  • c 2  

  • r
  • 用法:

  •    不同平台下同等目录的切换

  • 例子 :

  • cd `r tiger`

  • meld test.java `r rabbit`test.java

  • push
  • 用法:

  •    任意目录下给手机传输编译生成的文件:

  • 例子:

  •  
    • /home/b045/work/tiger/package/apps/Mail$push out/target/product/generical/system/app/Mail.apk  

  • pusht
  • 用法:

  •    遍历子目录的方式向手机传输多个文件

  • 例子:

  •    pusht out/target/product/generical/system/app/*  

  • dstack
  • 用法:

  •     logcat 中的本地代码栈内容还原成代码行信息

  • 例子:

  • dstack

  •    I/DEBUG   ( 1501): signal 11 (SIGSEGV), fault addr deaddead

  • bak
  • 用法:

  •    快速备份

  • 例子:

  • framework$bak *   è 备份

  • bak –r Activity.java   è 恢复备份

  • bak –c Activity.java     è 版本比较  

  • alias rphone="adb shell ps | grep system_ | awk '{print /$2 }' | xargs -t adb shell kill"
  • 用法:

  •    手机快速重启,原理:杀 system_server 进程。

  • 例子:

  •    rphone  

  • alias tousb='sudo /home/b045/bin/UsbSwitch_Linux;export ADBHOST=192.168.100.2;adb kill-server'
  • 用法:

  •    快速接入手机的 usb net 模式

  • 例子:

  •    tousb

  • ox
  • 用法:

  •    快速设置编译环境,

  • 例子:

  •    /home/b045/work/tiger$. ox    ==  . build/envsetup.sh && tapas

  • mkimg
  • 用法:

  •    任意平台目录快速生成 system.img 文件

  • 例子:

  •    mkimg

  • apk.reg
  • 用法:

  •    双击该 regr 文件,执行成功后,在所有 apk 文件的快捷菜单里有一项安装到手机里,点击该菜单项即可完成 apk 包的安装。  

总结:以上 10 多个短小的脚本实现的命令 , 充分发掘脚本本身的特性,大大缩减了开发过程中的低级重复劳动,希望能够提高大家的工作效率,并期待对大家有所启发,对其中的代码进行指正,扩充。  
 

附录:以上提到的所有脚本源码,

  • c
  • #!/usr/bin/env python  
     
    import  os,sys,fcntl,termios  
     
    dirlstfile = "
    /home/b045/.dirlst
    dirlst = file(dirlstfile, "
    r+ ").read().split(" /n ")[:-1] 
    commonbase = ["
    /home/b045/work/rat/ ", " /home/b045/work/tiger/ ", " /home/b045/work/rabbit/ ",  ] 
    updated = 0 
     
    def  torelate (path): 
        
    for  item in  commonbase:  
            
    if  path.find(item)>=0:  
                
    return  path[len(item):] 
     
        
    return  path 
     
    def  toabspath (path): 
        
    if  path[0] != ' / ': 
            pwd = os.path.abspath(os.getcwd()) 
            apppath = commonbase[0] 
            
    for  item in  commonbase[1:]:  
                
    if  pwd[:len(item)-1] == item[:-1]: 
                    apppath=item 
                    
    break  
                
    if  item[-2]==' * and  pwd[:len(item)-2]==item[:-2]:  
                    apppath=item 
                    
    break  
            
    return  " %s%s "%(apppath,path) 
        
    return  path 
     
    def  listdir (dirlst, filter): 
        startc = '
    a
        dircnt = 0 
        lastpath="" 
        
    for  item in  dirlst: 
            
    if  item!=''  and  filter in  item: 
                
    print  startc,item 
                lastpath=item 
                dircnt+=1 
            startc=chr(ord(startc)+1) 
        
    if  dircnt == 0 :  
            
    print  " use 'c +' to add dir cache
            
    return  
        
    if  dircnt==1: 
            shellcmd( "
    cd %s /n "%toabspath(lastpath))  
            
    return  
        ret = raw_input("
    select: ") 
        
    if  ret == '' : return  
        seldir(dirlst, ret[0]) 
     
    def  shellcmd (cmd):       
        
    for  c in  cmd:fcntl.ioctl(0, termios.TIOCSTI,c) 
     
    def  seldir (dirlst, c): 
        shellcmd( "
    cd %s /n "%toabspath(dirlst[ord(c)-ord(' a ')]))  
     
    if  len(sys.argv) > 1: 
        
    if  sys.argv[1] == ' - ': 
            
    if  len(sys.argv) == 2: 
                
    for  d in  dirlst: 
                    
    if  toabspath(d) == os.getcwd(): 
                        dirlst.remove(d) 
                        updated = 1 
                        
    break
            
    else
                startc = '
    a
                
    for  item in  dirlst: 
                    
    if  startc in  sys.argv[2]:  
                        dirlst.remove(item) 
                        updated = 1 
                    startc=chr(ord(startc)+1) 
     
        
    elif  sys.argv[1] == ' + ': 
            
    if  os.getcwd() not in  dirlst:  
                dirlst.append(torelate(os.getcwd())) 
                
    for  item in  dirlst: 
                    
    if  item=="": 
                        item=os.getcwd() 
                        dirlst=dirlst[:-1] 
                        
    break  
                updated = 1 
        
    elif  ' 1 ' <= sys.argv[1][0] <= ' 9 and  len(sys.argv[1]) == 1: 
            shellcmd("
    cd %s /n "%(' ../ '*(ord(sys.argv[1])-ord(' 0 ')))) 
        
    elif  len(sys.argv[1]) == 1: 
            seldir(dirlst, sys.argv[1]) 
        
    else :  
            listdir(dirlst, sys.argv[1]) 
     
    else
        listdir(dirlst, "") 
     
    if  updated == 1: 
        fl = file(dirlstfile, "
    w ") 
        
    for  item in  dirlst: 
            fl.write("
    %s /n "%item)

  • r
  • #!/usr/bin/env python  
     
    import  os,sys 
     
    pwd = os.getcwd() 
    pwd = os.path.abspath(pwd) 
    prefix='
    /home/b045/work/
    if  pwd.find(prefix)==0: 
        endpos=pwd.find('
    / ', len(prefix)+1) 
        pwd=prefix+sys.argv[1]+pwd[endpos:]+'
    /
    print  pwd

  • push
  • #!/usr/bin/env python  
     
    import  os,sys,fcntl,termios  
     
    def  shellcmd (cmd):       
        
    print  cmd, 
        
    try
            os.system(cmd) 
            os.wait() 
        
    except :  
            
    pass  
     
    #def shellcmd(cmd):      
    #    for c in cmd:fcntl.ioctl(0, termios.TIOCSTI,c)  
     
    if  len(sys.argv) > 1: 
        
    for  arg in  sys.argv[1:]: 
            
    if (arg[:4] == " out/ "): arg = " %s/%s "%(os.getenv(" ANDROID_BUILD_TOP "), arg) 
            arg=os.path.abspath(arg) 
            
    if (arg.rfind(' /system/ ') == -1): 
                shellcmd("
    adb install -r %s /n "%(arg)) 
            
    else
                shellcmd("
    adb push %s %s /n "%(arg, arg[arg.rfind(' /system/ '):]))

  • pusht
  • #!/usr/bin/env python  
     
    import  os,sys,fcntl,termios,glob  
     
    def  shellcmd (cmd):       
        
    print  cmd, 
        
    try
            os.system(cmd) 
            os.wait() 
        
    except :  
            
    pass  
     
    #    for c in cmd:fcntl.ioctl(0, termios.TIOCSTI,c)  
    def  transfer (fs): 
        
    for  fn in  fs: 
            
    if  os.path.isdir(fn): 
                shellcmd("
    adb shell mkdir %s /n "%(fn[fn.rfind(' /system/ '):])) 
                transfer(glob.glob("
    %s/* "%fn)) 
                
    continue  
            
    if (fn.rfind(' /system/ ') == -1): 
                shellcmd("
    adb install -r %s /n "%(fn)) 
            
    else
                shellcmd("
    adb push %s %s /n "%(fn, fn[fn.rfind(' /system/ '):])) 
     
    if  len(sys.argv) > 1: 
        
    for  arg in  sys.argv[1:]: 
            
    if (arg[:4] == " out/ "): arg = " %s/%s "%(os.getenv(" ANDROID_BUILD_TOP "), arg) 
            
    if  os.path.isdir(arg): fs=glob.glob(" %s/* "%arg) 
            
    else :fs=glob.glob(arg) 
            transfer(fs)

  • dstack

#!/usr/bin/env python  
 
import  commands, string, os, sys 
 
sobase={} 
 
armmap = '
build/core/prelink-linux-arm.map
if  os.getenv(' ANDROID_BUILD_TOP ') != None: 
    armmap = ('
%s/%s ')%(os.getenv(' ANDROID_BUILD_TOP '), armmap) 
for  its in  file(armmap): 
    it = its.split() 
    
if  len(it) == 2 and  it[0][:3]==' lib ': 
        sobase[it[0]]=string.atoi(it[1], 16) 
 
def  issopath (testpath): 
    paths=testpath.split('
/ ') 
    testfile=paths[len(paths)-1] 
    
if (testfile[:3]==" lib and  testfile[-3:] ==  " .so "): 
        
return  True 
    
return  False 
 
def  add2line (addrstr, sopath): 
    paths=sopath.split('
/ ') 
    testfile=paths[len(paths)-1] 
    binaddr = string.atoi(addrstr, 16) 
    binaddr -= sobase[testfile] 
    
if  os.getenv(' ANDROID_PRODUCT_OUT ') != None: 
        out=commands.getoutput("
addr2line  -f -C -e %s/%s %#x "%(os.getenv(' ANDROID_PRODUCT_OUT '), sopath, binaddr)) 
    
else
        out=commands.getoutput("
addr2line  -f -C -e out/target/product/SPARK/symbols/%s %#x "%(sopath, binaddr)) 
    out = out.rsplit('
/n ', 1) 
    
print  ' /033 [32m ', " %s%s ==> %s /n %s%s "%(' '*12, addrstr, out[0], ' '*13, out[1]), ' /033 [0m
 
def  parseadd (it): 
    
if  len(it)==2 and  issopath(it[1]): 
        add2line(it[0], it[1]) 
    
if  len(it)<5: return  
    
if  it[0] != ' I/DEBUG ': return  
    
elif  len(it)==7 and  (it[4]==' pc or  it[4]==' lr ') and  issopath(it[6]): 
        add2line(it[5], it[6]) 
    
elif  len(it)==7 and  (it[3]==' ==> ') and  issopath(it[6]): 
        add2line(it[5], it[6]) 
    
elif  len(it)==6 and  issopath(it[5]): 
        add2line(it[4], it[5]) 
 
if  len(sys.argv) > 1: 
    parseadd(sys.argv[1:]) 
    sys.exit() 
 
while  1: 
    its =  raw_input() 
    
if  its=='': break  
    it = its.split() 
    parseadd(it) 

  • bak
  • #!/usr/bin/env python  
     
    import  shutil,os,time,sys,commands,string 
    def  getbaks (name): 
        res = commands.getoutput('
    find %s -name revert '%bakpath) 
        destpath = os.path.abspath(sys.argv[2]) 
        lst=[] 
        
    for  revf in  res.split(): 
            
    for  ln in  file(revf): 
                cmdlines = ln.split() 
                
    if  len(cmdlines)==4 and  cmdlines[0]==' cp and  cmdlines[3][1:-1] == destpath: 
                    lst.append([os.stat(cmdlines[2][1:-1])[8], (cmdlines[2][1:-1]), (cmdlines[3][1:-1])]) 
        lst.sort() 
        lst.reverse() 
        
    return  lst 
     
    bakpath = '
    ~/baks
    bakpath = os.path.expanduser(bakpath) 
    if not  os.path.exists(bakpath) :  
        os.mkdir(bakpath) 
    if  len(sys.argv)==3: 
        
    if (sys.argv[1] == ' -r '): 
            lst = getbaks(sys.argv[2]) 
            ind = 1 
            
    for  ln in  lst: 
                
    print  ' [%d] '%ind , time.strftime(" %m-%d %H:%M:%S ", time.localtime(ln[0])) 
                ind += 1 
            ind = string.atoi(raw_input('
    select: ')) 
            
    if  ind>0 and  len(lst)>=ind:  
                
    print  lst[ind-1][1], " ==> ", lst[ind-1][2] 
                
    if  os.path.isdir(lst[ind-1][2]):shutil.copytree(lst[ind-1][1], lst[ind-1][2]) 
                
    else : shutil.copy(lst[ind-1][1], lst[ind-1][2]) 
            exit(0) 
        
    if (sys.argv[1] == ' -d '): 
            lst = getbaks(sys.argv[2]) 
            
    for  ln in  lst: 
                os.system('
    meld %s %s '%(ln[1], ln[2])) 
            exit(0) 
      
    tmdir = "
    %s/%s "%(bakpath, time.strftime(" %m%d ", time.gmtime())) 
    if  os.path.exists(tmdir) :  
        extdir = 1 
        
    while  os.path.exists(" %s-%d "%(tmdir, extdir)) :  
            extdir = extdir + 1 
        tmdir = "
    %s-%d "%(tmdir, extdir) 
     
    os.mkdir(tmdir) 
     
    f = file(("
    %s/%s ")%(tmdir, ' revert '),' w ') 
    for  it in  sys.argv[1:]: 
        des = "
    %s/%s "%(tmdir,os.path.basename(it)) 
        c = 1 
        
    while  os.path.exists(des): 
            des = "
    %s/%d-%s "%(tmdir,c,os.path.basename(it)) 
            c = c+1    
        
    if (os.path.isdir(it)): shutil.copytree(it, des) 
        
    else : shutil.copyfile(it, des) 
        f.write('
    echo "%s ==> %s" /n '%(des, os.path.abspath(it))) 
        f.write('
    cp -rf "%s" "%s" /n '%(des, os.path.abspath(it)))

  • ox

. build/envsetup.sh

export TARGET_SIMULATOR=false

export TARGET_BUILD_TYPE=release

export TARGET_PRODUCT=OMS1_3

#generic

set_stuff_for_environment

  • mkimg

echo 'create image:' ${ANDROID_BUILD_TOP}/out/target/product/${TARGET_PRODUCT}/system.img

mkyaffs2image -f ${ANDROID_BUILD_TOP}/out/target/product/${TARGET_PRODUCT}/system ${ANDROID_BUILD_TOP}/out/target/product/$TARGET_PRODUCT/system.img

  • apk.reg
  • Windows Registry Editor Version 5.00

  • [HKEY_CLASSES_ROOT/.apk/shell/installphone/command]

  • @="/"adb.exe/" install -r /"%1/""

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值