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
随机推荐
- nodejs mysql pool 只能插入10条记录或者较少记录
BEGIN; 解决方案:从连接池获取到的Connection,执行完操作后,必须及时关闭! 即:connection.end(); 使用后发现console有打印出警告信息,大致意思为 end() 方 ...
- WebSocket 协议详解
一.WebSocket 协议背景 早期,在网站上推送消息给用户,只能通过轮询的方式或 Comet 技术.轮询就是浏览器每隔几秒钟向服务端发送 HTTP 请求,然后服务端返回消息给客户端. 轮询技术一般 ...
- 为何数据库连接池不采用IO多路复用?
今天我们聊一个不常见的 Java 面试题:为什么数据库连接池不采用 IO 多路复用? 这是一个非常好的问题.IO多路复用被视为是非常好的性能助力器.但是一般我们在使用 DB 时,还是经常性采用c3 ...
- Halo 开源项目学习(二):实体类与数据表
基本介绍 Halo 项目中定义了一些实体类,用于存储博客中的关键数据,如用户信息.文章信息等.在深入学习 Halo 的设计理念与实现过程之前,不妨先学习一下一个完整的博客系统都由哪些元素组成. 实体类 ...
- python学习-Day37
目录 今日内容详细 GIL全局解释器锁 GIL与普通互斥锁区别 GIL对程序的影响 验证多线程作用 两个大前提 关于CPU的个数 关于任务的类型 死锁现象 避免死锁的解决: 添加超时释放锁 信号量 自 ...
- 一款高速的NET版的离线免费OCR
PaddleOCR.Onnx 一款基于Paddle的OCR,项目使用ONNX模型,速度更快.本项目同时支持X64和X86的CPU上使用.本项目是一个基于PaddleOCR的C++代码修改并封装的.NE ...
- python网络自动化ncclient模块,netconf协议检索与下发交换机配置
以juniper和华为设备为例 交换机必要配置,配置简单,使用ssh模式传输 #juniperset system services netconf ssh#华为 local-user netconf ...
- unity---克隆/贴图/平移/旋转
克隆 GameObject clone =Instantiate(gameObject,new Vector3(10,10,10),Quaternion.identity); Destroy(clon ...
- Go到底能不能实现安全的双检锁?
不安全的双检锁 从其他语言转入Go语言的同学经常会陷入一个思考:如何创建一个单例? 有些同学可能会把其它语言中的双检锁模式移植过来,双检锁模式也称为懒汉模式,首次用到的时候才创建实例.大部分人首次用G ...
- MOS管实现的STC自动下载电路
目录 MOSFET, MOS管基础和电路 MOS管实现的STC自动下载电路 三极管配合 PMOS 管控制电路开关 STC MCU在烧录时, 需要断电重置后才能进入烧录状态, 通常是用手按开关比较繁琐. ...