Exemplo n.º 1
0
 def is_readonly(self, key):
     ucrinfo_system = ConfigRegistryInfo(registered_only=False,
                                         load_customized=False)
     var = ucrinfo_system.get_variable(key)
     if var:
         return var.get('readonly') in ('yes', '1', 'true')
     return False
Exemplo n.º 2
0
	def query(self, pattern, key, category=None):
		'''Returns a dictionary of configuration registry variables
		found by searching for the (wildcard) expression defined by the
		UMCP request. Additionally a list of configuration registry
		categories can be defined.

		The dictionary returned is compatible with the Dojo data store
		format.'''
		variables = []
		if category == 'all':
			# load _all_ config registry variables
			base_info = ConfigRegistryInfo(registered_only=False)
		else:
			# load _all registered_ config registry variables
			base_info = ConfigRegistryInfo()

		if category in ('all', 'all-registered'):
			category = None

		def _match_value(name, var):
			return var.value and pattern.match(var.value)
		def _match_key(name, var):
			return pattern.match(name)
		def _match_description(name, var):
			descr = var.get('description')
			return descr and pattern.match(descr)
		def _match_all(name, var):
			return _match_value(name, var) or _match_description(name, var) or _match_key(name, var)

		func = eval('_match_%s' % key)
		for name, var in base_info.get_variables(category).iteritems():
			if func(name, var):
				variables.append({'key' : name, 'value' : var.value})

		return variables
Exemplo n.º 3
0
    def get(self, request):
        ucrReg = ucr.ConfigRegistry()
        ucrReg.load()
        ucrInfo = ConfigRegistryInfo(registered_only=False)

        # iterate over all requested variables
        results = []
        for key in request.options:
            info = ucrInfo.get_variable(str(key))
            value = ucrReg.get(str(key))
            if not info and (value or '' == value):
                # only the value available
                results.append({'key': key, 'value': value})
            elif info:
                # info (categories etc.) available
                info['value'] = value
                info['key'] = key
                results.append(info.normalize())
            else:
                # variable not available, request failed
                request.status = BAD_REQUEST_INVALID_OPTS
                self.finished(
                    request.id,
                    False,
                    message=_('The UCR variable %(key)s could not be found') %
                    {'key': key})
                return
        self.finished(request.id, results)
Exemplo n.º 4
0
 def categories(self, request):
     ucrInfo = ConfigRegistryInfo(registered_only=False)
     categories = []
     for id, obj in ucrInfo.categories.iteritems():
         name = obj['name']
         if ucrInfo.get_variables(id):
             categories.append({'id': id, 'label': name})
     self.finished(request.id, categories)
Exemplo n.º 5
0
	def __create_variable_info( self, options ):
		all_info = ConfigRegistryInfo( registered_only = False )
		info = ConfigRegistryInfo( install_mode = True )
		info.read_customized()
		var = Variable()

		# description
		for line in options[ 'descriptions' ]:
			text = line[ 'text' ]
			if not text: continue
			if 'lang' in line:
				var[ 'description[%s]' % line[ 'lang' ] ] = text
			else:
				var[ 'description' ] = text
		# categories
		if options[ 'categories' ]:
			var[ 'categories' ] = ','.join( options[ 'categories' ] )

		# type
		var[ 'type' ] = options[ 'type' ]

		# are there any modifications?
		old_value = all_info.get_variable( options[ 'key' ] )
		if old_value != var:
			# save
			info.add_variable( options[ 'key' ], var )
			info.write_customized()
    def query(self,
              pattern: str,
              key: str,
              category: Union[List[str], None] = None) -> Dict:
        '''Returns a dictionary of configuration registry variables
		found by searching for the (wildcard) expression defined by the
		UMCP request. Additionally a list of configuration registry
		categories can be defined.

		The dictionary returned is compatible with the Dojo data store
		format.'''
        variables = []
        if category == 'all':
            # load _all_ config registry variables
            base_info = ConfigRegistryInfo(registered_only=False)
        else:
            # load _all registered_ config registry variables
            base_info = ConfigRegistryInfo()

        if category in ('all', 'all-registered'):
            category = None

        def _match_value(name, var):
            return var.value and pattern.match(var.value)

        def _match_key(name, var):
            return pattern.match(name)

        def _match_description(name, var):
            descr = var.get('description')
            return descr and pattern.match(descr)

        def _match_all(name, var):
            return _match_value(name, var) or _match_description(
                name, var) or _match_key(name, var)

        func = locals().get(f'_match_{key}')
        for name, var in base_info.get_variables(category).items():
            if func(name, var):
                variables.append({
                    'key': name,
                    'value': var.value,
                    'description': var.get('description', None),
                })

        return variables
    def get(self, request: 'Request') -> None:
        ucrReg = ConfigRegistry()
        ucrReg.load()
        ucrInfo = ConfigRegistryInfo(registered_only=False)

        # iterate over all requested variables
        results = []
        for key in request.options:
            info = ucrInfo.get_variable(str(key))
            value = ucrReg.get(str(key))
            if not info and (value or '' == value):
                # only the value available
                results.append({'key': key, 'value': value})
            elif info:
                # info (categories etc.) available
                info['value'] = value
                info['key'] = key
                results.append(info.normalize())
            else:
                # variable not available, request failed
                raise UMC_Error(
                    _('The UCR variable %(key)s could not be found') %
                    {'key': key})
        self.finished(request.id, results)
Exemplo n.º 8
0
	def get( self, request ):
		ucrReg = ucr.ConfigRegistry()
		ucrReg.load()
		ucrInfo = ConfigRegistryInfo( registered_only = False )

		# iterate over all requested variables
		results = []
		for key in request.options:
			info = ucrInfo.get_variable( str( key ) )
			value = ucrReg.get( str( key ) )
			if not info and (value or '' == value):
				# only the value available
				results.append( {'key': key, 'value': value} )
			elif info:
				# info (categories etc.) available
				info['value'] = value
				info['key'] = key
				results.append(info.normalize())
			else:
				# variable not available, request failed
				request.status = BAD_REQUEST_INVALID_OPTS
				self.finished( request.id, False, message = _( 'The UCR variable %(key)s could not be found' ) % { 'key' : key } )
				return
		self.finished( request.id, results )
Exemplo n.º 9
0
    def __create_variable_info(self, options):
        all_info = ConfigRegistryInfo(registered_only=False)
        info = ConfigRegistryInfo(install_mode=True)
        info.read_customized()
        var = Variable()

        # description
        for line in options['descriptions']:
            text = line['text']
            if not text:
                continue
            if 'lang' in line:
                var['description[%s]' % line['lang']] = text
            else:
                var['description'] = text
        # categories
        if options['categories']:
            var['categories'] = ','.join(options['categories'])

        # type
        var['type'] = options['type']

        # are there any modifications?
        old_value = all_info.get_variable(options['key'])
        if old_value != var:
            # save
            info.add_variable(options['key'], var)
            info.write_customized()
Exemplo n.º 10
0
	def is_readonly( self, key ):
		ucrinfo_system = ConfigRegistryInfo( registered_only = False, load_customized = False )
		var = ucrinfo_system.get_variable( key )
		if var:
			return var.get( 'readonly' ) in  ( 'yes', '1', 'true' )
		return False