前に書かれたいくつかのPの単語:
疲れる仕事、怠惰な使用ツール。プログラマーが怠惰な人々として社会的進歩を促進することは、すべての人にとって明らかです。
adbは、開発者が使用できるすべてのツールを提供していますが、一連のadbコマンドを繰り返し実行するのも面倒なので、ビジネスニーズが修正された場合は、Pythonスクリプトで直接adbコマンドを実行します。
コアコードは非常に単純です。
python学习交流群:660193417###
cmd = 'adb shell'
os.system(cmd)
1.ビジネス要件:アプリケーションのアンインストールを実行し、指定されたディレクトリを削除します
Python学习交流Q群:660193417###
#!/usr/bin/python
import subprocess
import os, sys
import getopt
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
if __name__ == '__main__':
""" change commands and add shell"""
tag = ''
try:
opt, args = getopt.getopt(sys.argv[1:], "ht:", ['pkg', 'help'])
for op, value in opt:
if op in ("-t", "--pkg"):
tag = value
if op in ("-h", "--help"):
print "Usage: main_app_clean.py -t APP_PKG_NAME"
print "Options:"
print " -t APP_PKG_NAME should be a bundle id !"
print ""
print "Sample : ./main_app_clean.py -t <bundle id>"
print ""
sys.exit() except getopt.GetoptError:
print "Error: Could not find the args."
print "Usage: main_app_clean.py -t APP_PKG_NAME"
print "Options:"
print " -t APP_PKG_NAME should be a bundle id !"
print ""
print "Sample : ./main_app_clean.py -t <bundle id>"
print "" sys.exit()
if tag == '':
print "you should input a bundle id !"
exit() pkg = tag
print '' print '1) uninstalling ' + pkg +' ...' unInstallCmd = 'adb uninstall ' + pkg os.system(unInstallCmd)
print '' print '2) cleaning the cached file...' cleanCmd1 = 'adb shell rm -fR /sdcard/.DataBackupTest'
os.system(cleanCmd1) cleanCmd2 = 'adb shell rm -fR /sdcard/.DataBackup' os.system(cleanCmd2)
print ''
print ' All done !^_^!'
print ''
exit()
指示:
- オープンターミナル
cd <uninstall_clean_app.py dir path>
- Pythonコマンドを実行します
python ./uninstall_clean_app.py -t com.xxx.app
2.ビジネス要件:obbファイルをAndroidデバイスにプッシュし、対応するアプリケーションに関連付けます
Python学习交流Q群:Python学习交流Q群:906715085##3
#!/usr/bin/python
import subprocess
import os, sys
import getopt
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
if __name__ == '__main__':
""" change commands and add shell"""
path = ''
package = ''
obbVersion = ''
#see: https://blog.csdn.net/chengxuyuanyonghu/article/details/54972854
try:
opt, args = getopt.getopt(sys.argv[1:], "hf:p:v:", ['file=', 'package=','obbVersion=','help'])
for op, value in opt:
if op in ("-f", "--file"):
path = value
if op in ("-p", "--package"):
package = value
if op in ("-v", "--obbVersion"):
obbVersion = value
if op in ("-h", "--help"):
print "Usage: obb_push.py -f obb/file/full/path -p com.example.app.bundleid -v app_vesion"
print "Options:"
print " <-f> <-p> <-v> should not be null !"
print ""
print "OR: <--file=> <--package=> <-obbVersion=> should not be null "
print ""
print "Sample : ./obb_push.py -f obb/file/full/path.obb -p <com.example.app.bundleid> -v 15"
print ""
print "OR : ./obb_push.py --file=obb/file/full/path.obb --package=com.example.app.bundleid --obbVersion=15"
print ""
sys.exit()
except getopt.GetoptError:
print "Usage: obb_push.py -f obb/file/full/path -p com.example.app.bundleid -v app_vesion"
print "Options:"
print " <-f> <-p> <-v> should not be null !"
print "OR:"
print " <--file=> <--package=> <-obbVersion=> should not be null "
print ""
print "Sample : ./obb_push.py -f obb/file/full/path.obb -p <com.example.app.bundleid> -v 15"
print ""
print "OR : ./obb_push.py --file=obb/file/full/path.obb --package=com.example.app.bundleid --obbVersion=15"
print ""
sys.exit()
if path == '':
print "you should input a obb file\'s path !"
exit()
print '\n'
print '||--------------------------------------------------------------||'
print '\n'
print 'NOTICE:'
print 'obb file name rule: [main.bundleVersionCode.bundleID.obb]'
print '\n'
print '||--------------------------------------------------------------||'
print '\n'
print 'Start to copy obb file >>>>>>>>> '
print ' (1)===============> parsing obb file name:' obbFilePath = path
if obbFilePath == '':
print 'you should input a obb file\'s path !'
exit()
obbSubDirs = obbFilePath.split('/') # index = len(obbSubDirs) - 1 obbFileName = obbSubDirs[-1] print obbFileName if obbFileName == '' or obbFileName.find('.obb') == -1:
print 'can not find a obb file in the path !'
exit()
print '\n'
print '
get package name = ' + package
print '\n'
print ' (3)===============> adb shell mkdir :' obbDestPath = 'sdcard/Android/obb/' + package subDir = '' subDirs = obbDestPath.split('/') for dir in subDirs:
subDir += '/' + dir
# print subDir
os.system('adb shell mkdir ' + subDir)
print '\n' print ' (4)===============> adb push obb file to device :' pushCmd = 'adb push ' + obbFilePath.replace(' ','\\ ')+ ' /' + obbDestPath + '/'
# print pushCmd os.system(pushCmd)
print '\n'
print ' (5)===============> adb push rename obb file:'
newObbFileName = "main."+ obbVersion+"." + package + ".obb" oldFileFullPath = '/' + obbDestPath + '/' + obbFileName newFileFullPath = '/' + obbDestPath + '/' + newObbFileName
print ' old:' + oldFileFullPath reameCmd = 'adb shell mv ' + oldFileFullPath + " " + newFileFullPath os.system(reameCmd)
print ' new:' + newFileFullPath print '\n' print ' (6)===============> Completed!!!' print '\n' exit()
##3
#!/usr/bin/python
import subprocess
import os, sys
import getopt
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
if __name__ == '__main__':
""" change commands and add shell"""
path = ''
package = ''
obbVersion = ''
#see: https://blog.csdn.net/chengxuyuanyonghu/article/details/54972854
try:
opt, args = getopt.getopt(sys.argv[1:], "hf:p:v:", ['file=', 'package=','obbVersion=','help'])
for op, value in opt:
if op in ("-f", "--file"):
path = value
if op in ("-p", "--package"):
package = value
if op in ("-v", "--obbVersion"):
obbVersion = value
if op in ("-h", "--help"):
print "Usage: obb_push.py -f obb/file/full/path -p com.example.app.bundleid -v app_vesion"
print "Options:"
print " <-f> <-p> <-v> should not be null !"
print ""
print "OR: <--file=> <--package=> <-obbVersion=> should not be null "
print ""
print "Sample : ./obb_push.py -f obb/file/full/path.obb -p <com.example.app.bundleid> -v 15"
print ""
print "OR : ./obb_push.py --file=obb/file/full/path.obb --package=com.example.app.bundleid --obbVersion=15"
print ""
sys.exit()
except getopt.GetoptError:
print "Usage: obb_push.py -f obb/file/full/path -p com.example.app.bundleid -v app_vesion"
print "Options:"
print " <-f> <-p> <-v> should not be null !"
print "OR:"
print " <--file=> <--package=> <-obbVersion=> should not be null "
print ""
print "Sample : ./obb_push.py -f obb/file/full/path.obb -p <com.example.app.bundleid> -v 15"
print ""
print "OR : ./obb_push.py --file=obb/file/full/path.obb --package=com.example.app.bundleid --obbVersion=15"
print ""
sys.exit()
if path == '':
print "you should input a obb file\'s path !"
exit()
print '\n'
print '||--------------------------------------------------------------||'
print '\n'
print 'NOTICE:'
print 'obb file name rule: [main.bundleVersionCode.bundleID.obb]'
print '\n'
print '||--------------------------------------------------------------||'
print '\n'
print 'Start to copy obb file >>>>>>>>> '
print ' (1)===============> parsing obb file name:' obbFilePath = path
if obbFilePath == '':
print 'you should input a obb file\'s path !'
exit()
obbSubDirs = obbFilePath.split('/') # index = len(obbSubDirs) - 1 obbFileName = obbSubDirs[-1] print obbFileName if obbFileName == '' or obbFileName.find('.obb') == -1:
print 'can not find a obb file in the path !'
exit()
print '\n'
print '
get package name = ' + package
print '\n'
print ' (3)===============> adb shell mkdir :' obbDestPath = 'sdcard/Android/obb/' + package subDir = '' subDirs = obbDestPath.split('/') for dir in subDirs:
subDir += '/' + dir
# print subDir
os.system('adb shell mkdir ' + subDir)
print '\n' print ' (4)===============> adb push obb file to device :' pushCmd = 'adb push ' + obbFilePath.replace(' ','\\ ')+ ' /' + obbDestPath + '/'
# print pushCmd os.system(pushCmd)
print '\n'
print ' (5)===============> adb push rename obb file:'
newObbFileName = "main."+ obbVersion+"." + package + ".obb" oldFileFullPath = '/' + obbDestPath + '/' + obbFileName newFileFullPath = '/' + obbDestPath + '/' + newObbFileName
print ' old:' + oldFileFullPath reameCmd = 'adb shell mv ' + oldFileFullPath + " " + newFileFullPath os.system(reameCmd)
print ' new:' + newFileFullPath print '\n' print ' (6)===============> Completed!!!' print '\n' exit()
指示:
python </path/obb_push.py> -p <app package name > -f </path/of/obbfile> -v <app version code>
やっと
今日あなたと共有したAndroidアプリケーションセットフォルダの削除はここにあります。私に同じようなものを与えたくありません。
もちろん、それを収集してゆっくりと学ぶことを忘れないでください。質問がある場合は、コメントすることを忘れないでください。メッセージを残して、見たら返信します。