class RootWindow(tk.Tk):
    newthread = False
    scan_running = False
    automate_running = False
    commit_track_list = []

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.build_window()

    def build_window(self):
        # Build the Notebook widget
        self.notebook = ttk.Notebook(self)
        tab1 = ttk.Frame(self.notebook)
        tab2 = ttk.Frame(self.notebook)
        tab3 = ttk.Frame(self.notebook)
        self.results_tab = tab3
        tab4 = ttk.Frame(self.notebook)
        self.notebook.add(tab1, text="Welcome")
        self.notebook.add(tab2, text="Parser")
        self.notebook.add(tab3, text="Results")
        self.notebook.add(tab4, text="Hosting")
        self.notebook.pack(fill="both", expand=True)

        # Populate tab1
        t1_frm1 = ttk.Frame(tab1)
        t1_frm2 = ttk.Frame(tab1)
        t1_frm3 = ttk.Frame(tab1)
        t1_frm4 = ttk.Frame(tab1)
        t1_frm5 = ttk.Frame(tab1)
        t1_label1 = ttk.Label(
            t1_frm1,
            text=
            "Welcome to the Webkit Bug Finder. This program will parse a WebKit SVN changelog and find all bugs that are\n\
restricted from public view. It stores the changelog information for each bug into a database so that the\n\
program can show you each bug and its associated committ log. Most of these will contain details about\n\
what triggers the bug. Many will also contain layout test paths to trigger the bug. These layout tests are\n\
contained in your updated local WebKit repo and can be hosted by this program using the hosting tab above.\n\
Once hosted, you can navigate your WebKit based browser to your_IP_address:8000 to see if the browser is\n\
affected by the bug. This is how it works:\n\n\
\n1: Update your local copy of WebKit repo by running Tools" + dir_slash +
            "Scripts" + dir_slash + "update-webkit\n\n\
2: You will need to have Subversion installed and obtain a svn changelog by navigating\n\
    to the root of your WebKit directory and running: svn log > any_filename.txt\n\n\
3: Once you have the svn changelog, you can parse and scan it following the instructions\n\
    in the parser tab. If this is the first time running the program, a new database will be\n\
    generated. If you already have a database, it will be updated each time you repeat this\n\
    process. Once a scan has completed it can take a while to write the results to the database.\n\
    You will see a 'Done' message in the terminal window when it has completed. "
        ).pack(side='left', padx=5, pady=10)

        t1_label2 = ttk.Label(
            t1_frm2,
            text=
            "If you are running linux, have Subversion installed and have WebKit installed @ usershome/WebKit/\nthen the following 3 buttons will work. Automate will try to automate the entire process.\nThat is, update webkit, get a WebKit svn log, parse said log, scan for restricted bugs and switch\nyou to the results views. Throttle and Stop Date values will be obtained from the Parser tab. Change the values there prior to\nproceeding with the automation. This could take a while..."
        ).pack(side='left', padx=5, pady=10)

        self.updt_wbkt_btn = ttk.Button(t1_frm3,
                                        text="Update WebKit",
                                        width=12,
                                        command=self.updt_wbkt_clicked).pack()
        self.get_svnlog_btn = ttk.Button(
            t1_frm4,
            text="Get Svn Log",
            width=12,
            command=self.get_svnlog_clicked).pack()
        self.automate_btn = ttk.Button(t1_frm5,
                                       text="Automate",
                                       width=12,
                                       command=self.automate).pack()
        t1_frm1.grid(column=1, row=1, padx=10, pady=15, sticky='w')
        t1_frm2.grid(column=1, row=2, padx=10, pady=5, sticky='w')
        t1_frm3.grid(column=1, row=3, padx=10, pady=5, sticky='w')
        t1_frm4.grid(column=1, row=4, padx=10, pady=15, sticky='w')
        t1_frm5.grid(column=1, row=5, padx=10, pady=15, sticky='w')
        # Populate tab2
        frm1 = ttk.Frame(tab2)
        frm2 = ttk.Frame(tab2)
        frm3 = ttk.Frame(tab2)
        frm4 = ttk.Frame(tab2)
        frm5 = ttk.Frame(tab2)
        frm6 = ttk.Frame(tab2)
        frm7 = ttk.Frame(tab2)
        self.label1 = ttk.Label(
            frm1,
            text=
            "Enter the path to the .txt log file you want to parse, or click Browse below."
        ).pack(side='left', padx=5, pady=10)
        self.label2 = ttk.Label(frm2, text="Path:").pack(side='left',
                                                         padx=5,
                                                         pady=10)
        self.log_file_path = ttk.Entry(frm2, width=35)
        self.log_file_path.pack(side='left', padx=5, pady=10)
        self.browse_btn = ttk.Button(frm2,
                                     text="Browse..",
                                     command=self.browse_clicked).pack(
                                         side='left', padx=5, pady=10)
        self.label3 = ttk.Label(
            frm3,
            text=
            "Once you've provided a valid path above, click on the Parse log button. This will parse the log file\ninto seperate commit entries and generate a database file to work with. This will take a few seconds.\nTo stop parsing when a specific date is reached, adjust the stop date accordingly. YYYY-MM-DD\nIf you are updating an existing database, the parser will automatically stop when it reaches the last\nknown commit found in the database OR when the stop date you provide is reached. Whichever\nhappens first."
        ).pack(side='left', padx=5, pady=10)
        self.parse_btn = ttk.Button(frm4,
                                    text="Parse log",
                                    width=20,
                                    command=self.parse_clicked)
        self.parse_btn.pack(side='left', padx=5, pady=10)
        self.label7 = ttk.Label(frm4, text="Stop date:").pack(side='left',
                                                              padx=20,
                                                              pady=10)
        self.stop_year_box = ttk.Combobox(frm4,
                                          width=5,
                                          state='readonly',
                                          values=(range(2001, 2020)))
        self.stop_year_box.pack(side='left', padx=2, pady=10)
        date_slash = ttk.Label(frm4, text='-').pack(side='left',
                                                    padx=2,
                                                    pady=10)
        self.stop_month_box = ttk.Combobox(
            frm4,
            width=3,
            state='readonly',
            values=(["%.2d" % i for i in range(1, 13)]))
        self.stop_month_box.pack(side='left', padx=2, pady=10)
        date_slash2 = ttk.Label(frm4, text='-').pack(side='left',
                                                     padx=2,
                                                     pady=10)
        self.stop_date_box = ttk.Combobox(
            frm4,
            width=3,
            state='readonly',
            values=(["%.2d" % i for i in range(1, 32)]))
        self.stop_date_box.pack(side='left', padx=2, pady=10)
        self.label4 = ttk.Label(
            frm5,
            text=
            "Once parsing/database generation completes, click on the Scan for restricted button. This will attempt\nto scan for all bugs that are protected. This can take a long time. You can throttle the slider below\nto adjust the scanning speed. This represents how many threads the scanner will spawn. The default\nis 12 and should be ok for most systems. Throttle this down if the scanning process fails. After\nthis completes, switch to the results tab at the top and click the refresh list button."
        ).pack(side='left', padx=5, pady=10)
        self.scan_btn = ttk.Button(frm6,
                                   text="Scan for restricted bugs",
                                   width=20,
                                   command=self.scan_clicked)
        self.scan_btn.pack(side='left', padx=5, pady=10)
        self.label6 = ttk.Label(frm6, text="Throttle:").pack(side='left',
                                                             padx=20,
                                                             pady=10)
        self.throttler = tk.Scale(frm6,
                                  from_=1,
                                  to=15,
                                  length=325,
                                  tickinterval=1,
                                  orient='horizontal')
        self.throttler.pack(side='left', padx=1, pady=10)
        self.stop_scan_btn = ttk.Button(frm7,
                                        text='Stop scanning',
                                        width=20,
                                        command=self.stop_scan_clicked)
        self.stop_scan_btn.pack(side='left', padx=5)

        frm1.grid(column=1, row=1, padx=10, sticky='w')
        frm2.grid(column=1, row=2, padx=10, sticky='w')
        frm3.grid(column=1, row=3, padx=10, sticky='w')
        frm4.grid(column=1, row=4, padx=10, sticky='w')
        frm5.grid(column=1, row=5, padx=10, sticky='w')
        frm6.grid(column=1, row=6, padx=10, sticky='w')
        frm7.grid(column=1, row=7, padx=10, sticky='nw')
        self.stop_year_box.current(11)
        self.stop_month_box.current(9)
        self.stop_date_box.current(15)
        self.throttler.set(12)

        # Populate tab3
        frm8 = ttk.Frame(tab3)
        frm9 = ttk.Frame(tab3)
        self.commit_view_box = tk.Listbox(frm8, height=39, width=35)
        self.commit_view_box.pack(fill='both', expand=True)
        self.commit_view_box.bind("<<ListboxSelect>>", self.commit_selected)
        self.commit_view_scrollbar = ttk.Scrollbar(self.commit_view_box,
                                                   orient='vertical')
        self.commit_view_scrollbar.pack(side='right', fill='y')
        self.commit_view_box.config(
            yscrollcommand=self.commit_view_scrollbar.set)
        self.commit_view_scrollbar.config(command=self.commit_view_box.yview)
        self.results_box = ScrolledText(frm9, height=42, width=75, wrap='word')
        self.results_box.pack(fill='both', expand=True)
        self.refresh_btn = ttk.Button(frm8,
                                      text='Refresh list',
                                      width=20,
                                      command=self.refresh_clicked)
        self.refresh_btn.pack(side='bottom', padx=50)
        frm8.pack(side='left', fill='both', expand=True)
        frm9.pack(side='right', fill='both', expand=True)

        # Populate tab4
        frm10 = ttk.Frame(tab4)
        frm11 = ttk.Frame(tab4)
        frm12 = ttk.Frame(tab4)
        frm13 = ttk.Frame(tab4)
        frm14 = ttk.Frame(tab4)
        frm15 = ttk.Frame(tab4)
        frm16 = ttk.Frame(tab4)
        self.label6 = ttk.Label(
            frm10,
            text=
            "Please enter your local IP address into the box below. You can attempt to grab your\nIP address automatically by clicking the Get my IP button."
        ).pack(side='left', padx=5, pady=10)
        iplbl = ttk.Label(frm11, text='IP:').pack(side='left', padx=5, pady=10)
        self.localip_entry = ttk.Entry(frm11, width=30)
        self.localip_entry.pack(side='left', padx=5, pady=10)
        self.getip_btn = ttk.Button(frm11,
                                    text="Get my IP",
                                    width=20,
                                    command=self.getip_clicked)
        self.getip_btn.pack(side='left', padx=10, pady=10)
        self.label7 = ttk.Label(
            frm12,
            text="Next, provide the path to the layout tests directory below."
        ).pack(side='left', padx=5, pady=10)
        self.label8 = ttk.Label(frm13, text="Path:").pack(side='left',
                                                          padx=5,
                                                          pady=10)
        self.layouttests_path = ttk.Entry(frm13, width=30)
        self.layouttests_path.pack(side='left', padx=5, pady=10)
        self.browse2_btn = ttk.Button(frm13,
                                      text="Browse..",
                                      command=self.browse2_clicked)
        self.browse2_btn.pack(side='left', padx=10, pady=10)
        self.label9 = ttk.Label(
            frm14,
            text=
            "Now, simply switch to the results view and copy/paste the location of the layout test\nfile below. Then click the Host file button, This will rename and host the file as\nindex.html on port 8000, once hosting, point the console browser to\nyour_local_ip_address:8000. Be sure to stop the server when done"
        ).pack(side='left', padx=5, pady=10)
        self.label10 = ttk.Label(frm15, text="Paste:").pack(side='left',
                                                            padx=5,
                                                            pady=10)
        self.hostfile_entry = ttk.Entry(frm15, width=60)
        self.hostfile_entry.pack(side='left', padx=10, pady=10)
        self.host_btn = ttk.Button(frm16,
                                   text="Host file",
                                   width=20,
                                   command=self.host_file_clicked)
        self.host_btn.pack(side='left', padx=40, pady=10)
        self.stop_srvr_btn = ttk.Button(frm16,
                                        text="Stop server",
                                        width=20,
                                        command=self.stop_srvr_clicked)
        self.stop_srvr_btn.pack(side='left', padx=40, pady=10)
        frm10.grid(column=1, row=1, padx=10, sticky='w')
        frm11.grid(column=1, row=2, padx=10, sticky='w')
        frm12.grid(column=1, row=3, padx=10, sticky='w')
        frm13.grid(column=1, row=4, padx=10, sticky='w')
        frm14.grid(column=1, row=5, padx=10, sticky='w')
        frm15.grid(column=1, row=6, padx=10, sticky='w')
        frm16.grid(column=1, row=7, padx=10, sticky='w')

    # Behavior for button clicks in all tabs of root window.
    def updt_wbkt_clicked(self):
        users_home = os.path.expanduser('~')
        wk = users_home + dir_slash + 'WebKit'
        if os.path.isdir(wk):
            print('webkit directory exists at: ' + wk)
            command = wk + dir_slash + 'Tools' + dir_slash + 'Scripts' + dir_slash + './update-webkit'
            p = subprocess.Popen(command, shell=True)
            out, err = p.communicate()
            #print(out)
        else:
            print('webkit was not present at: ' + wk)

        #p.wait()
        #output = p.stdout.read()
        #p.stdout.close()

    def get_svnlog_clicked(self):
        cur = os.getcwd()
        users_home = os.path.expanduser('~')
        wk = users_home + dir_slash + 'WebKit'
        #print(users_home)
        if os.path.isdir(wk):
            print('webkit directory exists at: ' + wk)
            if os.path.isfile('commits.db'):
                today = datetime.now()
                today = str(today.month) + '-' + str(today.day) + '-' + str(
                    today.year)
                db = sqlite3.connect('commits.db')
                cursor = db.cursor()
                cursor.execute("SELECT revision FROM logs")
                results = cursor.fetchall()
                max_rvn = max(results)[0].split('r')[1]
                log_name = 'webkitlog-' + today + '.txt'
                command = 'svn log -r BASE:' + max_rvn + ' > ' + log_name
                #print(command)
                #print(max_rvn)
                db.close()
                os.chdir(wk)
                p = subprocess.Popen(command, shell=True)
                out, err = p.communicate()
                #print(out)
                os.chdir(original_directory)
                log_pth = wk + dir_slash + log_name
                return log_pth

        else:
            print('webkit was not present at: ' + wk)

    def automate(self):
        print('\n\nNow running full automation, please be patient....')
        self.automate_running = True
        print('\n\nUpdating WebKit.....\n\n')
        self.updt_wbkt_clicked()
        print('\n\nObtaining WebKit svn changelog.....\n\n')
        log_path = self.get_svnlog_clicked()
        print('\n\nParsing log.....\n\n')
        self.parse_clicked(log_path)
        print('Running scan.....\n\n')
        self.scan_clicked()
        print('Switching to Results tab.....')
        self.notebook.select(self.results_tab)

        self.automate_running = False

    def browse_clicked(self):
        log_path = filedialog.askopenfilename()
        self.log_file_path.delete('0', tk.END)
        self.log_file_path.insert('end', log_path)

    def browse2_clicked(self):
        tests_directory = filedialog.askdirectory()
        self.layouttests_path.delete('0', tk.END)
        self.layouttests_path.insert('end', tests_directory)

    def start_server(self, path_to_host, local_ip, layout_loc, file_path):
        if not self.newthread:
            self.newthread = ServerThread(local_ip, path_to_host, layout_loc,
                                          file_path)
            self.newthread.daemon = True
            self.newthread.start()
            while True:

                if self.newthread.finished == True:
                    message.showinfo(
                        'Done',
                        'Now hosting ' + path_to_host + ' as\nindex.html @ ' +
                        str(self.newthread.serv_info[0]) + ":" +
                        str(self.newthread.serv_info[1]))
                    break

        else:
            message.showerror('Error', 'Server is already running.')
            print('server is running')

    def stop_srvr_clicked(self):
        if self.newthread:
            self.newthread.server.shutdown()
            self.newthread = False
            print('server stopped')
        else:
            print('server not found running')

    def getip_clicked(self):
        ip = ''
        if os.name == 'posix':
            ip = commands.getoutput("hostname -I")
            print(ip)
        elif os.name == 'nt':
            ip = socket.gethostbyname(socket.gethostname())
            print(ip)
        else:
            print('couldnt get local ip')
        self.localip_entry.delete('0', tk.END)
        self.localip_entry.insert('end', ip)

    def parse_clicked(self, *args):
        if (len(args) > 0):
            log_path = open(args[0])
        #print(args)

        else:
            try:
                log_path = open(self.log_file_path.get())
            except Exception as e:
                print(e)
                log_path = None
        if log_path != None:
            try:
                stop_date = self.stop_year_box.get(
                ) + '-' + self.stop_month_box.get(
                ) + '-' + self.stop_date_box.get()
                self.parsed_log = LogParser(log_path, stop_date)
                self.commit_list = self.parsed_log.commit_list
                self.entry_count = self.parsed_log.entry_count
                if not self.automate_running:
                    message.showinfo('Complete', 'Operation is complete')
            except Exception as e:
                print(e)
                message.showerror('Error',
                                  'Something went wrong parsing the log.')
        else:
            message.showerror(
                'Error',
                'You did not provide a file name or the file name is invalid.')

    def scan_clicked(self):
        if not self.scan_running:
            throttle_value = self.throttler.get()
            self.html_thread = HTMLScraper(int(throttle_value))
            self.html_thread.daemon = True
            self.html_thread.start()

    def stop_scan_clicked(self):
        print 'stop scanning'
        try:
            self.html_thread.abort = True
        except Exception as e:
            print(e.args)

    def refresh_clicked(self):
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs WHERE restricted == 1")
        self.commit_view_box.configure(state='normal')
        self.commit_view_box.delete('0', tk.END)
        for i in cursor:
            self.commit_view_box.insert('end', i[1] + ' | ' + i[2])
            self.commit_track_list.append(i[1])
        db.close()

    '''
    def stripdb_clicked(self):
        
        db_id = []
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs")
        try:
            for i in cursor:
                if i[4] != 1:
                    db_id.append(i[0])
            for i in db_id:
                cursor.execute("DELETE FROM logs WHERE id = ?",(str(i),))
        except Exception as e:
            print(e)
            message.showerror('Error','Something went wrong stripping the database.')
        message.showinfo('Complete','Operation complete')
        db.commit()
        db.close()
    '''

    def host_file_clicked(self):
        self.stop_srvr_clicked()
        local_ip = self.localip_entry.get()
        layout_loc = self.layouttests_path.get()
        if os.name == 'nt':
            layout_loc = layout_loc.replace('/', dir_slash)
        if local_ip != '':
            if layout_loc != '':
                file_path = self.hostfile_entry.get()
                if os.name == 'nt':
                    file_path = file_path.replace('/', dir_slash)
                alt_file_path = layout_loc + dir_slash + file_path
                print('the file path : ' + file_path)
                if file_path != '':
                    try:
                        if os.path.isfile(alt_file_path):
                            self.start_server(alt_file_path, local_ip,
                                              layout_loc, file_path)
                            #self.copy_host_file(alt_file_path)
                            print('found file')
                            #message.showinfo('Done','Now hosting '+ alt_file_path)
                        else:
                            message.showerror('Error', 'File was not found.')
                    except Exception as e:
                        print(e)
                else:
                    message.showerror('Error', 'All fields are required.')
            else:
                message.showerror('Error', 'All fields are required.')
        else:
            message.showerror('Error', 'All fields are required.')

    '''
    def copy_host_file(self,file_to_host):
        filename = "index.html"
        try:
            shutil.copyfile(file_to_host, filename)
        except Exception as e:
            print(e)
    '''

    # Behavior for the commit_view_box listbox selections.
    def commit_selected(self, event):
        self.results_box.delete('0.0', tk.END)
        current = self.commit_view_box.curselection()
        activate_current = self.commit_view_box.activate(current)
        get_selection = current[0]
        #print "Selection", get_selection
        #print "Item", self.commit_track_list
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs WHERE revision = ?",
                       (self.commit_track_list[int(get_selection)], ))
        results = cursor.fetchall()
        #print results
        if len(results) > 0:
            for result in results:
                lid, rvn, date, url, info, rst, scnd = result
                #print "RVN:",rvn
                #print "DATE:",c
                #print "URL:",d
                try:
                    lid, rvn, date, url, info, rst, scnd = result
                    meta = rvn + '| ' + date + ' | ' + url
                    delimeter = '_' * 55
                    self.results_box.insert(
                        'end', '\n'.join([meta, delimeter, (info + "\n")]))
                except Exception as e:
                    print e.args

        cursor.close()
        db.close()
    def build_window(self):
        # Build the Notebook widget
        self.notebook = ttk.Notebook(self)
        tab1 = ttk.Frame(self.notebook)
        tab2 = ttk.Frame(self.notebook)
        tab3 = ttk.Frame(self.notebook)
        self.results_tab = tab3
        tab4 = ttk.Frame(self.notebook)
        self.notebook.add(tab1, text="Welcome")
        self.notebook.add(tab2, text="Parser")
        self.notebook.add(tab3, text="Results")
        self.notebook.add(tab4, text="Hosting")
        self.notebook.pack(fill="both", expand=True)

        # Populate tab1
        t1_frm1 = ttk.Frame(tab1)
        t1_frm2 = ttk.Frame(tab1)
        t1_frm3 = ttk.Frame(tab1)
        t1_frm4 = ttk.Frame(tab1)
        t1_frm5 = ttk.Frame(tab1)
        t1_label1 = ttk.Label(
            t1_frm1,
            text=
            "Welcome to the Webkit Bug Finder. This program will parse a WebKit SVN changelog and find all bugs that are\n\
restricted from public view. It stores the changelog information for each bug into a database so that the\n\
program can show you each bug and its associated committ log. Most of these will contain details about\n\
what triggers the bug. Many will also contain layout test paths to trigger the bug. These layout tests are\n\
contained in your updated local WebKit repo and can be hosted by this program using the hosting tab above.\n\
Once hosted, you can navigate your WebKit based browser to your_IP_address:8000 to see if the browser is\n\
affected by the bug. This is how it works:\n\n\
\n1: Update your local copy of WebKit repo by running Tools" + dir_slash +
            "Scripts" + dir_slash + "update-webkit\n\n\
2: You will need to have Subversion installed and obtain a svn changelog by navigating\n\
    to the root of your WebKit directory and running: svn log > any_filename.txt\n\n\
3: Once you have the svn changelog, you can parse and scan it following the instructions\n\
    in the parser tab. If this is the first time running the program, a new database will be\n\
    generated. If you already have a database, it will be updated each time you repeat this\n\
    process. Once a scan has completed it can take a while to write the results to the database.\n\
    You will see a 'Done' message in the terminal window when it has completed. "
        ).pack(side='left', padx=5, pady=10)

        t1_label2 = ttk.Label(
            t1_frm2,
            text=
            "If you are running linux, have Subversion installed and have WebKit installed @ usershome/WebKit/\nthen the following 3 buttons will work. Automate will try to automate the entire process.\nThat is, update webkit, get a WebKit svn log, parse said log, scan for restricted bugs and switch\nyou to the results views. Throttle and Stop Date values will be obtained from the Parser tab. Change the values there prior to\nproceeding with the automation. This could take a while..."
        ).pack(side='left', padx=5, pady=10)

        self.updt_wbkt_btn = ttk.Button(t1_frm3,
                                        text="Update WebKit",
                                        width=12,
                                        command=self.updt_wbkt_clicked).pack()
        self.get_svnlog_btn = ttk.Button(
            t1_frm4,
            text="Get Svn Log",
            width=12,
            command=self.get_svnlog_clicked).pack()
        self.automate_btn = ttk.Button(t1_frm5,
                                       text="Automate",
                                       width=12,
                                       command=self.automate).pack()
        t1_frm1.grid(column=1, row=1, padx=10, pady=15, sticky='w')
        t1_frm2.grid(column=1, row=2, padx=10, pady=5, sticky='w')
        t1_frm3.grid(column=1, row=3, padx=10, pady=5, sticky='w')
        t1_frm4.grid(column=1, row=4, padx=10, pady=15, sticky='w')
        t1_frm5.grid(column=1, row=5, padx=10, pady=15, sticky='w')
        # Populate tab2
        frm1 = ttk.Frame(tab2)
        frm2 = ttk.Frame(tab2)
        frm3 = ttk.Frame(tab2)
        frm4 = ttk.Frame(tab2)
        frm5 = ttk.Frame(tab2)
        frm6 = ttk.Frame(tab2)
        frm7 = ttk.Frame(tab2)
        self.label1 = ttk.Label(
            frm1,
            text=
            "Enter the path to the .txt log file you want to parse, or click Browse below."
        ).pack(side='left', padx=5, pady=10)
        self.label2 = ttk.Label(frm2, text="Path:").pack(side='left',
                                                         padx=5,
                                                         pady=10)
        self.log_file_path = ttk.Entry(frm2, width=35)
        self.log_file_path.pack(side='left', padx=5, pady=10)
        self.browse_btn = ttk.Button(frm2,
                                     text="Browse..",
                                     command=self.browse_clicked).pack(
                                         side='left', padx=5, pady=10)
        self.label3 = ttk.Label(
            frm3,
            text=
            "Once you've provided a valid path above, click on the Parse log button. This will parse the log file\ninto seperate commit entries and generate a database file to work with. This will take a few seconds.\nTo stop parsing when a specific date is reached, adjust the stop date accordingly. YYYY-MM-DD\nIf you are updating an existing database, the parser will automatically stop when it reaches the last\nknown commit found in the database OR when the stop date you provide is reached. Whichever\nhappens first."
        ).pack(side='left', padx=5, pady=10)
        self.parse_btn = ttk.Button(frm4,
                                    text="Parse log",
                                    width=20,
                                    command=self.parse_clicked)
        self.parse_btn.pack(side='left', padx=5, pady=10)
        self.label7 = ttk.Label(frm4, text="Stop date:").pack(side='left',
                                                              padx=20,
                                                              pady=10)
        self.stop_year_box = ttk.Combobox(frm4,
                                          width=5,
                                          state='readonly',
                                          values=(range(2001, 2020)))
        self.stop_year_box.pack(side='left', padx=2, pady=10)
        date_slash = ttk.Label(frm4, text='-').pack(side='left',
                                                    padx=2,
                                                    pady=10)
        self.stop_month_box = ttk.Combobox(
            frm4,
            width=3,
            state='readonly',
            values=(["%.2d" % i for i in range(1, 13)]))
        self.stop_month_box.pack(side='left', padx=2, pady=10)
        date_slash2 = ttk.Label(frm4, text='-').pack(side='left',
                                                     padx=2,
                                                     pady=10)
        self.stop_date_box = ttk.Combobox(
            frm4,
            width=3,
            state='readonly',
            values=(["%.2d" % i for i in range(1, 32)]))
        self.stop_date_box.pack(side='left', padx=2, pady=10)
        self.label4 = ttk.Label(
            frm5,
            text=
            "Once parsing/database generation completes, click on the Scan for restricted button. This will attempt\nto scan for all bugs that are protected. This can take a long time. You can throttle the slider below\nto adjust the scanning speed. This represents how many threads the scanner will spawn. The default\nis 12 and should be ok for most systems. Throttle this down if the scanning process fails. After\nthis completes, switch to the results tab at the top and click the refresh list button."
        ).pack(side='left', padx=5, pady=10)
        self.scan_btn = ttk.Button(frm6,
                                   text="Scan for restricted bugs",
                                   width=20,
                                   command=self.scan_clicked)
        self.scan_btn.pack(side='left', padx=5, pady=10)
        self.label6 = ttk.Label(frm6, text="Throttle:").pack(side='left',
                                                             padx=20,
                                                             pady=10)
        self.throttler = tk.Scale(frm6,
                                  from_=1,
                                  to=15,
                                  length=325,
                                  tickinterval=1,
                                  orient='horizontal')
        self.throttler.pack(side='left', padx=1, pady=10)
        self.stop_scan_btn = ttk.Button(frm7,
                                        text='Stop scanning',
                                        width=20,
                                        command=self.stop_scan_clicked)
        self.stop_scan_btn.pack(side='left', padx=5)

        frm1.grid(column=1, row=1, padx=10, sticky='w')
        frm2.grid(column=1, row=2, padx=10, sticky='w')
        frm3.grid(column=1, row=3, padx=10, sticky='w')
        frm4.grid(column=1, row=4, padx=10, sticky='w')
        frm5.grid(column=1, row=5, padx=10, sticky='w')
        frm6.grid(column=1, row=6, padx=10, sticky='w')
        frm7.grid(column=1, row=7, padx=10, sticky='nw')
        self.stop_year_box.current(11)
        self.stop_month_box.current(9)
        self.stop_date_box.current(15)
        self.throttler.set(12)

        # Populate tab3
        frm8 = ttk.Frame(tab3)
        frm9 = ttk.Frame(tab3)
        self.commit_view_box = tk.Listbox(frm8, height=39, width=35)
        self.commit_view_box.pack(fill='both', expand=True)
        self.commit_view_box.bind("<<ListboxSelect>>", self.commit_selected)
        self.commit_view_scrollbar = ttk.Scrollbar(self.commit_view_box,
                                                   orient='vertical')
        self.commit_view_scrollbar.pack(side='right', fill='y')
        self.commit_view_box.config(
            yscrollcommand=self.commit_view_scrollbar.set)
        self.commit_view_scrollbar.config(command=self.commit_view_box.yview)
        self.results_box = ScrolledText(frm9, height=42, width=75, wrap='word')
        self.results_box.pack(fill='both', expand=True)
        self.refresh_btn = ttk.Button(frm8,
                                      text='Refresh list',
                                      width=20,
                                      command=self.refresh_clicked)
        self.refresh_btn.pack(side='bottom', padx=50)
        frm8.pack(side='left', fill='both', expand=True)
        frm9.pack(side='right', fill='both', expand=True)

        # Populate tab4
        frm10 = ttk.Frame(tab4)
        frm11 = ttk.Frame(tab4)
        frm12 = ttk.Frame(tab4)
        frm13 = ttk.Frame(tab4)
        frm14 = ttk.Frame(tab4)
        frm15 = ttk.Frame(tab4)
        frm16 = ttk.Frame(tab4)
        self.label6 = ttk.Label(
            frm10,
            text=
            "Please enter your local IP address into the box below. You can attempt to grab your\nIP address automatically by clicking the Get my IP button."
        ).pack(side='left', padx=5, pady=10)
        iplbl = ttk.Label(frm11, text='IP:').pack(side='left', padx=5, pady=10)
        self.localip_entry = ttk.Entry(frm11, width=30)
        self.localip_entry.pack(side='left', padx=5, pady=10)
        self.getip_btn = ttk.Button(frm11,
                                    text="Get my IP",
                                    width=20,
                                    command=self.getip_clicked)
        self.getip_btn.pack(side='left', padx=10, pady=10)
        self.label7 = ttk.Label(
            frm12,
            text="Next, provide the path to the layout tests directory below."
        ).pack(side='left', padx=5, pady=10)
        self.label8 = ttk.Label(frm13, text="Path:").pack(side='left',
                                                          padx=5,
                                                          pady=10)
        self.layouttests_path = ttk.Entry(frm13, width=30)
        self.layouttests_path.pack(side='left', padx=5, pady=10)
        self.browse2_btn = ttk.Button(frm13,
                                      text="Browse..",
                                      command=self.browse2_clicked)
        self.browse2_btn.pack(side='left', padx=10, pady=10)
        self.label9 = ttk.Label(
            frm14,
            text=
            "Now, simply switch to the results view and copy/paste the location of the layout test\nfile below. Then click the Host file button, This will rename and host the file as\nindex.html on port 8000, once hosting, point the console browser to\nyour_local_ip_address:8000. Be sure to stop the server when done"
        ).pack(side='left', padx=5, pady=10)
        self.label10 = ttk.Label(frm15, text="Paste:").pack(side='left',
                                                            padx=5,
                                                            pady=10)
        self.hostfile_entry = ttk.Entry(frm15, width=60)
        self.hostfile_entry.pack(side='left', padx=10, pady=10)
        self.host_btn = ttk.Button(frm16,
                                   text="Host file",
                                   width=20,
                                   command=self.host_file_clicked)
        self.host_btn.pack(side='left', padx=40, pady=10)
        self.stop_srvr_btn = ttk.Button(frm16,
                                        text="Stop server",
                                        width=20,
                                        command=self.stop_srvr_clicked)
        self.stop_srvr_btn.pack(side='left', padx=40, pady=10)
        frm10.grid(column=1, row=1, padx=10, sticky='w')
        frm11.grid(column=1, row=2, padx=10, sticky='w')
        frm12.grid(column=1, row=3, padx=10, sticky='w')
        frm13.grid(column=1, row=4, padx=10, sticky='w')
        frm14.grid(column=1, row=5, padx=10, sticky='w')
        frm15.grid(column=1, row=6, padx=10, sticky='w')
        frm16.grid(column=1, row=7, padx=10, sticky='w')
