Exemplo n.º 1
0
	def __getDefinitions(self):
		"""get config definitions"""

		# open configuration definition source
		try:
			cfgDefSource = gmCfg.cCfgFile(aFile = self.__mDefinitionSource, \
				flags=gmCfg.cfg_SEARCH_STD_DIRS | gmCfg.cfg_IGNORE_CMD_LINE)
			# handle all exceptions including 'config file not found'
		except:
			exc = sys.exc_info()
			_log.LogException("Unhandled exception while opening config file [%s]" % self.__mDefinitionSource, exc,verbose=0)
			return None

		cfgData = cfgDefSource.getCfg()
		groups = cfgDefSource.getGroups()

		if not '_config_version_' in (groups):
			_log.Log(gmLog.lWarn, "No configuration definition version defined.")
			_log.Log(gmLog.lWarn, "Matching definitions to config data is unsafe.")
			_log.Log(gmLog.lWarn, "Config data will be read-only by default.")
			self.mVersion = None
		else:
			version = cfgDefSource.get('_config_version_', "version")
			# we don't check for type in order to allow for versions like '1.20.1b'			 
			self.__mVersion = version
			_log.Log(gmLog.lInfo, "Found config parameter definition version %s in %s" % (version,self.__mDefinitionSource))


		# every group holds one parameter description
		# group name = parameter name
		for paramName in groups:
			# ignore config version group
			if paramName == '_config_version_':
				continue

			paramType = cfgDefSource.get(paramName, "type")			
			if paramType is None:
				continue
			
			# parameter description - might differ from that stored 
			# in backend tables (cfg_template)
			paramDescription = cfgDefSource.get(paramName, "description")
			if paramDescription is None:
				continue

			validValuesRaw = None
			# if valid value list is supplied, get it
			if "validvalue" in (cfgDefSource.getOptions(paramName)):
				validValuesRaw = cfgDefSource.get(paramName, "validvalues")
			# transform valid values to a list
			validVals = None
			if not validValuesRaw is None:
				if type(validValuesRaw) == types.ListType:
					validVals = validValuesRaw
			
			# add new entry to parameter definition dictionary
			self.__mParameterDefinitions
			self.__mParameterDefinitions[paramName] = ParameterDefinition(paramName,paramType,validVals,paramDescription)
		return 1
Exemplo n.º 2
0
	def __init__(self, aFilename = None):
		""" Init config file """
		ConfigData.__init__(self,"FILE")

		self.filename = aFilename
		self.__cfgfile = None
		self.fullPath = None
				
		# open config file
		try:
			self.__cfgfile = gmCfg.cCfgFile(aFile = self.filename)
			# this is a little bit ugly, but we need to get the full name of the
			# file because this depends on the installation/system settings
			# if no absolute path was specified, we get the config file gnumed
			# would find first which is what we want usually
			self.fullPath = self.__cfgfile.cfgName

		except:
			_log.LogException("Can't open config file !", sys.exc_info(), verbose=0)
			raise ConstructorError, "ConfigDataFile: couldn't open config file"
Exemplo n.º 3
0
    def __init__(self, aFilename=None):
        """ Init config file """
        ConfigData.__init__(self, "FILE")

        self.filename = aFilename
        self.__cfgfile = None
        self.fullPath = None

        # open config file
        try:
            self.__cfgfile = gmCfg.cCfgFile(aFile=self.filename)
            # this is a little bit ugly, but we need to get the full name of the
            # file because this depends on the installation/system settings
            # if no absolute path was specified, we get the config file gnumed
            # would find first which is what we want usually
            self.fullPath = self.__cfgfile.cfgName

        except:
            _log.LogException("Can't open config file !",
                              sys.exc_info(),
                              verbose=0)
            raise ConstructorError, "ConfigDataFile: couldn't open config file"
