• 工作笔记--Python自动切换host


    修改host代码:

    #coding:utf-8
    import os,time

    pwd = os.path.dirname(__file__) #获取当前文件夹的绝对路径
    pull_host_cmd = 'adb pull system/etc/hosts '+pwd
    push_host_cmd = 'adb push '+pwd+'hosts system/etc/'

    os.popen('adb root')
    temp = os.popen('adb remount')

    print 'Pull hosts..'
    temp = os.popen(pull_host_cmd)
    temp = temp.readline().split()

    #读取配置文件
    config_path = os.path.join(pwd, 'config.txt') #获取当前文件夹内的config文件
    config_file = open(config_path, "r") #读取文件

    #写追加方式打开host文件
    host_path = os.path.join(pwd,'hosts')
    host_file = open(host_path,"a+")

    for line in config_file:
    host_file.write(line)

    config_file.close() #关闭文件
    host_file.close()

    #push hosts
    temp = os.popen(push_host_cmd)
    temp = temp.readline().split()
    temp = os.system('del hosts')

    重置到localhost的代码:
    #coding:utf-8
    import os,time

    pwd = os.path.dirname(__file__) #获取当前文件夹的绝对路径
    pull_host_cmd = 'adb pull system/etc/hosts '+pwd
    push_host_cmd = 'adb push '+pwd+'hosts system/etc/'

    temp = os.popen(pull_host_cmd)
    temp = temp.readline().split()

    host_path = os.path.join(pwd,'hosts')
    host_file = open(host_path,"wb")

    host_file.write('127.0.0.1 localhost ')
    host_file.close()
    os.system('adb push hosts system/etc/hosts')
    os.system('del hosts')

    Project目录:

     

    
    
  • 相关阅读:
    第二阶段站立会议第三天
    第二阶段站立会议第二天
    第二阶段站立会议第一天
    测试计划
    cnblogs用户体验及建议
    第一阶段绩效评估
    第一阶段各组意见回复
    第一阶段团队评价
    站立会议第十天
    站立会议第九天
  • 原文地址:https://www.cnblogs.com/ailiailan/p/7919470.html
Copyright © 2020-2023  润新知