• 大小: 0.02M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-05-11
  • 语言: Python
  • 标签: python  基础  常用  

资源简介

一些常用有用的python语句

资源截图

代码片段和文件信息

import subprocessre

back = 4
home = 3

def cmdexe(cmdtype=1):
    ‘‘‘执行cmd‘‘‘
    if type == 2:
        p = subprocess.Popen(cmd stdout=subprocess.PIPEshell=True)
    else:
        p = subprocess.Popen(cmd shell=True)
    p.communicate()

def get_cmdexe_result(cmd):
    ‘‘‘执行cmd并获取返回‘‘‘
    return str(subprocess.Popen(cmd stdout=subprocess.PIPEshell=True).stdout.read())

def screenshot(devicepath):
    cmd1 = ‘adb -s {0} shell /system/bin/screencap -p /sdcard/screenshot.png‘.format(device)
    cmd2 = ‘adb -s {0} pull /sdcard/screenshot.png {1}.png‘.format(device path)
    cmdexe(cmd12)
    cmdexe(cmd22)

def getWindowSize(device):
    cmd = ‘adb -s {0} shell dumpsys window displays‘.format(device)
    s = str(subprocess.Popen(cmd stdout=subprocess.PIPE shell=True).stdout.read())
    group_obj = re.search(r‘init=(\d*)x(\d*) ‘ s)

    return int(group_obj.group(2)) int(group_obj.group(1))

def startApp(devicepackagestartactivity):
    cmd = ‘adb -s {0} shell am start -W {1}/{2}‘.format(devicepackagestartactivity)
    cmdexe(cmd)

def closeApp(devicepackage):
    cmd = ‘adb -s {0} shell am force-stop {1}‘.format(devicepackage)
    cmdexe(cmd)

def sendkey(devicecode):
    cmd = ‘adb -s ‘+device+‘ shell input keyevent ‘+str(code)
    cmdexe(cmd)

def uninstall(devicepackage):
    cmd = ‘adb -s {0} uninstall {1}‘.format(devicepackage)
    cmdexe(cmd)

def tap_x_y(devicexy):
    cmd = ‘adb -s {0} shell input tap {1} {2}‘.format(device str(x) str(y))
    cmdexe(cmd)

def sendText(devicetext):
    cmd = ‘adb -s {0} shell input text {1}‘.format(device text)
    cmdexe(cmd)

def getCurActivity(device):
    cmd = ‘adb -s {0} shell dumpsys activity activities‘.format(device)
    return get_cmdexe_result(cmd)

def getSerialNo(device):
    cmd = ‘adb -s 172.16.17.11:3701 shell getprop ro.serialno‘
    return get_cmdexe_result(cmd).replace(“b‘“‘‘).replace(“\\r\\n‘“‘‘)

def getDeviceName():
    ‘‘‘
    获取连接电脑上的设备名
    ‘‘‘
    devices = []
    cmd = ‘adb devices‘
    s = get_cmdexe_result(cmd)
    for line in s.split(‘\\n‘):
        if ‘\\tdevice‘ in line:
            devices.append(line.split(‘\\tdevice‘)[0])
    return devices

def checkBackActivity(devicepackagestartactivity):
    ‘‘‘
    若当前app非指定app,则重新启动app
    ‘‘‘
    s = getCurActivity(device)
    groupObj = re.search(r‘mFocusedActivity: ActivityRecord{(.+)mFocusedStack‘s)
    if not package in groupObj.group(1):
        startApp(devicepackagestartactivity)

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-04-29 02:46  python_util\
     文件         453  2020-04-29 02:46  python_util\OrderedDict1.py
     文件        2544  2020-04-29 02:46  python_util\adbutils.py
     文件         335  2020-04-29 02:46  python_util\beautifulsoup1.py
     文件         298  2020-04-29 02:46  python_util\csv1.py
     文件         120  2020-04-29 02:46  python_util\deco1.py
     文件          56  2020-04-29 02:46  python_util\dict1.py
     文件         455  2020-04-29 02:46  python_util\elasticsearch1.py
     文件          64  2020-04-29 02:46  python_util\encode_issue.py
     文件        1372  2020-04-29 02:46  python_util\excelstyle.py
     文件         487  2020-04-29 02:46  python_util\excelread.py
     文件         540  2020-04-29 02:46  python_util\excelwrite.py
     文件         983  2020-04-29 02:46  python_util\flask1.py
     文件        1703  2020-04-29 02:46  python_util\ftplib1.py
     文件         191  2020-04-29 02:46  python_util\getUrlFile.py
     文件         264  2020-04-29 02:46  python_util\json1.py
     文件         229  2020-04-29 02:46  python_util\log1.py
     文件         181  2020-04-29 02:46  python_util\md51.py
     文件         755  2020-04-29 02:46  python_util\mysql1.py
     文件         349  2020-04-29 02:46  python_util\operator1.py
     文件         142  2020-04-29 02:46  python_util\os1.py
     文件        1821  2020-04-29 02:46  python_util\pandas1.py
     文件        1068  2020-04-29 02:46  python_util\pil1.py
     文件        2152  2020-04-29 02:46  python_util\proxy11.py
     文件         911  2020-04-29 02:46  python_util\pymongo1.py
     文件         363  2020-04-29 02:46  python_util\random1.py
     文件         215  2020-04-29 02:46  python_util\redis1.py
     文件        1508  2020-04-29 02:46  python_util\sendmail.py
     文件        1000  2020-04-29 02:46  python_util\soap_server.py
     文件         262  2020-04-29 02:46  python_util\subprocess1.py
     文件         114  2020-04-29 02:46  python_util\sys1.py
............此处省略6个文件信息

评论

共有 条评论