python 菜鸟学习笔记...
时间:2010-08-17 来源:zxm99888
python 脚本的执行问题:
本来想编写一个python的运行adb install的脚本
由于adb install会在当前文件夹下执行,而脚本又在当前目录导致adb install会到脚本文件是失败,又不想把每个文件明都加上路径,上豆瓣和baidu问了问,才了解到os.chdir,终于解决。
#!python
#coding=utf-8
import sys
import os
import string
import time
#path =' /home/symbio/apk/'
emulator = ''
if len(sys.argv) == 2:
showHelp()
elif len(sys.argv) > 2:
if sys.argv[1] == '-s':
emulator = sys.argv[2]
else:
showHelp()
if emulator == '':
ADBCMD = 'adb '
else:
ADBCMD = 'adb -s ' + emulator + '5554'
apkpackage = os.listdir("/home/symbio/apk")
#for i in range(len(apkpackage)):
# apkpackage[i] = path + apkpackage[i]
# print apkpackage[i]
#print len(apkpackage)
#print apkpackage
prerun = os.chdir('/home/symbio/apk')
#dir = os.system('ls')
#print dir
#install app test packages(.apk files)
print '>>>>>Begin to install test package files...'
for i in range(len(apkpackage)):
ret = os.system(ADBCMD + 'install -r ' + apkpackage[i])
if ret != 0:
print '\n\n\n>>>>>>>>ERROR>>>>>>>'
print 'Install ' + apkpackage[i] + ' failed! \nPlease check if the adb is working well or the package is right.'
print '>>>>>>>>>>>>>>>>>>>>\n\n\n'
exit()
print '>>>>>Test Package installation finished! Total is %d'%(len(apkpackage), )