python删除Android应用及文件夹,就说牛不牛吧
写在前面的一些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()
使用方法:
- 打开terminal
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应用集文件夹到这里就结束了,这不得给我一个赞~
当然,记得收藏起来慢慢学习,有问题的小伙伴记得评论留言,我看见都会回复的。
python删除Android应用及文件夹,就说牛不牛吧的更多相关文章
- 为什么 Android Studio 工程文件夹占用空间这么大?我们来给它减减肥
偶然中发现Android Studio的工程文件夹比ADT Bundle的大很多.用Android Studio新建一个空工程,工程文件夹大小为30M,运行一次后大小为40M.同样用ADT Bundl ...
- Android 项目中文件夹的说明与作用(转)
(转自:http://blog.csdn.net/goodshot/article/details/11529731) Android 项目中文件夹的作用 1. src:存放所有的*.java源程序. ...
- python之对指定目录文件夹的批量重命名
python之对指定目录文件夹的批量重命名 import os,shutil,string dir = "/Users/lee0oo0/Documents/python/test" ...
- [转载]删除所有的.svn文件夹
Windows 下,在DOS窗口中运行如下命令 dos 代码 for /r <你项目的路径> %i in (.svn) do rd /s /q %i Linux 下,可以先运行 显示出当前 ...
- 用Python来实现列举某个文件夹内所有的文件列表
用Python来实现列举某个文件夹内所有的文件列表.吾八哥我动手写代码之前分析了下,遍历一个文件夹,肯定是需要用到os模块了,查阅模块帮助信息,可知os.listdir()方法可以列举某个文件夹内的所 ...
- 用bat批处理程序通过DOS命令行删除所有的空文件夹
用过gothub或者码云的同学都知道,不包含任何文件的空文件夹上传提交时不被允许的.当然你可以在空文件下创建.keep文件(或.gitkeep文件),然后就可以上传了. 但是如果空文件夹比较多,并且我 ...
- window下删除所有带.svn文件夹及文件,删除所有的.svn文件夹
(一)------------------------------------------------------------------------------------------------- ...
- Android Studio:layout-sw600dp文件夹中创建activity_main.xml
1.右键res文件夹,新建Android resource directory文件夹 2.在resource type中选择layout 3.将Directory name命名为layout-sw6 ...
- 为什么 Android Studio 工程文件夹占用空间这么大?
为什么 Android Studio 工程文件夹占用空间这么大? 学习了: https://www.cnblogs.com/chengyujia/p/5791002.html
随机推荐
- JavaScript学习②
2. 基本对象: 1. Function:函数(方法)对象 1. 创建: 1. var fun = new Function(形式参数列表,方法体); //忘掉吧 2. function 方法名称(形 ...
- SIP信令跟踪工具HOMER
概述 HOMER是一款100%开源的针对SIP/VOIP/RTC的抓包工具和监控工具. HOMER是一款强大的.运营商级.可扩展的数据包和事件捕获系统,是基于HEP/EEP协议的VoIP/RTC监控应 ...
- docker入门_docker安装
docker入门_docker安装 ubuntu 安装 curl -sSL https://get.daocloud.io/docker | sh # 官方安装脚本自动安装 systemctl ena ...
- Android四大组件——Activity——Activity之间通信下
显式意图:一般是用于应用内组件跳转.(如从ActivityA跳转到ActivityB) 隐式意图:一半用于应用之间的跳转.(如从ActivityA跳转到拨号) 隐式意图跳转到百度: 只需将前面Main ...
- HTML中的Hack手段之条件注释
通常WEB的好处就是可以跨平台,但这个世界偏偏有个另类,就是IE浏览器.在平常做HTML设计时,有时需要为IE的表示差异而不得不使用一些Hack手段.条件注释就是这类手段之一. 条件注释是IE浏览器的 ...
- 事务的隔离级别与MVCC
提到数据库,你多半会联想到事务,进而还可能想起曾经背得滚瓜乱熟的ACID,不知道你有没有想过这个问题,事务有原子性.隔离性.一致性和持久性四大特性,为什么偏偏给隔离性设置了级别? 一切还得从事务说起. ...
- MySQL进阶之常用函数
我的小站 有时候,除了简单的数据查询,我们还有一些高级的函数. MySQL 包含了大量并且丰富的函数,这套 MySQL 函数大全只收集了几十个常用的,剩下的比较罕见的函数我们就不再整理了,读者可以到M ...
- 漏洞复现:MS12-020 远程桌面协议RDP远程代码执行漏洞
漏洞复现:MS12-020 远程桌面协议RDP远程代码执行漏洞 攻击机:Kali2019 靶机:Win7 64位 解题步骤: 1.打开Kali2019和Win7 64位 ,确定IP地址是多少 2.确定 ...
- 快速了解Spring,简明Spring使用流程
前言: 注意题目,这篇文章说的是操作,也就是重在应用,更多的是一个入门的或者说一篇概览,所以大佬们多多担待,不涉及底层分析和很多的源码,所以如果看官想看以上两者的可以划走了,有时间又不懒的话,可能以后 ...
- C++进阶-3-5-list容器
C++进阶-3-5-list容器 1 #include<iostream> 2 #include<list> 3 #include<algorithm> 4 usi ...