def InputRPI(): usePiCam = None useRPI = None while useRPI == None: inspectThisRPI = input(inputRPI) if isblank(inspectThisRPI) : useRPI = True elif not stb(inspectThisRPI) : useRPI = False elif stb(inspectThisRPI) : useRPI = True else : useRPI = None # If user stated that they will use Raspbery PI # ask them again if they are using PiCamera or # USB camera. if useRPI: while usePiCam == None: inspectThisPiCam = input(inputPiCam) if isblank(inspectThisPiCam) : usePiCam = True elif not stb(inspectThisPiCam) : usePiCam = False elif stb(inspectThisPiCam) : usePiCam = True else : usePiCam = None else: usePiCam = False return [useRPI, usePiCam]
def InputSave(_docArgs): doYouWantToSave = None while doYouWantToSave == None: inspectThis = input("\n" + inputSave) if isblank(inspectThis) : doYouWantToSave = True elif not stb(inspectThis) : doYouWantToSave = False elif stb(inspectThis) : doYouWantToSave = True else : doYouWantToSave = None if doYouWantToSave: assignallconfigrtv(_docArgs, _config, _configAbsPath)
def InputBoolReverse(_input, _confVar): legal = False while not legal: inspectThis = input(_input) if isblank(inspectThis): _confVar[2] = True elif not stb(inspectThis): _confVar[2] = False elif stb(inspectThis): _confVar[2] = True else: _confVar[2] = None if _confVar[2] != None: legal = True
def Set(_docArgs, _config, _configAbsPath): def SaveValueMod0(_configEntryName, _value): sv(_config, _configAbsPath, _docArgs, 0, _configEntryName, _value) def SaveValueMod2(_configEntryName, _value): sv(_config, _configAbsPath, _docArgs, 2, _configEntryName, _value) inputFailed = False if _docArgs.get("--cname"): value = _docArgs.get("--cname")[0] if isanum(value): SaveValueMod0(_config.clientName[0], value) else: inputFailed = True print("--cname") if _docArgs.get("--dba"): value = _docArgs.get("--dba")[0] if isanumdot(value): SaveValueMod0(_config.dbAddress[0], value) else: inputFailed = True print("--dba") if _docArgs.get("--dbn"): value = _docArgs.get("--dbn")[0] if isanumuscore(value): SaveValueMod0(_config.dbName[0], str(value).lower()) else: inputFailed = True print("--dbn") if _docArgs.get("--dbp"): value = _docArgs.get("--dbp")[0] if isnum(value): SaveValueMod0(_config.dbPort[0], value) else: inputFailed = True print("--dbp") if _docArgs.get("--irc"): value = _docArgs.get("--irc")[0] if isanumuscore(value): SaveValueMod0(_config.irCode[0], str(value).upper()) else: inputFailed = True print("--irc") if _docArgs.get("--cvgui"): currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutOCVGUI[0])) changedValue = not currentValueInConfigFile SaveValueMod2(_config.withoutOCVGUI[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--cvgui") if _docArgs.get("--db"): # I need to get the value first. currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutDB[0])) # After I get the boolean value then I need # to invert the value. changedValue = not currentValueInConfigFile # After I invert the value I need to write the value # back into `config.ini` file. SaveValueMod2(_config.withoutDB[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--db") if _docArgs.get("--faced"): currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutFaceD[0])) changedValue = not currentValueInConfigFile SaveValueMod2(_config.withoutFaceD[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--faced") if _docArgs.get("--ird"): currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutIRD[0])) changedValue = not currentValueInConfigFile SaveValueMod2(_config.withoutIRD[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--ird") if _docArgs.get("--log"): currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutLog[0])) changedValue = not currentValueInConfigFile SaveValueMod2(_config.withoutLog[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--log") if _docArgs.get("--pvd"): currentValueInConfigFile = stb( getvaluefromconfig(_configAbsPath, _config.iniSections[2], _config.withoutPVD[0])) changedValue = not currentValueInConfigFile SaveValueMod2(_config.withoutPVD[0], changedValue) #print(currentValueInConfigFile) #print(changedValue) #print("--pvd") if inputFailed: print("\ninput failed\n")
def DocoptControl(self, _docArgs, _config, _configAbsPath, _logFolderAbsPath): # This variable need to be here so that `show --config` # will not return twice `showcf(_config, _configAbsPath)`. configFileShown = False # This variable is to indicate if this application will # continued into main infinite loop after Docopt CLI. continueProgramToMainLoop = False # If `config.ini` is deleted or not. deletedConfig = False # Check if user choose to start with Raspberry PI Raspbian. raspberryPI = [False, False] # Get `first_run` value from `config.ini`. firstRun = stb( gvfc(_configAbsPath, _config.iniSections[1], _config.firstRun[0])) if _docArgs.get("reset"): # For reset we need to get connection to database to delete all table # and also to delete the config.ini file in the root of this project # directory. if _docArgs.get("--dbl"): ddl(_config, _configAbsPath, _logFolderAbsPath) # Delete the `config.ini` and then give `True` into the `deletedConfig`. deletedConfig = dc(_configAbsPath) if _docArgs.get("set"): # Set to all default variables. if _docArgs.get("all-default"): assignallconfigdefault(_docArgs, _config, _configAbsPath) # Set everything manually. else: ss(_docArgs, _config, _configAbsPath) # If user ever once set something than prevent # wizard from appearing when `start` command # inputted sv(_config, _configAbsPath, _docArgs, 1, _config.firstRun[0], False) _config.firstRun[2] = False if _docArgs.get("show") and _docArgs.get("--config"): configFileShown = True showcf(_config, _configAbsPath) if _docArgs.get("start"): if firstRun: # Start the wizard. sWI = swi(_docArgs, _config, _configAbsPath) raspberryPI = [sWI[0], sWI[1]] sv(_config, _configAbsPath, _docArgs, 1, _config.firstRun[0], False) _config.firstRun[2] = False else: # `start all-default` let user to # use default components (using all # inputs and detections). And as well # as database setting variables. if _docArgs.get("all-default"): raspberryPI = sad(_docArgs, _config, _configAbsPath) # `start without` command let user specify # which components to use and which ones not # to use. The rest is taken from the `config.ini`. elif _docArgs.get("without"): raspberryPI = sw(_docArgs, _config, _configAbsPath) # If this is first run then every time # this application launches go to here. elif _docArgs.get("wizard"): sWI = swi(_docArgs, _config, _configAbsPath) raspberryPI = [sWI[0], sWI[1]] sv(_config, _configAbsPath, _docArgs, 1, _config.firstRun[0], False) _config.firstRun[2] = False # If there is no other parameters support the `start` command # check if user want to start this in Raspberry PI or normal # operating system. else: raspberryPI = srpi(_docArgs) # If `start` is used this application will go into main loop. continueProgramToMainLoop = True return [ configFileShown, continueProgramToMainLoop, deletedConfig, raspberryPI ]
def __init__(self, _docArgs): # Codes to clear the terminal screen before launching this application. if platform == "darwin" or platform == "linux" or platform == "linux2": subp.call(["reset"], shell=True) elif platform == "cygwin" or platform == "win32": subp.call(["cls"], shell=True) print("sociometric client\n") #print(_docArgs) docArgs = _docArgs # Arguments supplied from Docopt. CASCADE_FRONT_FACE_DEF_NAME = "cascade_face_front_default.xml" # Cascade file name. CONFIG_FILE_NAME = "config.ini" # File name for the configuration file. LOG_FOLDER_NAME = "log" cascAbsPath = os.path.join("./", CASCADE_FRONT_FACE_DEF_NAME) config = conf() # Configuration variable. configAbsPath = os.path.join( "./", CONFIG_FILE_NAME ) # Absolute path to the configuration file exist or not. conn = None # For holding information about the connection between this application and the database. connDB = None # Return value from `cdb()`. db = None # For holding information about the database. docoptControl = None # For holding CLI Docopt control. logAbsPath = None # Absolute path into current `log.txt`. logFolderAbsPath = os.path.join( "./", LOG_FOLDER_NAME) # Absolute path into the `log` folder. threads = [] # An empty array to hold all threading.Thread object. # Threads variables. You may ask on why I am not putting this directly # into the `threads` variable. The answer is because not every thread # will be put into `threads`. In case `config.withoutPVD[2]` # is True then `mPVD` will not be in the `threads`. cFD = None iDB = None iRD = None iRS = None mPVD = None # Generate the cascade .xml for front face detection. if not os.path.exists(cascAbsPath): io.FileIO(cascAbsPath, "w") with open(cascAbsPath, "a") as cascXML: cascXML.write(ccfd) print("cascade file created") # I want to know the `type()` of `docArgs`. #print(type(docArgs)) # `docArgs` is apparently a native Python dictionary type data. #print(docArgs.get("start")) # # `docArgs.get("start")` will return either True or False depending # whether `start` sub - command is used or not when starting this # application. # # Check if there is a configuration file. If not then create one. if not os.path.exists(configAbsPath): cc(config, configAbsPath) # Assign all value into run - time variables. # Use `try` and except. If there is an error # delete the current config.ini and make a new # one. try: assignallrtvconfig(config, configAbsPath) except cfgp.NoOptionError as error: print( "there is missing parameter(s) in current configuration file") print("deleting config.ini") os.remove(configAbsPath) print("creating new config.ini") cc(config, configAbsPath) # Docopt arguments handlers. docoptControl = self.DocoptControl(docArgs, config, configAbsPath, logFolderAbsPath) if not docoptControl[0] and not docoptControl[2]: showcf(config, configAbsPath) # Terminate the program right here if there is no start command # issued in CLI. if docoptControl[1]: # Show run time variables. showcr(config) # Create log folder here. Check if there something # in the `logFolderAbsPath`. if os.path.exists(logFolderAbsPath): # If there is something exists then check if the # thing is a folder or not. If the thing is not # a folder then create new folder in `logFolderAbsPath` if not os.path.isdir(logFolderAbsPath): os.makedirs(logFolderAbsPath) print("log folder created") else: os.makedirs(logFolderAbsPath) print("log folder created") # Create log file for this session. gDT = gdt() logName = (config.clientName[2] + "-" + gDT[0] + gDT[1] + gDT[2] + "-" + gDT[3] + gDT[4] + gDT[5] + "-" + gDT[6].replace("/", "-") + ".txt") logAbsPath = os.path.join(logFolderAbsPath, logName) if os.path.exists(logAbsPath): if os.path.isdir(logAbsPath): io.FileIO(logAbsPath, "w") print(logName + " log created") else: io.FileIO(logAbsPath, "w") print(logName + " log created") # First I need to check if database will be used or not. if not config.withoutDB[2]: connDB = cdb(config, False, True) # `connDB[0]` returns `True` if database connection is successful. if connDB != None: #print(connDB) if connDB[0]: db = connDB[1] conn = connDB[2] # In any case `iDB` will still be instantiated. # Only the database connection will not be used # in case of `config.withoutDB[2]` is `True.` iDB = idb("IDB_1", threads, config, config.withoutDB[2], db, conn, logAbsPath) # `docoptControl[3]` is a variable that states if user choose to run this # application in Raspberry PI's Raspbian Jessie environment. # # The cam face detection only care if the user uses PiCamera or normal USB # web cam. Hence, `docoptControl[3][1]` will return `True` if Docopt argument # `--picam` is used. # # While the pitch and volume detection need to know the operating system it # runs because it need to detect default sound card. Hence, `docoptControl[3][0]` # refer to Docopt argument `--rpi`. User need to choose this if this application # runs in Raspberry PI' Raspbian Jessie. I do not make any programming for other # Raspberry compatible OS but Raspbian Jessie. if not stb(config.withoutFaceD[2]): cFD = cfd("CFD_1", threads, iDB, docoptControl[3][1], config) # Camera face detection. if not stb(config.withoutPVD[2]): mPVD = mpvd("MPVD_1", threads, iDB, docoptControl[3] [0]) # Microphone pitch and volume detection. if not stb(config.withoutIRD[2]): iRD = ird("IRD_1", threads, iDB) iRS = irs("IRS_1", threads, config) # Then run all available threads. for t in threads: t.start() #Infinite loop. while True: self.Update(threads)