示例#1
0
文件: __init__.py 项目: B-Rich/smart
	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
示例#2
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)
    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