Example #3
0
    def __init__(self, top=None):
        global urlAddress
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9'  # X11 color: 'gray85'
        _ana1color = '#d9d9d9'  # X11 color: 'gray85'
        _ana2color = '#ececec'  # Closest X11 color: 'gray92'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.', background=_bgcolor)
        self.style.configure('.', foreground=_fgcolor)
        self.style.map('.',
                       background=[('selected', _compcolor),
                                   ('active', _ana2color)])

        top.geometry("951x650+377+0")
        top.title("Data Mining")
        top.configure(background="#9c9c9e")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="#000000")

        self.root_label = tk.Label(top)
        self.root_label.place(relx=0.021, rely=0.024, height=46, width=112)
        self.root_label.configure(activebackground="#a5a5a8")
        self.root_label.configure(activeforeground="#a5a5a8")
        self.root_label.configure(background="#9c9c9e")
        self.root_label.configure(disabledforeground="#a3a3a3")
        self.root_label.configure(
            font="-family {Yu Gothic UI Semibold} -size 9 -weight bold")
        self.root_label.configure(foreground="#000000")
        self.root_label.configure(highlightbackground="#d9d9d9")
        self.root_label.configure(highlightcolor="black")
        self.root_label.configure(text='''Enter Root''')

        self.root_text = tk.Text(top)
        self.root_text.place(relx=0.158,
                             rely=0.036,
                             relheight=0.04,
                             relwidth=0.604)
        self.root_text.configure(background="white")
        self.root_text.configure(
            font="-family {Yu Gothic UI Semibold} -size 9 -weight bold")
        self.root_text.configure(foreground="black")
        self.root_text.configure(highlightbackground="#d9d9d9")
        self.root_text.configure(highlightcolor="black")
        self.root_text.configure(inactiveselectbackground="#000000")
        self.root_text.configure(insertbackground="black")
        self.root_text.configure(selectbackground="#c4c4c4")
        self.root_text.configure(selectforeground="black")
        self.root_text.configure(width=574)
        self.root_text.configure(wrap="word")
        tooltip_font = "TkDefaultFont"
        ToolTip(self.root_text, tooltip_font, '''enter your root''', delay=0.5)

        self.search_button = tk.Button(top)
        self.search_button.place(relx=0.831, rely=0.036, height=33, width=146)
        self.search_button.configure(activebackground="#3e3eed")
        self.search_button.configure(activeforeground="white")
        self.search_button.configure(activeforeground="#000000")
        self.search_button.configure(background="#e8e7e6")
        self.search_button.configure(command=self.import_url)
        self.search_button.configure(disabledforeground="#a3a3a3")
        self.search_button.configure(font="-family {Segoe UI Emoji} -size 9")
        self.search_button.configure(foreground="#000000")
        self.search_button.configure(highlightbackground="#d9d9d9")
        self.search_button.configure(highlightcolor="black")
        self.search_button.configure(pady="0")
        self.search_button.configure(text='''Search''')
        self.search_button.configure(width=146)
        tooltip_font = "TkDefaultFont"
        ToolTip(self.search_button,
                tooltip_font,
                '''press to Search''',
                delay=0.5)

        self.export_to_txt_button = tk.Button(top)
        self.export_to_txt_button.place(relx=0.852,
                                        rely=0.881,
                                        height=73,
                                        width=106)
        self.export_to_txt_button.configure(activebackground="#ececec")
        self.export_to_txt_button.configure(activeforeground="#000000")
        self.export_to_txt_button.configure(background="#d9d9d9")
        self.export_to_txt_button.configure(
            command=Window_support.export_to_txt)
        self.export_to_txt_button.configure(disabledforeground="#a3a3a3")
        self.export_to_txt_button.configure(foreground="#000000")
        self.export_to_txt_button.configure(highlightbackground="#d9d9d9")
        self.export_to_txt_button.configure(highlightcolor="#000000")
        self.export_to_txt_button.configure(pady="0")
        self.export_to_txt_button.configure(text='''export to TXT''')
        self.export_to_txt_button.configure(width=106)
        tooltip_font = "TkDefaultFont"
        ToolTip(self.export_to_txt_button,
                tooltip_font,
                '''press to export the table to TXT file''',
                delay=0.5)

        self.filter_button = tk.Button(top)
        self.filter_button.place(relx=0.862, rely=0.155, height=73, width=96)
        self.filter_button.configure(activebackground="#ececec")
        self.filter_button.configure(activeforeground="#000000")
        self.filter_button.configure(background="#d9d9d9")
        self.filter_button.configure(disabledforeground="#a3a3a3")
        self.filter_button.configure(foreground="#000000")
        self.filter_button.configure(highlightbackground="#d9d9d9")
        self.filter_button.configure(highlightcolor="black")
        self.filter_button.configure(pady="0")
        self.filter_button.configure(command=self.search_by_model)
        self.filter_button.configure(text='''Find Specific\n Model''')

        self.filter_model_text = tk.Text(top)
        self.filter_model_text.place(relx=0.831,
                                     rely=0.286,
                                     relheight=0.04,
                                     relwidth=0.151)
        self.filter_model_text.configure(background="white")
        self.filter_model_text.configure(font="TkTextFont")
        self.filter_model_text.configure(foreground="black")
        self.filter_model_text.configure(highlightbackground="#d9d9d9")
        self.filter_model_text.configure(highlightcolor="black")
        self.filter_model_text.configure(insertbackground="black")
        self.filter_model_text.configure(selectbackground="#c4c4c4")
        self.filter_model_text.configure(selectforeground="black")
        self.filter_model_text.configure(width=144)
        self.filter_model_text.configure(wrap="word")
        tooltip_font = "TkDefaultFont"
        ToolTip(self.filter_model_text,
                tooltip_font,
                '''enter specific model to filter the result''',
                delay=0.5)

        self.reset_button = tk.Button(top)
        self.reset_button.place(relx=0.032, rely=0.929, height=33, width=186)
        self.reset_button.configure(activebackground="#ececec")
        self.reset_button.configure(activeforeground="#000000")
        self.reset_button.configure(background="#d9d9d9")
        self.reset_button.configure(disabledforeground="#a3a3a3")
        self.reset_button.configure(foreground="#000000")
        self.reset_button.configure(highlightbackground="#d9d9d9")
        self.reset_button.configure(highlightcolor="black")
        self.reset_button.configure(pady="0")
        self.reset_button.configure(command=self.delete_Scrolledtext)
        self.reset_button.configure(text='''Reset''')
        tooltip_font = "TkDefaultFont"
        ToolTip(self.reset_button,
                tooltip_font,
                '''press to reset the table''',
                delay=0.5)

        self.menubar = tk.Menu(top,
                               font="TkMenuFont",
                               bg=_bgcolor,
                               fg=_fgcolor)
        top.configure(menu=self.menubar)

        self.Scrolledtext1 = ScrolledText(top)
        self.Scrolledtext1.place(relx=0.032,
                                 rely=0.107,
                                 relheight=0.802,
                                 relwidth=0.783)
        self.Scrolledtext1.configure(background="white")
        self.Scrolledtext1.configure(font="TkTextFont")
        self.Scrolledtext1.configure(state="disabled")
        self.Scrolledtext1.configure(foreground="black")
        self.Scrolledtext1.configure(highlightbackground="#d9d9d9")
        self.Scrolledtext1.configure(highlightcolor="black")
        self.Scrolledtext1.configure(insertbackground="black")
        self.Scrolledtext1.configure(insertborderwidth="50")
        self.Scrolledtext1.configure(selectbackground="#c4c4c4")
        self.Scrolledtext1.configure(selectforeground="black")
        self.Scrolledtext1.configure(width=200)
        self.Scrolledtext1.configure(wrap="none")