Exemplo n.º 4
0
def importDBSet(filename,aUser = None, aWorkplace = 'xxxDEFAULTxxx'):
	"""get config definitions from a file exported with 
	   exportDBSet()."""

	# open configuration definition source
	try:
		importFile = gmCfg.cCfgFile(aFile = filename, \
			flags= gmCfg.cfg_IGNORE_CMD_LINE)
		# handle all exceptions including 'config file not found'
	except:
		exc = sys.exc_info()
		_log.LogException("Unhandled exception while opening input file [%s]" % filename, exc,verbose=0)
		return None

	try:
		importConfigSource = ConfigSourceDB("export",aUser,aWorkplace)
	except:
		_log.Log(gmLog.lErr, "Cannot open config set [%s@%s]." % (aUser,aWorkplace))
		return None

	existingParamList = importConfigSource.getAllParamNames()

	importData = importFile.getCfg()
	groups = importFile.getGroups()
	# every group holds one parameter description
	# group name = parameter name
	successfully_stored = 0
	for paramName in groups:
		# ignore empty parameter names
		if paramName == "":
			continue
		paramType = importFile.get(paramName, "type")			
		if paramType is None:
			continue

		# parameter description - might differ from that stored 
		# in backend tables (cfg_template)
		paramDescription = importFile.get(paramName, "description")
		if paramDescription is None:
			continue


		paramValueStr = importFile.get(paramName, "value")
		if paramDescription is None:
			continue
		else:
			if paramType in ['string','numeric','str_array']:
				paramValue = eval(repr(paramValueStr))
			else:
				paramValue = pickle.loads(paramValueStr)
		# TODO: check if the parameter already exists with different type
		if existingParamList is not None and paramName in (existingParamList):
			if not importConfigSource.getParamType(paramName) == paramType:
				# if yes, print a warning
				# you will have to delete that parameter before
				# storing a different type
				_log.Log(gmLog.lWarn,
				"Cannot store config parameter [%s]: different type stored already." % paramName)
			else:
				# same type -> store new value	
				s=importConfigSource.setConfigData(paramName,paramValue)
				if s is None:
					_log.Log(gmLog.lWarn, 
						"Cannot store config parameter [%s] to set [%s@%s]." % (paramName,aUser,aWorkplace))
				else:
					successfully_stored = successfully_stored + 1

		else:
			# add new entry to parameter definition dictionary
			s=importConfigSource.addConfigParam(paramName,paramType,paramValue,paramDescription)
			if s is None:
				_log.Log(gmLog.lWarn, 
					"Cannot store config parameter [%s] to set [%s@%s]." % (paramName,aUser,aWorkplace))
			else:
				successfully_stored = successfully_stored + 1	
	return successfully_stored
Exemplo n.º 5
0
def importDBSet(filename, aUser=None, aWorkplace='xxxDEFAULTxxx'):
    """get config definitions from a file exported with 
	   exportDBSet()."""

    # open configuration definition source
    try:
        importFile = gmCfg.cCfgFile(aFile = filename, \
         flags= gmCfg.cfg_IGNORE_CMD_LINE)
        # handle all exceptions including 'config file not found'
    except:
        exc = sys.exc_info()
        _log.LogException("Unhandled exception while opening input file [%s]" %
                          filename,
                          exc,
                          verbose=0)
        return None

    try:
        importConfigSource = ConfigSourceDB("export", aUser, aWorkplace)
    except:
        _log.Log(gmLog.lErr,
                 "Cannot open config set [%s@%s]." % (aUser, aWorkplace))
        return None

    existingParamList = importConfigSource.getAllParamNames()

    importData = importFile.getCfg()
    groups = importFile.getGroups()
    # every group holds one parameter description
    # group name = parameter name
    successfully_stored = 0
    for paramName in groups:
        # ignore empty parameter names
        if paramName == "":
            continue
        paramType = importFile.get(paramName, "type")
        if paramType is None:
            continue

        # parameter description - might differ from that stored
        # in backend tables (cfg_template)
        paramDescription = importFile.get(paramName, "description")
        if paramDescription is None:
            continue

        paramValueStr = importFile.get(paramName, "value")
        if paramDescription is None:
            continue
        else:
            if paramType in ['string', 'numeric', 'str_array']:
                paramValue = eval(repr(paramValueStr))
            else:
                paramValue = pickle.loads(paramValueStr)
        # TODO: check if the parameter already exists with different type
        if existingParamList is not None and paramName in (existingParamList):
            if not importConfigSource.getParamType(paramName) == paramType:
                # if yes, print a warning
                # you will have to delete that parameter before
                # storing a different type
                _log.Log(
                    gmLog.lWarn,
                    "Cannot store config parameter [%s]: different type stored already."
                    % paramName)
            else:
                # same type -> store new value
                s = importConfigSource.setConfigData(paramName, paramValue)
                if s is None:
                    _log.Log(
                        gmLog.lWarn,
                        "Cannot store config parameter [%s] to set [%s@%s]." %
                        (paramName, aUser, aWorkplace))
                else:
                    successfully_stored = successfully_stored + 1

        else:
            # add new entry to parameter definition dictionary
            s = importConfigSource.addConfigParam(paramName, paramType,
                                                  paramValue, paramDescription)
            if s is None:
                _log.Log(
                    gmLog.lWarn,
                    "Cannot store config parameter [%s] to set [%s@%s]." %
                    (paramName, aUser, aWorkplace))
            else:
                successfully_stored = successfully_stored + 1
    return successfully_stored
