push多张照片至Android手机

来源:互联网 发布:网络研修 编辑:程序博客网 时间:2024/05/02 04:54

任务需求:往android手机中push多张照片

功能:
1、push照片
2、重启手机
3、删除push照片

使用语言:python 2.7

知识点
Python执行系统命令,os.system && os.popen && subprocess.Popen
1、os.system实现

import os# 1.push photosfor i in range(1, 1001):    cmd1 = "adb push D:\\test\\1.jpg /sdcard/DCIM/Camera/{}.jpg".format(i)    os.system(cmd1)    print i# 2.finish push and reboot the phonecmd2 = "adb shell reboot"os.system(cmd2)# 3.delete pushed photosfor j in range(1, 1001):    cmd3 = " adb shell rm -r /sdcard/DCIM/Camera/{}.jpg".format(j)    os.system(cmd3)    print j

2、os.popen 实现

import os# 1.push photosfor i in range(1, 1001):    cmd1 = "adb push D:\\test\\1.jpg /sdcard/DCIM/Camera/{}.jpg".format(i)    # print cmd1    os.popen(cmd1)    print i# 2.finish push and reboot the phonecmd2 = "adb shell reboot"os.popen(cmd2)# 3.delete pushed photosfor j in range(1, 1001):    cmd3 = " adb shell rm -r /sdcard/DCIM/Camera/{}.jpg".format(j)    os.popen(cmd3)    print cmd3

3、subprocess.Popen实现

import subprocess# 1.push photosfor i in range(1, 3):    returnCode = subprocess.call("adb push D:\\test\\1.jpg /sdcard/DCIM/Camera/{}.jpg".format(i))    assert returnCode == 0    print i# 2.finish push and reboot the phonesubprocess.call("adb shell reboot")# 3.delete pushed photosfor j in range(1, 3):    returnDelete = subprocess.call("adb shell rm -r /sdcard/DCIM/Camera/{}.jpg".format(j))    assert returnDelete == 0
原创粉丝点击