Example #4
0
class data_screen:
    ####---------------------------------------- START OF GUI INIT ---------------------------------------####

    def __init__(self, top=None):
        global urlAddress
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9'  # X11 color: 'gray85'
        _ana1color = '#d9d9d9'  # X11 color: 'gray85'
        _ana2color = '#ececec'  # Closest X11 color: 'gray92'
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.', background=_bgcolor)
        self.style.configure('.', foreground=_fgcolor)
        self.style.map('.',
                       background=[('selected', _compcolor),
                                   ('active', _ana2color)])

        top.geometry("951x770+377+0")
        top.title("Data Mining")
        top.configure(background="#9c9c9e")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="#000000")

        self.root_label = tk.Label(top)
        self.root_label.place(relx=0.021, rely=0.024, height=46, width=112)
        self.root_label.configure(activebackground="#a5a5a8")
        self.root_label.configure(activeforeground="#a5a5a8")
        self.root_label.configure(background="#9c9c9e")
        self.root_label.configure(disabledforeground="#a3a3a3")
        self.root_label.configure(
            font="-family {Yu Gothic UI Semibold} -size 9 -weight bold")
        self.root_label.configure(foreground="#000000")
        self.root_label.configure(highlightbackground="#d9d9d9")
        self.root_label.configure(highlightcolor="black")
        self.root_label.configure(text='''Enter Root''')

        self.root_text = tk.Text(top)
        self.root_text.place(relx=0.158,
                             rely=0.036,
                             relheight=0.04,
                             relwidth=0.604)
        self.root_text.configure(background="white")
        self.root_text.configure(
            font="-family {Yu Gothic UI Semibold} -size 9 -weight bold")
        self.root_text.configure(foreground="black")
        self.root_text.configure(highlightbackground="#d9d9d9")
        self.root_text.configure(highlightcolor="black")
        self.root_text.configure(inactiveselectbackground="#000000")
        self.root_text.configure(insertbackground="black")
        self.root_text.configure(selectbackground="#c4c4c4")
        self.root_text.configure(selectforeground="black")
        self.root_text.configure(width=574)
        self.root_text.configure(wrap="word")
        tooltip_font = "TkDefaultFont"
        ToolTip(self.root_text, tooltip_font, '''enter your root''', delay=0.5)

        self.search_button = tk.Button(top)
        self.search_button.place(relx=0.831, rely=0.036, height=33, width=146)
        self.search_button.configure(activebackground="#3e3eed")
        self.search_button.configure(activeforeground="white")
        self.search_button.configure(activeforeground="#000000")
        self.search_button.configure(background="#e8e7e6")
        self.search_button.configure(command=self.import_url)
        self.search_button.configure(disabledforeground="#a3a3a3")
        self.search_button.configure(font="-family {Segoe UI Emoji} -size 9")
        self.search_button.configure(foreground="#000000")
        self.search_button.configure(highlightbackground="#d9d9d9")
        self.search_button.configure(highlightcolor="black")
        self.search_button.configure(pady="0")
        self.search_button.configure(text='''Search''')
        self.search_button.configure(width=146)
        tooltip_font = "TkDefaultFont"
        ToolTip(self.search_button,
                tooltip_font,
                '''press to Search''',
                delay=0.5)

        self.import_to_txt_button = tk.Button(top)
        self.import_to_txt_button.place(relx=0.852,
                                        rely=0.881,
                                        height=73,
                                        width=106)
        self.import_to_txt_button.configure(activebackground="#ececec")
        self.import_to_txt_button.configure(activeforeground="#000000")
        self.import_to_txt_button.configure(background="#d9d9d9")
        self.import_to_txt_button.configure(
            command=Window_support.import_to_txt)
        self.import_to_txt_button.configure(disabledforeground="#a3a3a3")
        self.import_to_txt_button.configure(foreground="#000000")
        self.import_to_txt_button.configure(highlightbackground="#d9d9d9")
        self.import_to_txt_button.configure(highlightcolor="#000000")
        self.import_to_txt_button.configure(pady="0")
        self.import_to_txt_button.configure(text='''export to TXT''')
        self.import_to_txt_button.configure(width=106)
        tooltip_font = "TkDefaultFont"
        ToolTip(self.import_to_txt_button,
                tooltip_font,
                '''press to export the table to TXT file''',
                delay=0.5)

        self.filter_button = tk.Button(top)
        self.filter_button.place(relx=0.862, rely=0.155, height=73, width=96)
        self.filter_button.configure(activebackground="#ececec")
        self.filter_button.configure(activeforeground="#000000")
        self.filter_button.configure(background="#d9d9d9")
        self.filter_button.configure(disabledforeground="#a3a3a3")
        self.filter_button.configure(foreground="#000000")
        self.filter_button.configure(highlightbackground="#d9d9d9")
        self.filter_button.configure(highlightcolor="black")
        self.filter_button.configure(pady="0")
        self.filter_button.configure(command=self.search_by_model)
        self.filter_button.configure(text='''Find Specific\n Model''')

        self.filter_model_text = tk.Text(top)
        self.filter_model_text.place(relx=0.831,
                                     rely=0.286,
                                     relheight=0.04,
                                     relwidth=0.151)
        self.filter_model_text.configure(background="white")
        self.filter_model_text.configure(font="TkTextFont")
        self.filter_model_text.configure(foreground="black")
        self.filter_model_text.configure(highlightbackground="#d9d9d9")
        self.filter_model_text.configure(highlightcolor="black")
        self.filter_model_text.configure(insertbackground="black")
        self.filter_model_text.configure(selectbackground="#c4c4c4")
        self.filter_model_text.configure(selectforeground="black")
        self.filter_model_text.configure(width=144)
        self.filter_model_text.configure(wrap="word")
        tooltip_font = "TkDefaultFont"
        ToolTip(self.filter_model_text,
                tooltip_font,
                '''enter specific model to filter the result''',
                delay=0.5)

        self.reset_button = tk.Button(top)
        self.reset_button.place(relx=0.032, rely=0.929, height=33, width=186)
        self.reset_button.configure(activebackground="#ececec")
        self.reset_button.configure(activeforeground="#000000")
        self.reset_button.configure(background="#d9d9d9")
        self.reset_button.configure(disabledforeground="#a3a3a3")
        self.reset_button.configure(foreground="#000000")
        self.reset_button.configure(highlightbackground="#d9d9d9")
        self.reset_button.configure(highlightcolor="black")
        self.reset_button.configure(pady="0")
        self.reset_button.configure(command=self.delete_Scrolledtext)
        self.reset_button.configure(text='''Reset''')
        tooltip_font = "TkDefaultFont"
        ToolTip(self.reset_button,
                tooltip_font,
                '''press to reset the table''',
                delay=0.5)

        self.menubar = tk.Menu(top,
                               font="TkMenuFont",
                               bg=_bgcolor,
                               fg=_fgcolor)
        top.configure(menu=self.menubar)

        self.Scrolledtext1 = ScrolledText(top)
        self.Scrolledtext1.place(relx=0.032,
                                 rely=0.107,
                                 relheight=0.802,
                                 relwidth=0.783)
        self.Scrolledtext1.configure(background="white")
        self.Scrolledtext1.configure(font="TkTextFont")
        self.Scrolledtext1.configure(state="disabled")
        self.Scrolledtext1.configure(foreground="black")
        self.Scrolledtext1.configure(highlightbackground="#d9d9d9")
        self.Scrolledtext1.configure(highlightcolor="black")
        self.Scrolledtext1.configure(insertbackground="black")
        self.Scrolledtext1.configure(insertborderwidth="50")
        self.Scrolledtext1.configure(selectbackground="#c4c4c4")
        self.Scrolledtext1.configure(selectforeground="black")
        self.Scrolledtext1.configure(width=200)
        self.Scrolledtext1.configure(wrap="none")

    ####---------------------------------------- END OF GUI INIT ---------------------------------------####

    #****************    function for search button    ********************#

    def import_url(self):
        '''
        GUI method that import all table from specific url
        :return: None
        '''
        self.Scrolledtext1.configure(state="normal")
        self.Scrolledtext1.delete("1.0", "end-1c")
        urlAddress = self.root_text.get("1.0", "end-1c")
        self.Scrolledtext1.insert(
            tk.INSERT, Window_support.search_window(urlAddress, 'all'))
        self.Scrolledtext1.configure(state="disabled")

    #****************    END function for search button    ********************#

    #****************    START function for filter button    ********************#

    def search_by_model(self):
        '''
        function that do the same as import_url but, filter by specific model and return table
        :return:None
        '''
        self.Scrolledtext1.configure(state="normal")
        self.Scrolledtext1.delete("1.0", "end-1c")
        urlAddress = self.root_text.get("1.0", "end-1c")
        model = self.filter_model_text.get("1.0", 'end-1c')
        self.Scrolledtext1.insert(
            tk.INSERT, Window_support.search_window(urlAddress, model))
        self.Scrolledtext1.configure(state="disabled")

    #****************    END function for filter button    ********************#

    #****************    START function for reset button    ********************#
    def delete_Scrolledtext(self):
        '''
        functio that delete the scrolled_text when we want a new table
        :return: None
        '''
        self.Scrolledtext1.configure(state="normal")
        self.Scrolledtext1.delete("1.0", "end-1c")
        self.root_text.delete("1.0", "end-1c")
        self.Scrolledtext1.configure(state="disabled")
