TookDES產品BUG報告生成器 v1.0G 源代碼探討

TookDES產品BUG報告生成器 v1.0G採用了easygui來製作簡單的GUI程序。代碼非常簡單,能做的工作也不多。主要是一個探討。




一開始我想使用wxpython作爲GUI庫,當時想用下拉菜單,無論如何實現不好那個和事件驅動的綁定,我果然是弱爆了……

之後就想到用tkinter,結果覺得功能有點弱,自己又怕麻煩…於是上網一搜,就找到了easygui,照着範例一做,嘿,成了。


源代碼如下:

#!usr/bin/env python
# -*- coding: utf-8 -*-

import sys 
reload(sys) 
sys.setdefaultencoding('utf8') 

from easygui import *

global product1
product1 = ""
global product2
product2 = ""
global product3
product3 = ""
global product
global bugdes
global seriousness
global personinfor
global bug
global attachment

def productchoose():
    msg = "請選擇TookDES產品:(按名稱排序)"
    title = "TookDES產品BUG報告生成器 v1.0G"
    choices = ["Tookubuntu", "TookDroid", "TookBlog", "TookCode",
               "TookSUSE", "Windows FLP for VirtualBox", "GAPPS for TookDroid",
               "njit8021xclient", "定製版Android APK程序","TookDroid x86",
               "Tookubuntu字體", "Tookubuntu yong輸入法","卡爾改鍵",
               "TookDES產品BUG報告生成器"]
    global product1
    product1 = choicebox(msg, title, choices)

def tookubuntu():
    msg = "請選擇Tookubuntu版本:"
    title = "Tookubuntu系列操作系統"
    choices = ["TooKubuntu 3.0", "Tookubuntux 1.0", "Tookubuntu 2.4 LTS",
               "Tookubuntu for VNC"]
    global product2
    product2 = choicebox(msg, title, choices)

def tookdroid():
    msg = "請選擇TookDroid支持的設備:"
    title = "TookDroid系列Android ROM"
    choices = ["HTC Desire", "HTC Desire S", "HTC Desire Z",
               "HTC DROID Incredible 2", "HTC EVO 3D GSM",
               "HTC HD2", "HTC Touch Diamond", "Malata Zpad T8 (WCDMA)",
               "Motorola Milestone"]
    global product2
    product2 = choicebox(msg, title, choices)
    global product3
    product3 = enterbox('''請輸入詳細版本號,如“v1.0I”''', "TookDroid詳細版本號",)

def tookblog():
    msg = "請選擇Tookblog版本:"
    title = "TookBlog程序"
    choices = ["Windows Phone 7", "Android"]
    global product2
    product2 = choicebox(msg, title, choices)

def GAPPS():
    msg = "請選擇GAPPS for TookDroid版本:"
    title = "TookDroid的Google服務套件"
    choices = ["Android 2.3.4~2.3.5", "Android 2.3.7"
               ,"Android 4.0.3~4.0.4"]
    global product2
    product2 = choicebox(msg, title, choices)

def njit8021xclient():
    msg = "請選擇njit8021xclient版本:"
    title = "H3C iNode 802.1X Linux操作系統第三方客戶端"
    choices = ["openWRT on ar71xx", "openWRT on brcm47xx/53xx",
               "openWRT on Tp-Link WR941ND"]
    global product2
    product2 = choicebox(msg, title, choices)

def APK():
    msg = "請選擇修改版的APK程序:"
    title = "TookDES修改或漢化後的APK程序"
    choices = ["gReader Pro", "Blogger", "ODF閱讀器", "Verizon Opera Mini",
               "一鍵鎖屏"]
    global product2
    product2 = choicebox(msg, title, choices)

def bugger():
    msg = "請選擇產品BUG報告生成器版本:"
    title = "TookDES產品BUG報告生成器"
    choices = ["GUI版本(版本號爲G字母結尾,圖形模式)",
               "CUI版本(版本號爲C字母結尾,終端模式)"]
    global product2
    product2 = choicebox(msg, title, choices)

