cmd 指令

#!D:\Python27\python.exe


import wx
import subprocess




def ShowLog(text = "..."):
    dlg = wx.TextEntryDialog(None, text)
    if dlg.ShowModal() == wx.ID_OK:
        res = dlg.GetValue
        print (res)


class TextFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"Write SSID Tool",size=(300,250))
        panel = wx.Panel(self,-1)
        self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"


        self.basicLabel = wx.StaticText(panel, -1, "...", pos=(100, 10))
        basicLabel = wx.StaticText(panel,-1,"SSID:",pos=(65,50))
        self.basicText  = wx.TextCtrl(panel,-1,"Input ssid...",pos=(100,50),size=(175,-1))
        button = wx.Button(panel,label="Write",pos=(100,80),size=(175,-1))
        self.Bind(wx.EVT_BUTTON,self.OnWriteSsid,button)


        #radio button
        radio1 = wx.RadioButton(panel,-1,"cache",pos=(100,120),style=wx.RB_GROUP)
        radio2 = wx.RadioButton(panel,-1,"data",pos=(100,140))
        for rad in [radio1,radio2]:
            self.Bind(wx.EVT_RADIOBUTTON,self.onRadio,rad)
        
        #
        self.GETERR  = "Execution cmd fail!"
        self.GETSUCC = "Cmd run success,not return code!"
        self.GETRET  = "get return code"




    def onRadio(self,event):
        radioselect = event.GetEventObject()
        seltext = radioselect.GetLabel()
        print seltext
        if ("cache" == seltext):
            self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"


        self.strSSIDFilePath = "/data/pv_wifi_switch_ssid.cfg"
            


    def MySendCmdFun(self,strCmd):        
        pipe = subprocess.Popen(strCmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
        print strCmd
        if (-1 == pipe.wait()):
            print 'write cmd fail!'
            return self.GETERR
        elif 0 == pipe.returncode:
            ret = pipe.stdout.read()
            print "stdout.read:",ret
            if (0 == len(ret)):
                return self.GETSUCC
            return ret        
       
        return self.GETSUCC




    def OnWriteSsid(self,event):
        self.basicLabel.SetLabel("...")        
        ssidline = self.basicText.GetValue()
        if "Input ssid..." == ssidline:
            self.basicLabel.SetLabel("None input...")
            return;


        WriteCmd = 'adb shell \"echo -n %s > %s\"' % (ssidline,self.strSSIDFilePath)
        #WriteCmd = "adb shell cat /cache/pv_wifi_switch_ssid.cfg"
        #Write cmd
        print "begin write..."
        ret = self.MySendCmdFun(WriteCmd)       
        if self.GETSUCC != ret:
            self.basicLabel.SetOwnForegroundColour("Red")
            self.basicLabel.SetLabel(ret)
            return
        
        #check data
        getdat = "adb shell cat %s" % self.strSSIDFilePath
        ret = self.MySendCmdFun(getdat)        
        if (ssidline != ret):
            self.basicLabel.SetOwnForegroundColour("Red")
            self.basicLabel.SetLabel(ret)
            return


        self.basicLabel.SetOwnForegroundColour("Blue")
        self.basicLabel.SetLabel("Write success")


if __name__ == '__main__':
    app = wx.PySimpleApp();
    frame = TextFrame()
    frame.Show()
    app.MainLoop()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值