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
随机推荐
- AngularJS ui-router 用resolve、service预先加载数据写法,属于优化性能方面吧
AngularJS的service怎么声明此处就不再赘述,下面的例子是ui-router中使用service的实现代码 $stateProvider.state('myState', { url: & ...
- 09. 树莓派ASP.NET环境配置
在树莓派上部署ASP.NET环境(树莓派做ASP.NET项目服务器),之后Windows上开发的ASP.NET项目可以部署在树莓派上.配置过程如下: 前言:本篇文章内容是根据mono官网上查阅的配置教 ...
- web前端 在 iOS下 input不能输入 以及获取焦点之后会出现蓝色的border轮廓
iOS下 input 不能获取焦点 获取焦点后:设置border:none无效果 .hb_content input{ display: inline-block; margin-left: 0.22 ...
- Halo 开源项目学习(五):评论与点赞
基本介绍 博客系统中,用户浏览文章时可以在文章下方发表自己的观点,与博主或其他用户进行互动,也可以为喜欢的文章点赞.下面我们一起分析一下 Halo 项目中评论和点赞功能的实现过程. 发表评论 评论可以 ...
- 深入理解mmap--内核代码分析及驱动demo示例
mmap是一个很常用的系统调用,无论是分配内存.读写大文件.链接动态库文件,还是多进程间共享内存,都可以看到其身影.本文首先介绍了进程地址空间和mmap,然后分析了内核代码以了解其实现,最后通过一个简 ...
- SpringJdbcTemplate简单实现
SpringJdbcTemplate 配置文件 1.依赖坐标 <dependencies> <dependency> <groupId>javax.servlet& ...
- 『现学现忘』Git基础 — 23、Git中的撤销操作
目录 1.撤销操作说明 2.撤销工作区中文件的修改 3.撤销暂存区中文件的修改 4.总结 1.撤销操作说明 我们在使用Git版本管理时,往往需要撤销某些操作.比如说我们想将某个修改后的文件撤销到上一个 ...
- Web安全学习笔记 SQL注入上
Web安全学习笔记 SQL注入上 繁枝插云欣 --ICML8 SQL注入分类 SQL注入检测 一.注入分类 1.简介 SQL注入是一种代码注入技术用于攻击数据驱动的应用程序在应用程序中,如果没有做恰当 ...
- 167. Two Sum II - Input array is sorted - LeetCode
Question 167. Two Sum II - Input array is sorted Solution 题目大意:和Two Sum一样,这里给出的数组是有序的 思路:target - nu ...
- 关于ECharts图表反复修改都无法显示的解决方案
解决方案:清空浏览器所有记录,再次刷新即可