def person():
    msg = "請填入個人信息,以方便我們聯繫:"
    title = "個人信息"
    fieldNames  = ["姓名/代稱","電子郵件","手機號碼"]
    fieldValues = []
    global personinfor
    personinfor = multenterbox(msg, title, fieldNames)
    if personinfor == "":
        personinfor = "匿名"

def bugdescrible():
    global bugdes
    bugdes = textbox('''
請粘貼(而不是在此輸入,因爲沒有自動保存功能)詳細的BUG描述,如:

1.產生的步驟
2.問題的表現
3.希望的改進
4.錯誤日誌文本''', "BUG描述")

def seriousnesschoose():
    msg = "請評估BUG的嚴重程度,這將有利於對BUG的處理:"
    title = "BUG嚴重程度"
    choices = ["高","中","低"]
    global seriousness
    seriousness = buttonbox(msg, title=title, choices=choices)

def desbugreport():
    global product1
    global product2
    global product3
    global bug
    global product
    global bugdes
    global seriousness
    global attachment
    productchoose()
    if product1 == "Tookubuntu":
        tookubuntu()
    elif product1 == "TookDroid":
        tookdroid()
    elif product1 == "TookBlog":
        tookblog()
    elif product1 == "njit8021xclient":
        njit8021xclient()
    elif product1 == "定製版Android APK程序":
        APK()
    elif product1 == "GAPPS for TookDroid":
        GAPPS()
    elif product1 == "":
        sys.exit("用戶未實現有效選擇,程序退出")
    else:
        pass
    bugdescrible()
    seriousnesschoose()
    person()

def txt():
    global product1
    global product2
    global product3
    global product
    global bugdes
    global seriousness
    global personinfor
    text = "【TookDES產品】\n\n"+product1+","+product2+","+product3\
           +"\n\n【BUG詳情】\n\n"+bugdes+"\n【嚴重程度】\n\n"+seriousness+\
           "\n\n【聯繫信息】\n\n"+str(personinfor[0])+"\n"+str(personinfor[1])\
           +"\n"+str(personinfor[2])
    codebox('''
請複製下面的所有內容(鼠標拖動,再按鍵盤Ctrl+C),發送郵件至[email protected]。
你可以在郵件中附上截圖等文件,此郵箱接收上限爲20M大小。

感謝使用TookDES產品BUG收集器!''', "", text)
    
if __name__ == '__main__':
    desbugreport()
    txt()


探討:


未完成的tkinter代碼:

#!usr/bin/env python
# -*- coding: utf-8 -*-

from Tkinter import *
import ttk

window = Tk()
window.title("TookDES產品BUG提交工具")   

frame1 = Frame(window, borderwidth=2, relief=GROOVE)
#告訴Tk,如果主窗口調整大小,框架應該擴展來佔據額外的空間。
frame1.columnconfigure(0,weight=1)

Ver = StringVar()
Dev = StringVar()

label1 = Label(frame1, text="產品名稱:").grid(row=0,column=0)
chos1 = ttk.Combobox(frame1,values=["Tookbuntu", "TookSUSE", "TookDroid",
                                    "TookCode", "TookBlog", "Windows FLP"
                                    ]).grid(row=0,column=1)
label2 = Label(frame1, text="產品版本:").grid(row=0,column=2)
entry = Entry(frame1, textvariable=Ver).grid(row=0,column=3)
label2 = Label(frame1, text="設備型號:").grid(row=0,column=4)
entry = Entry(frame1, textvariable=Dev).grid(row=0,column=5)

frame1.pack()

frame2 = Frame(window, borderwidth=2, relief=GROOVE)
frame2.columnconfigure(0,weight=1)
label2 = Label(frame2, text="BUG詳述:").pack(side="left")
text = Text(frame2, height=10, width=72).pack()

frame2.pack()
window.mainloop()