Example #5
0
import tkinter as tk
from tkinter import *
import tkinter.scrolledtext as ScrolledText
import os

root = tk.Tk(className=" Just another Text Editor")
textPad = ScrolledText(root, width=100, height=80)

# create a menu & define functions for each menu item


def open_command():
    file = tkFileDialog.askopenfile(parent=root,
                                    mode='rb',
                                    title='Select a file')
    if file != None:
        contents = file.read()
        textPad.insert('1.0', contents)
        file.close()


def save_command(self):
    file = tkFileDialog.asksaveasfile(mode='w')
    if file != None:
        # slice off the last character from get, as an extra return is added
        data = self.textPad.get('1.0', END + '-1c')
        file.write(data)
        file.close()


def exit_command():
    def build_window(self):
        # Build the Notebook widget
        n = ttk.Notebook(self)
        tab1 = ttk.Frame(n)
        tab2 = ttk.Frame(n)
        tab3 = ttk.Frame(n)
        tab4 = ttk.Frame(n)
        n.add(tab1,text="Welcome1")
        n.add(tab2,text="Parser")
        n.add(tab3,text="Results")
        n.add(tab4,text="Hosting")
        n.pack(fill="both", expand=True)

        # Populate tab1
        t1_frm1 = ttk.Frame(tab1)   
        t1_frm2 = ttk.Frame(tab1)
        t1_label1 = ttk.Label(t1_frm1,text="Welcome to the Webkit Bug Finder. This program will parse a WebKit SVN changelog and find all bugs that are\n\
restricted from public view. It stores the changelog information for each bug into a database so that the\n\
program can show you each bug and its associated committ log. Most of these will contain details about\n\
what triggers the bug. Many will also contain layout test paths to trigger the bug. These layout tests are\n\
contained in your updated local WebKit repo and can be hosted by this program using the hosting tab above.\n\
Once hosted, you can navigate your WebKit based browser to your_IP_address:8000 to see if the browser is\n\
affected by the bug. This is how it works:\n\n\
\n1: Update your local copy of WebKit repo by running Tools"+dir_slash+"Scripts"+dir_slash+"update-webkit\n\n\
2: You will need to have Subversion installed and obtain a svn changelog by navigating\n\
    to the root of your WebKit directory and running: svn log > any_filename.txt\n\n\
3: Once you have the svn changelog, you can parse and scan it following the instructions\n\
    in the parser tab. If this is the first time running the program, a new database will be\n\
    generated. If you already have a database, it will be updated each time you repeat this\n\
    process. Once a scan has completed it can take a while to write the results to the database.\n\
    You will see a 'Done' message in the terminal window when it has completed. ").pack(side='left',padx=5,pady=10)
        
        self.updt_wbkt_btn=ttk.Button(t1_frm2,text="Update WebKit",command=self.updt_wbkt_clicked).pack()
        t1_frm1.grid(column=1,row=1,padx=10,sticky='w')
        t1_frm2.grid(column=1,row=2,padx=10,sticky='sw')
        # Populate tab2
        frm1 = ttk.Frame(tab2)
        frm2 = ttk.Frame(tab2)
        frm3 = ttk.Frame(tab2)
        frm4 = ttk.Frame(tab2)
        frm5 = ttk.Frame(tab2)
        frm6 = ttk.Frame(tab2)
        frm7 = ttk.Frame(tab2)
        self.label1 = ttk.Label(frm1,text="Enter the path to the .txt log file you want to parse, or click Browse below.").pack(side='left',padx=5,pady=10)
        self.label2 = ttk.Label(frm2,text="Path:").pack(side='left',padx=5,pady=10)
        self.log_file_path = ttk.Entry(frm2, width=35)
        self.log_file_path.pack(side='left',padx=5,pady=10)
        self.browse_btn = ttk.Button(frm2,text="Browse..",command=self.browse_clicked).pack(side='left',padx=5,pady=10)
        self.label3 = ttk.Label(frm3,text="Once you've provided a valid path above, click on the Parse log button. This will parse the log file\ninto seperate commit entries and generate a database file to work with. This will take a few seconds.\nTo stop parsing when a specific date is reached, adjust the stop date accordingly. YYYY-MM-DD\nIf you are updating an existing database, the parser will automatically stop when it reaches the last\nknown commit found in the database OR when the stop date you provide is reached. Whichever\nhappens first.").pack(side='left',padx=5,pady=10)
        self.parse_btn = ttk.Button(frm4,text="Parse log",width=20,command=self.parse_clicked)
        self.parse_btn.pack(side='left',padx=5,pady=10)
        self.label7 = ttk.Label(frm4,text="Stop date:").pack(side='left',padx=20,pady=10)
        self.stop_year_box = ttk.Combobox(frm4,width=5,state='readonly',values=(range(2001,2020)))
        self.stop_year_box.pack(side='left',padx=2,pady=10)
        date_slash = ttk.Label(frm4,text='-').pack(side='left',padx=2,pady=10)
        self.stop_month_box = ttk.Combobox(frm4,width=3,state='readonly',values=(["%.2d"%i for i in range(1,13)]))
        self.stop_month_box.pack(side='left',padx=2,pady=10)
        date_slash2 = ttk.Label(frm4,text='-').pack(side='left',padx=2,pady=10)
        self.stop_date_box = ttk.Combobox(frm4,width=3,state='readonly',values=(["%.2d"%i for i in range(1,32)]))
        self.stop_date_box.pack(side='left',padx=2,pady=10)       
        self.label4 = ttk.Label(frm5,text="Once parsing/database generation completes, click on the Scan for restricted button. This will attempt\nto scan for all bugs that are protected. This can take a long time. You can throttle the slider below\nto adjust the scanning speed. This represents how many threads the scanner will spawn. The default\nis 12 and should be ok for most systems. Throttle this down if the scanning process fails. After\nthis completes, switch to the results tab at the top and click the refresh list button.").pack(side='left',padx=5,pady=10)
        self.scan_btn = ttk.Button(frm6,text="Scan for restricted bugs",width=20,command=self.scan_clicked)
        self.scan_btn.pack(side='left',padx=5,pady=10)
        self.label6 = ttk.Label(frm6,text="Throttle:").pack(side='left',padx=20,pady=10)
        self.throttler = tk.Scale(frm6,from_=1,to=15, length=325,tickinterval=1, orient='horizontal')
        self.throttler.pack(side='left',padx=1,pady=10)
        self.stop_scan_btn = ttk.Button(frm7,text='Stop scanning',width=20,command=self.stop_scan_clicked)
        self.stop_scan_btn.pack(side='left',padx=5)
        
        frm1.grid(column=1,row=1,padx=10,sticky='w')
        frm2.grid(column=1,row=2,padx=10,sticky='w')
        frm3.grid(column=1,row=3,padx=10,sticky='w')
        frm4.grid(column=1,row=4,padx=10,sticky='w')
        frm5.grid(column=1,row=5,padx=10,sticky='w')
        frm6.grid(column=1,row=6,padx=10,sticky='w')
        frm7.grid(column=1,row=7,padx=10,sticky='nw')
        self.stop_year_box.current(11)
        self.stop_month_box.current(9)
        self.stop_date_box.current(15)
        self.throttler.set(12)

        # Populate tab3
        frm8 = ttk.Frame(tab3)
        frm9 = ttk.Frame(tab3)   
        self.commit_view_box = tk.Listbox(frm8, height=39,width=35)
        self.commit_view_box.pack(fill='both',expand=True)
        self.commit_view_box.bind("<<ListboxSelect>>", self.commit_selected)
        self.commit_view_scrollbar = ttk.Scrollbar(self.commit_view_box,orient='vertical')
        self.commit_view_scrollbar.pack(side='right',fill='y')
        self.commit_view_box.config(yscrollcommand=self.commit_view_scrollbar.set)
        self.commit_view_scrollbar.config(command=self.commit_view_box.yview)
        self.results_box = ScrolledText(frm9,height=42,width=75,wrap='word')        
        self.results_box.pack(fill='both',expand=True)
        self.refresh_btn = ttk.Button(frm8,text='Refresh list',width=20,command=self.refresh_clicked)
        self.refresh_btn.pack(side='bottom',padx=50)
        frm8.pack(side='left',fill='both',expand=True)
        frm9.pack(side='right',fill='both',expand=True)

        # Populate tab4
        frm10 = ttk.Frame(tab4)
        frm11 = ttk.Frame(tab4)
        frm12 = ttk.Frame(tab4)
        frm13 = ttk.Frame(tab4)
        frm14 = ttk.Frame(tab4)
        frm15 = ttk.Frame(tab4)
        frm16 = ttk.Frame(tab4) 
        self.label6 = ttk.Label(frm10,text="Please enter your local IP address into the box below. You can attempt to grab your\nIP address automatically by clicking the Get my IP button.").pack(side='left',padx=5,pady=10)
        iplbl = ttk.Label(frm11,text='IP:').pack(side='left',padx=5,pady=10)
        self.localip_entry = ttk.Entry(frm11,width=30)
        self.localip_entry.pack(side='left',padx=5,pady=10)
        self.getip_btn = ttk.Button(frm11,text="Get my IP",width=20,command=self.getip_clicked)
        self.getip_btn.pack(side='left',padx=10,pady=10)
        self.label7 = ttk.Label(frm12,text="Next, provide the path to the layout tests directory below.").pack(side='left',padx=5,pady=10)
        self.label8 = ttk.Label(frm13,text="Path:").pack(side='left',padx=5,pady=10)
        self.layouttests_path = ttk.Entry(frm13, width=30)
        self.layouttests_path.pack(side='left',padx=5,pady=10)
        self.browse2_btn = ttk.Button(frm13,text="Browse..",command=self.browse2_clicked)
        self.browse2_btn.pack(side='left',padx=10,pady=10)
        self.label9 = ttk.Label(frm14,text="Now, simply switch to the results view and copy/paste the location of the layout test\nfile below. Then click the Host file button, This will rename and host the file as\nindex.html on port 8000, once hosting, point the console browser to\nyour_local_ip_address:8000. Be sure to stop the server when done").pack(side='left',padx=5,pady=10)
        self.label10 = ttk.Label(frm15,text="Paste:").pack(side='left',padx=5,pady=10)
        self.hostfile_entry = ttk.Entry(frm15, width=60)
        self.hostfile_entry.pack(side='left',padx=10,pady=10)
        self.host_btn = ttk.Button(frm16,text="Host file",width=20,command=self.host_file_clicked)
        self.host_btn.pack(side='left',padx=40,pady=10)
        self.stop_srvr_btn = ttk.Button(frm16,text="Stop server",width=20,command=self.stop_srvr_clicked)
        self.stop_srvr_btn.pack(side='left',padx=40,pady=10)
        frm10.grid(column=1,row=1,padx=10,sticky='w')
        frm11.grid(column=1,row=2,padx=10,sticky='w')
        frm12.grid(column=1,row=3,padx=10,sticky='w')
        frm13.grid(column=1,row=4,padx=10,sticky='w')
        frm14.grid(column=1,row=5,padx=10,sticky='w')
        frm15.grid(column=1,row=6,padx=10,sticky='w')
        frm16.grid(column=1,row=7,padx=10,sticky='w')
