<s> __author__ = '<STR_LIT>' <EOL> from Tkinter import * <EOL> from tkFileDialog import * <EOL> import threading <EOL> import os <EOL> import re <EOL> from gitana import Gitana <EOL> import traceback <EOL> class UpdateDB_GUI ( Tk ) : <EOL> def __init__ ( self ) : <EOL> Tk . __init__ ( self ) <EOL> self . initialize ( ) <EOL> self . title ( "<STR_LIT>" ) <EOL> self . mainloop ( ) <EOL> def initialize ( self ) : <EOL> emptyLabel = Label ( self , anchor = "<STR_LIT:w>" ) <EOL> emptyLabel . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:1> , sticky = '<STR_LIT>' ) <EOL> labelRepoPath = Label ( self , text = u"<STR_LIT>" , anchor = "<STR_LIT:w>" ) <EOL> labelRepoPath . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:2> , sticky = '<STR_LIT>' ) <EOL> self . repoPathVariable = StringVar ( ) <EOL> self . entryRepoPath = Entry ( self , textvariable = self . repoPathVariable , width = <NUM_LIT:30> ) <EOL> self . entryRepoPath . grid ( column = <NUM_LIT:1> , row = <NUM_LIT:2> , sticky = '<STR_LIT>' ) <EOL> buttonSearchRepo = Button ( self , text = u"<STR_LIT>" , command = self . search_for_directory ) <EOL> buttonSearchRepo . grid ( column = <NUM_LIT:2> , row = <NUM_LIT:2> , sticky = "<STR_LIT:E>" ) <EOL> labelDBName = Label ( self , text = u"<STR_LIT>" , anchor = "<STR_LIT:w>" ) <EOL> labelDBName . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:3> , sticky = '<STR_LIT>' ) <EOL> self . DBNameVariable = StringVar ( ) <EOL> self . entryDBName = Entry ( self , textvariable = self . DBNameVariable , width = <NUM_LIT:30> ) <EOL> self . entryDBName . grid ( column = <NUM_LIT:1> , row = <NUM_LIT:3> , sticky = '<STR_LIT>' ) <EOL> labelBeforeDate = Label ( self , text = u"<STR_LIT>" , anchor = "<STR_LIT:w>" ) <EOL> labelBeforeDate . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:4> , sticky = '<STR_LIT>' ) <EOL> self . beforeDateVariable = StringVar ( ) <EOL> self . beforeDate = Entry ( self , textvariable = self . beforeDateVariable , width = <NUM_LIT:30> ) <EOL> self . beforeDate . grid ( column = <NUM_LIT:1> , row = <NUM_LIT:4> , sticky = '<STR_LIT>' ) <EOL> emptyLabel = Label ( self , anchor = "<STR_LIT:w>" ) <EOL> emptyLabel . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:5> , sticky = '<STR_LIT>' ) <EOL> self . buttonFinish = Button ( self , text = u"<STR_LIT>" , command = self . launch_thread_execute ) <EOL> self . buttonFinish . grid ( column = <NUM_LIT:1> , row = <NUM_LIT:6> , sticky = "<STR_LIT:E>" ) <EOL> self . buttonAbort = Button ( self , text = u"<STR_LIT>" , command = self . launch_thread_interrupt ) <EOL> self . buttonAbort . grid ( column = <NUM_LIT:2> , row = <NUM_LIT:6> , sticky = "<STR_LIT:E>" ) <EOL> self . buttonAbort . config ( state = DISABLED ) <EOL> self . info_execution = StringVar ( ) <EOL> labelExecuting = Label ( self , textvariable = self . info_execution , anchor = "<STR_LIT:w>" ) <EOL> labelExecuting . grid ( column = <NUM_LIT:0> , row = <NUM_LIT:6> , sticky = '<STR_LIT>' ) <EOL> self . resizable ( False , False ) <EOL> def search_for_directory ( self ) : <EOL> dir = askdirectory ( parent = self , title = '<STR_LIT>' ) <EOL> self . repoPathVariable . set ( dir ) <EOL> try : <EOL> repoName = dir . split ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> self . repoNameVariable . set ( re . sub ( r'<STR_LIT>' , '<STR_LIT>' , repoName ) . lower ( ) ) <EOL> except : <EOL> try : <EOL> repoName = dir . split ( '<STR_LIT:\\>' ) [ - <NUM_LIT:1> ] <EOL> self . repoNameVariable . set ( re . sub ( r'<STR_LIT>' , '<STR_LIT>' , repoName ) . lower ( ) ) <EOL> except : <EOL> repoName = '<STR_LIT>' <EOL> def launch_thread_execute ( self ) : <EOL> self . info_execution . set ( "<STR_LIT>" ) <EOL> self . buttonFinish . config ( state = DISABLED ) <EOL> self . buttonAbort . config ( state = NORMAL ) <EOL> self . thread_execute = threading . Thread ( target = self . validator_import ) <EOL> self . thread_execute . daemon = True <EOL> self . thread_execute . start ( ) <EOL> def launch_thread_interrupt ( self ) : <EOL> self . buttonFinish . config ( state = DISABLED ) <EOL> self . buttonAbort . config ( state = NORMAL ) <EOL> self . thread_interrupt = threading . Thread ( target = self . interrupt ) <EOL> self . thread_interrupt . daemon = True <EOL> self . thread_interrupt . start ( ) <EOL> self . thread_interrupt . join ( ) <EOL> def validator_import ( self ) : <EOL> flag = True <EOL> if self . repoPathVariable . get ( ) == "<STR_LIT>" : <EOL> self . repoPathVariable . set ( "<STR_LIT>" ) <EOL> flag = False <EOL> else : <EOL> if not self . check_path_existance ( self . repoPathVariable . get ( ) ) : <EOL> self . repoPathVariable . set ( "<STR_LIT>" ) <EOL> flag = False <EOL> if self . DBNameVariable . get ( ) == "<STR_LIT>" : <EOL> self . DBNameVariable . set ( "<STR_LIT>" ) <EOL> flag = False <EOL> else : <EOL> self . DBNameVariable . set ( re . sub ( r'<STR_LIT>' , '<STR_LIT>' , self . DBNameVariable . get ( ) ) . lower ( ) ) <EOL> if flag : <EOL> self . execute_update ( ) <EOL> def interrupt ( self ) : <EOL> self . info_execution . set ( "<STR_LIT>" ) <EOL> sys . exc_clear ( ) <EOL> sys . exc_traceback = sys . last_traceback = None <EOL> os . _exit ( - <NUM_LIT:1> ) <EOL> def check_path_existance ( self , string ) : <EOL> flag = True <EOL> if not os . path . exists ( string ) : <EOL> flag = False <EOL> return flag <EOL> def execute_update ( self ) : <EOL> try : <EOL> self . REPO_PATH = self . repoPathVariable . get ( ) <EOL> self . DBNAME = self . DBNameVariable . get ( ) <EOL> g = Gitana ( self . DBNAME ) <EOL> g . updatedb ( self . DBNAME , self . REPO_PATH ) <EOL> self . info_execution . set ( "<STR_LIT>" ) <EOL> self . buttonFinish . config ( state = NORMAL ) <EOL> self . buttonAbort . config ( state = DISABLED ) <EOL> except : <EOL> print traceback . format_exc ( ) <EOL> self . info_execution . set ( "<STR_LIT>" ) <EOL> self . buttonFinish . config ( state = NORMAL ) <EOL> self . buttonAbort . config ( state = DISABLED ) <EOL> def start_export ( self ) : <EOL> label = Label ( self , text = id ) <EOL> label . pack ( side = "<STR_LIT>" , fill = "<STR_LIT>" , padx = <NUM_LIT:10> , pady = <NUM_LIT:10> ) <EOL> def main ( ) : <EOL> UpdateDB_GUI ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