未完成的CUI版本代碼:

#!usr/bin/env python
# -*- coding: utf-8 -*-

print '''TookDES產品BUG提交工具 CUI版 v1.0


請輸入產品名稱序號,或直接輸入產品名:

1.Tookubuntu
2.TookDroid
3.TookBlog
4.TookCode
5.TookSUSE
6.Windows FLP

'''

tdes = raw_input()

if tdes == "1":
    print '''

請選擇產品版本序號,或直接輸入產品版本:

1.TooKubuntu 3.0
2.TookUbuntu 2.4 LTS
3.Tookubuntux 1.0

'''

    tu = raw_input()
    if tu == "1":
        pro = "Tookubuntu 3.0"
    elif tu == "2":
        pro = "TookUbuntu 2.4 LTS"
    elif tu == "3":
        pro = "TookUbuntux 1.0"
    else:
        pro = tu

elif tdes == "2":
    print '''

請選擇適配機型:

1.HTC 


本來還想直接用電子郵件發過去的,但是不知道爲什麼,可能網易不讓直接這樣連接發送了吧:

#!usr/bin/env python
# -*- coding: utf-8 -*-

import sys 
reload(sys) 
sys.setdefaultencoding('utf8') 

from easygui import *
import smtplib
import email.MIMEMultipart
import email.MIMEBase
import os.path

global product1
product1 = ""
global product2
product2 = ""
global product3
product3 = ""
global product
global bugdes
global seriousness

global bug
global attachment

def productchoose():
    msg = "請選擇TookDES產品:(按名稱排序)"
    title = "TookDES產品BUG提交工具 GUI版本 v1.0"
    choices = ["Tookubuntu", "TookDroid", "TookBlog", "TookCode",
               "TookSUSE", "Windows FLP for VirtualBox", "GAPPS for TookDroid",
               "njit8021xclient", "定製版Android APK程序","TookDroid x86",
               "Tookubuntu字體", "Tookubuntu yong輸入法","卡爾改鍵"]
    global product1
    product1 = choicebox(msg, title, choices)

def tookubuntu():
    msg = "請選擇Tookubuntu版本:"
    title = "Tookubuntu系列操作系統"
    choices = ["TooKubuntu 3.0", "Tookubuntux 1.0", "Tookubuntu 2.4 LTS",
               "Tookubuntu for VNC"]
    global product2
    product2 = choicebox(msg, title, choices)

def tookdroid():
    msg = "請選擇TookDroid支持的設備:"
    title = "TookDroid系列Android ROM"
    choices = ["HTC Desire", "HTC Desire S", "HTC Desire Z",
               "HTC DROID Incredible 2", "HTC EVO 3D GSM",
               "HTC HD2", "HTC Touch Diamond", "Malata Zpad T8 (WCDMA)",
               "Motorola Milestone"]
    global product2
    product2 = choicebox(msg, title, choices)
    global product3
    product3 = enterbox('''請輸入詳細版本號,如“v1.0I”''', "TookDroid詳細版本號",)

##def tookdroidx86:
##    msg = "請選擇TookDroid x86支持的設備:"
##    title = "TookDroid x86系列"
##    choices = ["Virtualbox"]
##    choic = choicebox(msg, title, choices)

def tookblog():
    msg = "請選擇Tookblog版本:"
    title = "TookBlog程序"
    choices = ["Windows Phone 7", "Android"]
    global product2
    product2 = choicebox(msg, title, choices)

def GAPPS():
    msg = "請選擇GAPPS for TookDroid版本:"
    title = "TookDroid的Google服務套件"
    choices = ["Android 2.3.4~2.3.5", "Android 2.3.7"
               ,"Android 4.0.3~4.0.4"]
    global product2
    product2 = choicebox(msg, title, choices)

def njit8021xclient():
    msg = "請選擇njit8021xclient版本:"
    title = "H3C iNode 802.1X Linux操作系統第三方客戶端"
    choices = ["openWRT on ar71xx", "openWRT on brcm47xx/53xx",
               "openWRT on Tp-Link WR941ND"]
    global product2
    product2 = choicebox(msg, title, choices)

def APK():
    msg = "請選擇修改版的APK程序:"
    title = "TookDES修改或漢化後的APK程序"
    choices = ["gReader Pro", "Blogger", "ODF閱讀器", "Verizon Opera Mini",
               "一鍵鎖屏"]
    global product2
    product2 = choicebox(msg, title, choices)

def productensure():
    msg = "請修改確認以下信息是否無誤:"
    title = "產品信息最終確認"
    fieldNames  = ["產品名","版本號","次級版本號"]
    fieldValues = [product1, product2, product3]
    global product
    product = multenterbox(msg, title, fieldNames)

def bugdescrible():
    global bugdes
    bugdes = textbox('''
