def getOutputData(self): """ @return {String} - returns output of command """ try: process = Popen(self.command, stdout=PIPE) # output = str(process.stdout.read()) # Use for big data of stdout (output, error) = process.communicate() # Store data in clipboard self.returnCode = process.returncode if self.returnCode == 0: res = None if output: res = str(output) if self.writeToFile and self.fileName: lines = res.split('\\n') Helper.createNewFile(self.fileName, os.linesep.join(lines), 'w') return res else: debug.log().error( "Command '{}' failed, exit-code = {}, error = {}".format( self.command, self.returnCode, str(error))) except (ValueError, OSError, TypeError) as err: debug.log().critical(err) Helper.systemExit()
def checkValidConfigKey(self): """ Check the availability of required keys """ for obj in self.config.pattern: for key in self.validKeys: if key not in obj: debug.log().critical( "Not valid config pattern {}".format(obj)) Helper.systemExit()
def __init__(self, userConfig=None, launchCommand=None): """ Class constructor @param userConfig {Dict|None} - [optional]:None @param launchCommand {String|None} - [optional]:None """ super().__init__() self._defaultConfig = Helper.parseJson("src/default_config.json") if not self._defaultConfig: debug.log().critical("Default config doesn't exist") Helper.systemExit() # Config in current folder, which program was run. self._currentConfig = Helper.parseJson( os.path.join(os.getcwd(), "current.json")) self.config = Helper.MergeDict(self._defaultConfig, self._currentConfig) if userConfig: self._userConfig = Helper.parseJson(userConfig) self.config = Helper.MergeDict(self.config, self._userConfig) if launchCommand: self.config.launchCommand = launchCommand # Keys, which must be in each pattern self.validKeys = ["code", "regex", "name"] self.checkValidConfigKey()