Exemplo n.º 6
0
    def __getDefinitions(self):
        """get config definitions"""

        # open configuration definition source
        try:
            cfgDefSource = gmCfg.cCfgFile(aFile = self.__mDefinitionSource, \
             flags=gmCfg.cfg_SEARCH_STD_DIRS | gmCfg.cfg_IGNORE_CMD_LINE)
            # handle all exceptions including 'config file not found'
        except:
            exc = sys.exc_info()
            _log.LogException(
                "Unhandled exception while opening config file [%s]" %
                self.__mDefinitionSource,
                exc,
                verbose=0)
            return None

        cfgData = cfgDefSource.getCfg()
        groups = cfgDefSource.getGroups()

        if not '_config_version_' in (groups):
            _log.Log(gmLog.lWarn,
                     "No configuration definition version defined.")
            _log.Log(gmLog.lWarn,
                     "Matching definitions to config data is unsafe.")
            _log.Log(gmLog.lWarn, "Config data will be read-only by default.")
            self.mVersion = None
        else:
            version = cfgDefSource.get('_config_version_', "version")
            # we don't check for type in order to allow for versions like '1.20.1b'
            self.__mVersion = version
            _log.Log(
                gmLog.lInfo,
                "Found config parameter definition version %s in %s" %
                (version, self.__mDefinitionSource))

        # every group holds one parameter description
        # group name = parameter name
        for paramName in groups:
            # ignore config version group
            if paramName == '_config_version_':
                continue

            paramType = cfgDefSource.get(paramName, "type")
            if paramType is None:
                continue

            # parameter description - might differ from that stored
            # in backend tables (cfg_template)
            paramDescription = cfgDefSource.get(paramName, "description")
            if paramDescription is None:
                continue

            validValuesRaw = None
            # if valid value list is supplied, get it
            if "validvalue" in (cfgDefSource.getOptions(paramName)):
                validValuesRaw = cfgDefSource.get(paramName, "validvalues")
            # transform valid values to a list
            validVals = None
            if not validValuesRaw is None:
                if type(validValuesRaw) == types.ListType:
                    validVals = validValuesRaw

            # add new entry to parameter definition dictionary
            self.__mParameterDefinitions
            self.__mParameterDefinitions[paramName] = ParameterDefinition(
                paramName, paramType, validVals, paramDescription)
        return 1
Exemplo n.º 7
0
	def __getFormatInfo(self):
		"""get info on how to format parameters returned by query groups"""

		# open configuration source
		try:
			cfgSource = gmCfg.cCfgFile(aFile = self.dbConfFile, \
				flags=gmCfg.cfg_SEARCH_STD_DIRS | gmCfg.cfg_IGNORE_CMD_LINE)
			# handle all exceptions including 'config file not found'
		except:
			exc = sys.exc_info()
			_log.LogException("Unhandled exception while opening config file [%s]" % self.dbConfFile, exc, verbose = 0)
			return None

		cfgData = cfgSource.getCfg()
		groups = cfgSource.getGroups()

		# every info holds 
        # -an format string (presented as an list)
        # -a heading
        # -a format type ('none','single' or 'list')
        # -a position in the product info (int >= 0)
        # -the query group name that supplies the variables that are to be
        #  matched to the format string 
		# format infos are identified by the item 'type=format' 
		for entry_group in groups:
			entry_type = cfgSource.get(entry_group, "type")
			# groups not containing format strings are silently ignored
			if entry_type != 'format':
				continue

			# group name
			qname = cfgSource.get(entry_group, "querygroup")
			if qname is None:
				_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
				continue

			# group format type 
			ftype = cfgSource.get(entry_group, "formattype")
			if ftype is None:
				_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
				continue

			fposstring = cfgSource.get(entry_group, "position")
			# check that the position is an valid int number
			try:
				fpos = int(fposstring)
			except TypeError:
				fpos = -1

			if fpos is None or fpos < 0:
				_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
				continue

			if ftype != 'heading':
				format = cfgSource.get(entry_group, "format")
				if format is None or not type(format) == types.ListType:
					_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
					continue

				usedVars = cfgSource.get(entry_group, "usedvars")
				if usedVars is None:
					_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
					continue


			if ftype != 'noheading':
				heading = cfgSource.get(entry_group, "heading")
				if format is None or not type(format) == types.ListType:
					_log.Log(gmLog.lWarn,"query definition invalid in entry_group %s." % entry_group)
					continue

			# set the parameters read from config file				
			self.__mGroupPos[fpos] = qname 
			self.__mFormatType[fpos] = ftype
			if ftype != 'heading':
				fstring=string.join(format,'')
				self.__mFormatString[fpos] = fstring
				usedVarsList = string.split(usedVars,',')
				self.__mUsedVars[fpos] = usedVarsList
			if ftype != 'noheading':
				fheading = string.join(heading,'')
				self.__mHeading[fpos] = fheading
		return 1