請粘貼(而不是在此輸入,因爲沒有自動保存功能)詳細的BUG描述,如:

1.產生的步驟
2.問題的表現
3.希望的改進
4.您的電子郵件地址''', "BUG描述")

def attachmentadd():
    if ccbox("如果有附件(如截圖、錯誤日誌),請將它們壓縮打包爲一個文件,然後選擇:",
             "附件"):
        global attachment
        attachment = fileopenbox()
    else: 
        pass

def seriousnesschoose():
    msg = "請評估BUG的嚴重程度,這將有利於對BUG的處理:"
    title = "BUG嚴重程度"
    choices = ["高","中","低"]
    global seriousness
    seriousness = buttonbox(msg, title=title, choices=choices)

def desbugreport():
    global product1
    global product2
    global product3
    global bug
    global product
    global bugdes
    global seriousness
    global attachment
    productchoose()
    if product1 == "Tookubuntu":
        tookubuntu()
    elif product1 == "TookDroid":
        tookdroid()
    elif product1 == "TookBlog":
        tookblog()
    elif product1 == "njit8021xclient":
        njit8021xclient()
    elif product1 == "定製版Android APK程序":
        APK()
    elif product1 == "GAPPS for TookDroid":
        GAPPS()
    elif product1 == "":
        sys.exit("用戶未實現有效選擇,程序退出")
    else:
        pass
    bugdescrible()
    attachmentadd()
    seriousnesschoose()
    productensure()
    bug = product + bugdes + seriousness
    print product1
    print product2
    print product3
    print product
    print bugdes
    print seriousness
    print bug
    print attachment

def sendemail():
    global bug
    global attachment
    if ccbox("即將發送報告,請確認", "確認發送"):
        smtpsvr = 'smtp.126.com'
        name = ''
        from_ = ''
        pw = ''
        blogmail = '[email protected]'
        contype = 'application/octet-stream'
        maintype, subtype = contype.split('/', 1)#構造文件附件內容容器
        data = open(attachment, 'rb')
        file_msg = email.MIMEBase.MIMEBase(maintype, subtype)
        file_msg.set_payload(data.read( ))
        data.close( )
        email.Encoders.encode_base64(file_msg)#讀取並格式化
        basename = os.path.basename(attachment)
        file_msg.add_header('Content-Disposition',
                            'attachment', filename = basename)#設置附件頭
        origBody = file_msg.as_string() + bug
        origHdrs = ['From:'+from_, 'To:'+blogmail,
                    'Subject:'+"TookDES BUG報告 by GUI版 v1.0"]
        origMsg = '\r\n\r\n'.join(['\r\n'.join(origHdrs),
                                       '\r\n'.join(origBody)])
        sendSvr = SMTP(smtpsvr)
        sendSvr.login(name,pw)
        errs = sendSvr.sendmail(from_, blogmail, origMsg)
        sendSvr.quit()
    else:
        sys.exit("用戶取消發送,程序退出")
    
if __name__ == '__main__':
    desbugreport()
    sendemail()
    


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章