<s> import subprocess <EOL> import threading <EOL> import tkFont <EOL> import ttk <EOL> import webbrowser <EOL> from os import makedirs <EOL> from os . path import exists , expanduser , join as path_join <EOL> from sys import path as sys_path <EOL> from Tkinter import * <EOL> sys_path . append ( '<STR_LIT>' ) <EOL> from PIL import ImageTk , Image <EOL> HomeFolder = expanduser ( "<STR_LIT>" ) <EOL> DATA_ROOT_FOLDER = path_join ( HomeFolder , "<STR_LIT>" ) <EOL> class MongoApp ( ) : <EOL> pidPath = path_join ( DATA_ROOT_FOLDER , '<STR_LIT>' , '<STR_LIT>' ) <EOL> dbPath = path_join ( DATA_ROOT_FOLDER , '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> def __init__ ( self , maxConns = <NUM_LIT:10> , noauth = True ) : <EOL> self . maxConns = maxConns <EOL> self . noauth = noauth <EOL> self . CreateQuery ( ) <EOL> def CreateQuery ( self ) : <EOL> self . MongoQuery = '<STR_LIT>' + str ( self . pidPath ) + '<STR_LIT>' + str ( self . maxConns ) + '<STR_LIT>' + str ( self . dbPath ) <EOL> if self . noauth : <EOL> self . MongoQuery += '<STR_LIT>' <EOL> def StartMongo ( self ) : <EOL> query = "<STR_LIT>" + self . MongoQuery <EOL> MongoProcess = subprocess . Popen ( [ query ] , stdin = subprocess . PIPE , <EOL> stdout = subprocess . PIPE , <EOL> stderr = subprocess . PIPE , <EOL> shell = True ) <EOL> return MongoProcess <EOL> def Start ( self ) : <EOL> SM = threading . Thread ( target = self . StartMongo , args = ( ) ) <EOL> SM . start ( ) <EOL> class Application ( Frame ) : <EOL> Mongo = MongoApp ( maxConns = <NUM_LIT:100> ) <EOL> Status = <NUM_LIT:0> <EOL> def __init__ ( self , master = None ) : <EOL> Frame . __init__ ( self , master ) <EOL> self . pack ( expand = <NUM_LIT:0> , fill = '<STR_LIT>' , padx = <NUM_LIT:10> , pady = <NUM_LIT:10> ) <EOL> self . ConsoleLogFrame = Frame ( master ) <EOL> self . ConsoleLogFrame . pack ( expand = <NUM_LIT:1> , fill = '<STR_LIT>' ) <EOL> self . ActiveIconImage = ImageTk . PhotoImage ( <EOL> Image . open ( "<STR_LIT>" ) ) <EOL> self . ErrorIconImage = ImageTk . PhotoImage ( <EOL> Image . open ( "<STR_LIT>" ) ) <EOL> self . OffIconImage = ImageTk . PhotoImage ( <EOL> Image . open ( "<STR_LIT>" ) ) <EOL> self . MongoDBLogo = ImageTk . PhotoImage ( <EOL> Image . open ( "<STR_LIT>" ) ) <EOL> self . menubar = Menu ( self ) <EOL> MenuRoot = Menu ( master , tearoff = <NUM_LIT:0> ) <EOL> MenuBar = Menu ( MenuRoot , tearoff = <NUM_LIT:0> ) <EOL> MenuBar . add_command ( label = "<STR_LIT>" , command = self . LinkGitHubPage ) <EOL> MenuBar . add_command ( label = "<STR_LIT>" , command = self . LinkMongoDBDocs ) <EOL> MenuRoot . add_cascade ( label = "<STR_LIT>" , menu = MenuBar ) <EOL> master . config ( menu = MenuRoot ) <EOL> self . CreateWidgets ( ) <EOL> master . protocol ( "<STR_LIT>" , self . QuitEvent ) <EOL> def LinkGitHubPage ( self ) : <EOL> webbrowser . open ( '<STR_LIT>' ) <EOL> def LinkMongoDBDocs ( self ) : <EOL> webbrowser . open ( '<STR_LIT>' ) <EOL> def OpenDBFolder ( self ) : <EOL> subprocess . call ( [ "<STR_LIT>" , DATA_ROOT_FOLDER + "<STR_LIT>" ] ) <EOL> def StartServer ( self ) : <EOL> self . MongoObject = self . Mongo . StartMongo ( ) <EOL> SStatus = <NUM_LIT:0> <EOL> while True : <EOL> Line = self . MongoObject . stdout . readline ( ) <EOL> self . AppendLog ( Line ) <EOL> if str ( self . MongoObject . poll ( ) ) == '<STR_LIT:None>' : <EOL> self . IconPanel . config ( image = self . ActiveIconImage ) <EOL> self . Status = <NUM_LIT:1> <EOL> SStatus = <NUM_LIT:1> <EOL> elif str ( self . MongoObject . poll ( ) ) == '<STR_LIT:100>' : <EOL> SStatus = <NUM_LIT:0> <EOL> else : <EOL> self . IconPanel . config ( image = self . OffIconImage ) <EOL> if not Line : <EOL> break <EOL> self . Status = <NUM_LIT:0> <EOL> self . MongoObject . stdout . close ( ) <EOL> if SStatus == <NUM_LIT:0> : <EOL> self . StopButton [ "<STR_LIT:state>" ] = DISABLED <EOL> self . StartButton [ "<STR_LIT:state>" ] = NORMAL <EOL> self . IconPanel . config ( image = self . ErrorIconImage ) <EOL> self . AppendLog ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . AppendLog ( "<STR_LIT>" <EOL> "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . AppendLog ( "<STR_LIT>" , <EOL> '<STR_LIT>' ) <EOL> def StartServerMulti ( self ) : <EOL> self . StartButton [ "<STR_LIT:state>" ] = DISABLED <EOL> self . StopButton [ "<STR_LIT:state>" ] = NORMAL <EOL> self . AppendLog ( "<STR_LIT>" , '<STR_LIT>' ) <EOL> self . SM = threading . Thread ( target = self . StartServer , args = ( ) ) <EOL> self . SM . setDaemon ( <NUM_LIT:1> ) <EOL> self . SM . start ( ) <EOL> def StopServer ( self ) : <EOL> self . MongoObject . terminate ( ) <EOL> self . StopButton [ "<STR_LIT:state>" ] = DISABLED <EOL> self . StartButton [ "<STR_LIT:state>" ] = NORMAL <EOL> self . Status = <NUM_LIT:0> <EOL> def ClearConsole ( self ) : <EOL> self . LogArea . delete ( "<STR_LIT>" , END ) <EOL> def CreateWidgets ( self ) : <EOL> self . StartButton = Button ( self ) <EOL> self . StartButton [ "<STR_LIT:text>" ] = "<STR_LIT>" <EOL> self . StartButton [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . StartButton [ "<STR_LIT>" ] = self . StartServerMulti <EOL> self . StartButton . pack ( { "<STR_LIT>" : "<STR_LIT:left>" } ) <EOL> self . StopButton = Button ( self ) <EOL> self . StopButton [ "<STR_LIT:text>" ] = "<STR_LIT>" <EOL> self . StopButton [ "<STR_LIT>" ] = self . StopServer <EOL> self . StopButton [ "<STR_LIT:state>" ] = DISABLED <EOL> self . StopButton . pack ( { "<STR_LIT>" : "<STR_LIT:left>" } ) <EOL> self . GetInfo = Button ( self ) <EOL> self . GetInfo [ "<STR_LIT:text>" ] = "<STR_LIT>" <EOL> self . GetInfo [ "<STR_LIT>" ] = self . ClearConsole <EOL> self . GetInfo . pack ( { "<STR_LIT>" : "<STR_LIT:left>" } ) <EOL> self . OpenFolder = Button ( self ) <EOL> self . OpenFolder [ "<STR_LIT:text>" ] = "<STR_LIT>" <EOL> self . OpenFolder [ "<STR_LIT>" ] = self . OpenDBFolder <EOL> self . OpenFolder . pack ( { "<STR_LIT>" : "<STR_LIT:left>" } ) <EOL> self . PoweredMongoPanel = Label ( self , image = self . MongoDBLogo ) <EOL> self . PoweredMongoPanel . image = self . MongoDBLogo <EOL> self . PoweredMongoPanel . pack ( { "<STR_LIT>" : "<STR_LIT:right>" } ) <EOL> self . IconPanel = Label ( self , image = self . OffIconImage ) <EOL> self . IconPanel . image = self . OffIconImage <EOL> self . IconPanel . pack ( { "<STR_LIT>" : "<STR_LIT:right>" } ) <EOL> self . LogArea = Text ( self . ConsoleLogFrame ) <EOL> self . LogArea [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . LogArea [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . LogArea [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . LogArea [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> self . LogArea . insert ( INSERT , "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> self . LogArea . pack ( expand = <NUM_LIT:1> , fill = '<STR_LIT>' ) <EOL> self . LogArea . tag_config ( "<STR_LIT>" , background = "<STR_LIT>" , <EOL> foreground = "<STR_LIT>" ) <EOL> self . LogArea . tag_config ( "<STR_LIT>" , background = "<STR_LIT>" , <EOL> foreground = "<STR_LIT>" , <EOL> font = tkFont . Font ( weight = '<STR_LIT>' ) ) <EOL> def AppendLog ( self , logline , tag = '<STR_LIT:None>' ) : <EOL> if tag == '<STR_LIT:None>' : <EOL> self . LogArea . insert ( END , logline ) <EOL> else : <EOL> self . LogArea . insert ( END , logline , ( tag ) ) <EOL> self . LogArea . see ( '<STR_LIT:end>' ) <EOL> def QuitEvent ( self ) : <EOL> if self . Status == <NUM_LIT:1> : <EOL> self . MongoObject . terminate ( ) <EOL> self . master . destroy ( ) <EOL> self . master . quit ( ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if not exists ( DATA_ROOT_FOLDER ) : <EOL> makedirs ( DATA_ROOT_FOLDER + "<STR_LIT>" ) <EOL> makedirs ( DATA_ROOT_FOLDER + "<STR_LIT>" ) <EOL> root = Tk ( ) <EOL> app = Application ( master = root ) <EOL> app . master . title ( "<STR_LIT>" ) <EOL> app . master . geometry ( "<STR_LIT>" ) <EOL> app . mainloop ( ) </s>