class RootWindow(tk.Tk):
    newthread=False
    scan_running=False
    commit_track_list = []
    def __init__(self,*args,**kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        self.build_window()

    def build_window(self):
        # Build the Notebook widget
        n = ttk.Notebook(self)
        tab1 = ttk.Frame(n)
        tab2 = ttk.Frame(n)
        tab3 = ttk.Frame(n)
        tab4 = ttk.Frame(n)
        n.add(tab1,text="Welcome1")
        n.add(tab2,text="Parser")
        n.add(tab3,text="Results")
        n.add(tab4,text="Hosting")
        n.pack(fill="both", expand=True)

        # Populate tab1
        t1_frm1 = ttk.Frame(tab1)   
        t1_frm2 = ttk.Frame(tab1)
        t1_label1 = ttk.Label(t1_frm1,text="Welcome to the Webkit Bug Finder. This program will parse a WebKit SVN changelog and find all bugs that are\n\
restricted from public view. It stores the changelog information for each bug into a database so that the\n\
program can show you each bug and its associated committ log. Most of these will contain details about\n\
what triggers the bug. Many will also contain layout test paths to trigger the bug. These layout tests are\n\
contained in your updated local WebKit repo and can be hosted by this program using the hosting tab above.\n\
Once hosted, you can navigate your WebKit based browser to your_IP_address:8000 to see if the browser is\n\
affected by the bug. This is how it works:\n\n\
\n1: Update your local copy of WebKit repo by running Tools"+dir_slash+"Scripts"+dir_slash+"update-webkit\n\n\
2: You will need to have Subversion installed and obtain a svn changelog by navigating\n\
    to the root of your WebKit directory and running: svn log > any_filename.txt\n\n\
3: Once you have the svn changelog, you can parse and scan it following the instructions\n\
    in the parser tab. If this is the first time running the program, a new database will be\n\
    generated. If you already have a database, it will be updated each time you repeat this\n\
    process. Once a scan has completed it can take a while to write the results to the database.\n\
    You will see a 'Done' message in the terminal window when it has completed. ").pack(side='left',padx=5,pady=10)
        
        self.updt_wbkt_btn=ttk.Button(t1_frm2,text="Update WebKit",command=self.updt_wbkt_clicked).pack()
        t1_frm1.grid(column=1,row=1,padx=10,sticky='w')
        t1_frm2.grid(column=1,row=2,padx=10,sticky='sw')
        # Populate tab2
        frm1 = ttk.Frame(tab2)
        frm2 = ttk.Frame(tab2)
        frm3 = ttk.Frame(tab2)
        frm4 = ttk.Frame(tab2)
        frm5 = ttk.Frame(tab2)
        frm6 = ttk.Frame(tab2)
        frm7 = ttk.Frame(tab2)
        self.label1 = ttk.Label(frm1,text="Enter the path to the .txt log file you want to parse, or click Browse below.").pack(side='left',padx=5,pady=10)
        self.label2 = ttk.Label(frm2,text="Path:").pack(side='left',padx=5,pady=10)
        self.log_file_path = ttk.Entry(frm2, width=35)
        self.log_file_path.pack(side='left',padx=5,pady=10)
        self.browse_btn = ttk.Button(frm2,text="Browse..",command=self.browse_clicked).pack(side='left',padx=5,pady=10)
        self.label3 = ttk.Label(frm3,text="Once you've provided a valid path above, click on the Parse log button. This will parse the log file\ninto seperate commit entries and generate a database file to work with. This will take a few seconds.\nTo stop parsing when a specific date is reached, adjust the stop date accordingly. YYYY-MM-DD\nIf you are updating an existing database, the parser will automatically stop when it reaches the last\nknown commit found in the database OR when the stop date you provide is reached. Whichever\nhappens first.").pack(side='left',padx=5,pady=10)
        self.parse_btn = ttk.Button(frm4,text="Parse log",width=20,command=self.parse_clicked)
        self.parse_btn.pack(side='left',padx=5,pady=10)
        self.label7 = ttk.Label(frm4,text="Stop date:").pack(side='left',padx=20,pady=10)
        self.stop_year_box = ttk.Combobox(frm4,width=5,state='readonly',values=(range(2001,2020)))
        self.stop_year_box.pack(side='left',padx=2,pady=10)
        date_slash = ttk.Label(frm4,text='-').pack(side='left',padx=2,pady=10)
        self.stop_month_box = ttk.Combobox(frm4,width=3,state='readonly',values=(["%.2d"%i for i in range(1,13)]))
        self.stop_month_box.pack(side='left',padx=2,pady=10)
        date_slash2 = ttk.Label(frm4,text='-').pack(side='left',padx=2,pady=10)
        self.stop_date_box = ttk.Combobox(frm4,width=3,state='readonly',values=(["%.2d"%i for i in range(1,32)]))
        self.stop_date_box.pack(side='left',padx=2,pady=10)       
        self.label4 = ttk.Label(frm5,text="Once parsing/database generation completes, click on the Scan for restricted button. This will attempt\nto scan for all bugs that are protected. This can take a long time. You can throttle the slider below\nto adjust the scanning speed. This represents how many threads the scanner will spawn. The default\nis 12 and should be ok for most systems. Throttle this down if the scanning process fails. After\nthis completes, switch to the results tab at the top and click the refresh list button.").pack(side='left',padx=5,pady=10)
        self.scan_btn = ttk.Button(frm6,text="Scan for restricted bugs",width=20,command=self.scan_clicked)
        self.scan_btn.pack(side='left',padx=5,pady=10)
        self.label6 = ttk.Label(frm6,text="Throttle:").pack(side='left',padx=20,pady=10)
        self.throttler = tk.Scale(frm6,from_=1,to=15, length=325,tickinterval=1, orient='horizontal')
        self.throttler.pack(side='left',padx=1,pady=10)
        self.stop_scan_btn = ttk.Button(frm7,text='Stop scanning',width=20,command=self.stop_scan_clicked)
        self.stop_scan_btn.pack(side='left',padx=5)
        
        frm1.grid(column=1,row=1,padx=10,sticky='w')
        frm2.grid(column=1,row=2,padx=10,sticky='w')
        frm3.grid(column=1,row=3,padx=10,sticky='w')
        frm4.grid(column=1,row=4,padx=10,sticky='w')
        frm5.grid(column=1,row=5,padx=10,sticky='w')
        frm6.grid(column=1,row=6,padx=10,sticky='w')
        frm7.grid(column=1,row=7,padx=10,sticky='nw')
        self.stop_year_box.current(11)
        self.stop_month_box.current(9)
        self.stop_date_box.current(15)
        self.throttler.set(12)

        # Populate tab3
        frm8 = ttk.Frame(tab3)
        frm9 = ttk.Frame(tab3)   
        self.commit_view_box = tk.Listbox(frm8, height=39,width=35)
        self.commit_view_box.pack(fill='both',expand=True)
        self.commit_view_box.bind("<<ListboxSelect>>", self.commit_selected)
        self.commit_view_scrollbar = ttk.Scrollbar(self.commit_view_box,orient='vertical')
        self.commit_view_scrollbar.pack(side='right',fill='y')
        self.commit_view_box.config(yscrollcommand=self.commit_view_scrollbar.set)
        self.commit_view_scrollbar.config(command=self.commit_view_box.yview)
        self.results_box = ScrolledText(frm9,height=42,width=75,wrap='word')        
        self.results_box.pack(fill='both',expand=True)
        self.refresh_btn = ttk.Button(frm8,text='Refresh list',width=20,command=self.refresh_clicked)
        self.refresh_btn.pack(side='bottom',padx=50)
        frm8.pack(side='left',fill='both',expand=True)
        frm9.pack(side='right',fill='both',expand=True)

        # Populate tab4
        frm10 = ttk.Frame(tab4)
        frm11 = ttk.Frame(tab4)
        frm12 = ttk.Frame(tab4)
        frm13 = ttk.Frame(tab4)
        frm14 = ttk.Frame(tab4)
        frm15 = ttk.Frame(tab4)
        frm16 = ttk.Frame(tab4) 
        self.label6 = ttk.Label(frm10,text="Please enter your local IP address into the box below. You can attempt to grab your\nIP address automatically by clicking the Get my IP button.").pack(side='left',padx=5,pady=10)
        iplbl = ttk.Label(frm11,text='IP:').pack(side='left',padx=5,pady=10)
        self.localip_entry = ttk.Entry(frm11,width=30)
        self.localip_entry.pack(side='left',padx=5,pady=10)
        self.getip_btn = ttk.Button(frm11,text="Get my IP",width=20,command=self.getip_clicked)
        self.getip_btn.pack(side='left',padx=10,pady=10)
        self.label7 = ttk.Label(frm12,text="Next, provide the path to the layout tests directory below.").pack(side='left',padx=5,pady=10)
        self.label8 = ttk.Label(frm13,text="Path:").pack(side='left',padx=5,pady=10)
        self.layouttests_path = ttk.Entry(frm13, width=30)
        self.layouttests_path.pack(side='left',padx=5,pady=10)
        self.browse2_btn = ttk.Button(frm13,text="Browse..",command=self.browse2_clicked)
        self.browse2_btn.pack(side='left',padx=10,pady=10)
        self.label9 = ttk.Label(frm14,text="Now, simply switch to the results view and copy/paste the location of the layout test\nfile below. Then click the Host file button, This will rename and host the file as\nindex.html on port 8000, once hosting, point the console browser to\nyour_local_ip_address:8000. Be sure to stop the server when done").pack(side='left',padx=5,pady=10)
        self.label10 = ttk.Label(frm15,text="Paste:").pack(side='left',padx=5,pady=10)
        self.hostfile_entry = ttk.Entry(frm15, width=60)
        self.hostfile_entry.pack(side='left',padx=10,pady=10)
        self.host_btn = ttk.Button(frm16,text="Host file",width=20,command=self.host_file_clicked)
        self.host_btn.pack(side='left',padx=40,pady=10)
        self.stop_srvr_btn = ttk.Button(frm16,text="Stop server",width=20,command=self.stop_srvr_clicked)
        self.stop_srvr_btn.pack(side='left',padx=40,pady=10)
        frm10.grid(column=1,row=1,padx=10,sticky='w')
        frm11.grid(column=1,row=2,padx=10,sticky='w')
        frm12.grid(column=1,row=3,padx=10,sticky='w')
        frm13.grid(column=1,row=4,padx=10,sticky='w')
        frm14.grid(column=1,row=5,padx=10,sticky='w')
        frm15.grid(column=1,row=6,padx=10,sticky='w')
        frm16.grid(column=1,row=7,padx=10,sticky='w')

    # Behavior for button clicks in all tabs of root window.
    def updt_wbkt_clicked(self):
        print('not working yet')
        users_home = os.path.expanduser('~')
        wk = users_home+dir_slash+'WebKit'
        print(users_home)
        if os.path.isdir(wk):
            print('webkit directory exists at: '+wk)
        else:
            print('webkit was not present at: '+wk)
        
    def browse_clicked(self):
        log_path = filedialog.askopenfilename()
        self.log_file_path.delete('0',tk.END)
        self.log_file_path.insert('end',log_path)
   
    def browse2_clicked(self):        
        tests_directory = filedialog.askdirectory()
        self.layouttests_path.delete('0',tk.END)
        self.layouttests_path.insert('end',tests_directory)

    def start_server(self, path_to_host, local_ip, layout_loc, file_path):
        if not self.newthread:
                self.newthread = ServerThread(local_ip, path_to_host, layout_loc, file_path)
                self.newthread.daemon=True
                self.newthread.start()
                while True:
                    
                    if self.newthread.finished == True:
                        message.showinfo('Done','Now hosting '+ path_to_host + ' as\nindex.html @ '+str(self.newthread.serv_info[0])+":"+str(self.newthread.serv_info[1]))
                        break
                        
        else:
            message.showerror('Error','Server is already running.')
            print('server is running')
     
    def stop_srvr_clicked(self):
        if self.newthread:
            self.newthread.server.shutdown()
            self.newthread = False
            print('server stopped')
        else:
            print('server not found running')

    
    def getip_clicked(self):
        ip = ''
        if os.name == 'posix':
            ip = commands.getoutput("hostname -I")
            print(ip)
        elif os.name == 'nt':
            ip = socket.gethostbyname(socket.gethostname())
            print(ip)
        else:
            print('couldnt get local ip')
        self.localip_entry.delete('0',tk.END)
        self.localip_entry.insert('end',ip)
            
         

    def parse_clicked(self):
        try:
            log_path = open(self.log_file_path.get())
        except Exception as e:
            print(e)
            log_path=None
        if log_path != None:
            try:
                stop_date = self.stop_year_box.get()+'-'+self.stop_month_box.get()+'-'+self.stop_date_box.get()             
                self.parsed_log = LogParser(log_path,stop_date)
                self.commit_list = self.parsed_log.commit_list
                self.entry_count = self.parsed_log.entry_count
                message.showinfo('Complete','Operation is complete')
            except Exception as e:
                print(e)
                message.showerror('Error','Something went wrong parsing the log.')
        else:
            message.showerror('Error','You did not provide a file name or the file name is invalid.')

    def scan_clicked(self):
        if not self.scan_running:
                throttle_value = self.throttler.get()
                self.html_thread = HTMLScraper(int(throttle_value))
                self.html_thread.daemon=True
                self.html_thread.start()

    def stop_scan_clicked(self):
        print 'stop scanning'
        try:
            self.html_thread.abort = True
        except Exception as e:
            print(e.args)

    def refresh_clicked(self):
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs WHERE restricted == 1")
        self.commit_view_box.configure(state='normal')
        self.commit_view_box.delete('0',tk.END)
        for i in cursor:
            self.commit_view_box.insert('end',i[1]+' | '+i[2])
            self.commit_track_list.append(i[1])
        db.close()
    '''
    def stripdb_clicked(self):
        
        db_id = []
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs")
        try:
            for i in cursor:
                if i[4] != 1:
                    db_id.append(i[0])
            for i in db_id:
                cursor.execute("DELETE FROM logs WHERE id = ?",(str(i),))
        except Exception as e:
            print(e)
            message.showerror('Error','Something went wrong stripping the database.')
        message.showinfo('Complete','Operation complete')
        db.commit()
        db.close()
    '''
    def host_file_clicked(self):
        self.stop_srvr_clicked()
        local_ip = self.localip_entry.get()
        layout_loc = self.layouttests_path.get()
        if os.name =='nt':
                    layout_loc=layout_loc.replace('/',dir_slash)
        if local_ip != '':
            if layout_loc != '':
                file_path = self.hostfile_entry.get()
                if os.name =='nt':
                    file_path=file_path.replace('/',dir_slash)
                alt_file_path = layout_loc + dir_slash + file_path
                print('the file path : ' + file_path)
                if file_path != '':
                    try:
                        if os.path.isfile(alt_file_path):
                            self.start_server(alt_file_path, local_ip, layout_loc, file_path)
                            #self.copy_host_file(alt_file_path)
                            print('found file')
                            #message.showinfo('Done','Now hosting '+ alt_file_path)
                        else:
                            message.showerror('Error','File was not found.')
                    except Exception as e:
                        print(e)                       
                else:
                    message.showerror('Error','All fields are required.')    
            else:
                message.showerror('Error','All fields are required.')
        else:
            message.showerror('Error','All fields are required.')
    '''
    def copy_host_file(self,file_to_host):
        filename = "index.html"
        try:
            shutil.copyfile(file_to_host, filename)
        except Exception as e:
            print(e)
    '''
    # Behavior for the commit_view_box listbox selections.
    def commit_selected(self,event):
        self.results_box.delete('0.0',tk.END)    
        current = self.commit_view_box.curselection()
        activate_current = self.commit_view_box.activate(current)
        get_selection = current[0]
        #print "Selection", get_selection
        #print "Item", self.commit_track_list
        db = sqlite3.connect(db_name)
        cursor = db.cursor()
        cursor.execute("SELECT * FROM logs WHERE revision = ?",(self.commit_track_list[int(get_selection)],))
        results = cursor.fetchall()
        #print results
        if len(results) > 0:
             for result in results:
                lid,rvn,date,url,info,rst,scnd  = result
                #print "RVN:",rvn
                #print "DATE:",c
                #print "URL:",d
                try:
                    lid,rvn,date,url,info,rst,scnd = result
                    meta = rvn + '| ' + date + ' | ' + url
                    delimeter = '_'*55
                    self.results_box.insert('end','\n'.join([meta,delimeter,(info+ "\n")]))
                except Exception as e:
                    print e.args
                
        cursor.close()
        db.close()