push多张照片至Android手机

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

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

使用语言:python 2.7

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

import os

# 1.push photos
for 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 phone
cmd2 = "adb shell reboot"
os.system(cmd2)

# 3.delete pushed photos
for 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 photos
for 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 phone
cmd2 = "adb shell reboot"
os.popen(cmd2)

# 3.delete pushed photos
for 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 photos
for 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 phone
subprocess.call("adb shell reboot")


# 3.delete pushed photos
for j in range(1, 3):
    returnDelete = subprocess.call("adb shell rm -r /sdcard/DCIM/Camera/{}.jpg".format(j))
    assert returnDelete == 0

你可能感兴趣的:(测试)