Exemplo n.º 8
0
    def __getFormatInfo(self):
        """get info on how to format parameters returned by query groups"""

        # open configuration source
        try:
            cfgSource = gmCfg.cCfgFile(aFile = self.dbConfFile, \
             flags=gmCfg.cfg_SEARCH_STD_DIRS | gmCfg.cfg_IGNORE_CMD_LINE)
            # handle all exceptions including 'config file not found'
        except:
            exc = sys.exc_info()
            _log.LogException(
                "Unhandled exception while opening config file [%s]" %
                self.dbConfFile,
                exc,
                verbose=0)
            return None

        cfgData = cfgSource.getCfg()
        groups = cfgSource.getGroups()

        # every info holds
        # -an format string (presented as an list)
        # -a heading
        # -a format type ('none','single' or 'list')
        # -a position in the product info (int >= 0)
        # -the query group name that supplies the variables that are to be
        #  matched to the format string
        # format infos are identified by the item 'type=format'
        for entry_group in groups:
            entry_type = cfgSource.get(entry_group, "type")
            # groups not containing format strings are silently ignored
            if entry_type != 'format':
                continue

            # group name
            qname = cfgSource.get(entry_group, "querygroup")
            if qname is None:
                _log.Log(
                    gmLog.lWarn,
                    "query definition invalid in entry_group %s." %
                    entry_group)
                continue

            # group format type
            ftype = cfgSource.get(entry_group, "formattype")
            if ftype is None:
                _log.Log(
                    gmLog.lWarn,
                    "query definition invalid in entry_group %s." %
                    entry_group)
                continue

            fposstring = cfgSource.get(entry_group, "position")
            # check that the position is an valid int number
            try:
                fpos = int(fposstring)
            except TypeError:
                fpos = -1

            if fpos is None or fpos < 0:
                _log.Log(
                    gmLog.lWarn,
                    "query definition invalid in entry_group %s." %
                    entry_group)
                continue

            if ftype != 'heading':
                format = cfgSource.get(entry_group, "format")
                if format is None or not type(format) == types.ListType:
                    _log.Log(
                        gmLog.lWarn,
                        "query definition invalid in entry_group %s." %
                        entry_group)
                    continue

                usedVars = cfgSource.get(entry_group, "usedvars")
                if usedVars is None:
                    _log.Log(
                        gmLog.lWarn,
                        "query definition invalid in entry_group %s." %
                        entry_group)
                    continue

            if ftype != 'noheading':
                heading = cfgSource.get(entry_group, "heading")
                if format is None or not type(format) == types.ListType:
                    _log.Log(
                        gmLog.lWarn,
                        "query definition invalid in entry_group %s." %
                        entry_group)
                    continue

            # set the parameters read from config file
            self.__mGroupPos[fpos] = qname
            self.__mFormatType[fpos] = ftype
            if ftype != 'heading':
                fstring = string.join(format, '')
                self.__mFormatString[fpos] = fstring
                usedVarsList = string.split(usedVars, ',')
                self.__mUsedVars[fpos] = usedVarsList
            if ftype != 'noheading':
                fheading = string.join(heading, '')
                self.__mHeading[fpos] = fheading
        return 1