예제 #1
0
def handler_info(args, opts=dict()):
    # type: (List[str], Dict[str, Any]) -> Iterator[str]
    """
	Print variable info.

	:param args: Command line arguments.
	:param opts: Command line options.
	"""
    ucr = ConfigRegistry()
    ucr.load()
    # Import located here, because on module level, a circular import would be
    # created
    import univention.config_registry_info as cri  # pylint: disable-msg=W0403
    cri.set_language('en')
    info = cri.ConfigRegistryInfo(install_mode=False)

    for arg in args:
        try:
            yield variable_info_string(arg,
                                       ucr.get(arg, None),
                                       info.get_variable(arg),
                                       details=_SHOW_EMPTY | _SHOW_DESCRIPTION
                                       | _SHOW_CATEGORIES)
        except UnknownKeyException as ex:
            print(ex, file=sys.stderr)
def test_set_language():
    old = ucri._locale
    try:
        ucri.set_language("xx")
        assert ucri._locale == "xx"
        assert ucri.uit._locale == "xx"
    finally:
        ucri.set_language(old)
예제 #3
0
파일: frontend.py 프로젝트: B-Rich/smart
def handler_info(args, opts=dict()):
	"""Print variable info."""
	reg = ConfigRegistry()
	reg.load()
	# Import located here, because on module level, a circular import would be
	# created
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
	cri.set_language('en')
	info = cri.ConfigRegistryInfo(install_mode=False)

	for arg in args:
		try:
			print_variable_info_string(arg, reg.get(arg, None),
					info.get_variable(arg),
					details=_SHOW_EMPTY | _SHOW_DESCRIPTION | _SHOW_CATEGORIES)
		except UnknownKeyException, ex:
			print >> sys.stderr, ex
예제 #4
0
def handler_info(args, opts=dict()):
    """Print variable info."""
    ucr = ConfigRegistry()
    ucr.load()
    # Import located here, because on module level, a circular import would be
    # created
    import univention.config_registry_info as cri  # pylint: disable-msg=W0403
    cri.set_language('en')
    info = cri.ConfigRegistryInfo(install_mode=False)

    for arg in args:
        try:
            print_variable_info_string(arg,
                                       ucr.get(arg, None),
                                       info.get_variable(arg),
                                       details=_SHOW_EMPTY | _SHOW_DESCRIPTION
                                       | _SHOW_CATEGORIES)
        except UnknownKeyException as ex:
            print >> sys.stderr, ex
예제 #5
0
def handler_search(args, opts=dict()):
	# type: (List[str], Dict[str, Any]) -> Iterator[str]
	"""
	Search for registry variable.

	:param args: Command line arguments.
	:param opts: Command line options.
	"""
	search_keys = opts.get('key', False)
	search_values = opts.get('value', False)
	search_all = opts.get('all', False)
	count_search = int(search_keys) + int(search_values) + int(search_all)
	if count_search > 1:
		print('E: at most one out of [--key|--value|--all] may be set', file=sys.stderr)
		sys.exit(1)
	elif count_search == 0:
		search_keys = True
	search_values |= search_all
	search_keys |= search_all

	if not args:
		regex = [re.compile('')]
	else:
		try:
			regex = [re.compile(_) for _ in args]
		except re.error as ex:
			print('E: invalid regular expression: %s' % (ex,), file=sys.stderr)
			sys.exit(1)

	# Import located here, because on module level, a circular import would be
	# created
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
	cri.set_language('en')
	info = cri.ConfigRegistryInfo(install_mode=False)

	category = opts.get('category', None)
	if category and not info.get_category(category):
		print('E: unknown category: "%s"' % (category,), file=sys.stderr)
		sys.exit(1)

	ucr = ConfigRegistry()
	ucr.load()

	details = _SHOW_EMPTY | _SHOW_DESCRIPTION
	if opts.get('non-empty', False):
		details &= ~_SHOW_EMPTY
	if opts.get('brief', False) or ucr.is_true('ucr/output/brief', False):
		details &= ~_SHOW_DESCRIPTION
	if ucr.is_true('ucr/output/scope', False):
		details |= _SHOW_SCOPE
	if opts.get('verbose', False):
		details |= _SHOW_CATEGORIES | _SHOW_DESCRIPTION

	all_vars = {}  # type: Dict[str, Tuple[Optional[str], Optional[cri.Variable], Optional[str]]] # key: (value, vinfo, scope)
	for key, var in info.get_variables(category).items():
		all_vars[key] = (None, var, None)
	for key, (scope, value) in ucr.items(getscope=True):
		try:
			all_vars[key] = (value, all_vars[key][1], scope)
		except LookupError:
			all_vars[key] = (value, None, scope)

	for key, (value2, vinfo, scope2) in all_vars.items():
		for reg in regex:
			if any((
				search_keys and reg.search(key),
				search_values and value2 and reg.search(value2),
				search_all and vinfo and reg.search(vinfo.get('description', ''))
			)):
				yield variable_info_string(key, value2, vinfo, details=details)
				break

	if _SHOW_EMPTY & details and not OPT_FILTERS['shell'][2]:
		patterns = {}  # type: Dict
		for arg in args or ('',):
			patterns.update(info.describe_search_term(arg))
		for pattern, vinfo in patterns.items():
			yield variable_info_string(pattern, None, vinfo, details=details)
예제 #6
0
파일: frontend.py 프로젝트: B-Rich/smart
	search_values |= search_all
	search_keys |= search_all

	if not args:
		regex = [re.compile('')]
	else:
		try:
			regex = [re.compile(_) for _ in args]
		except re.error, ex:
			print >> sys.stderr, 'E: invalid regular expression: %s' % (ex,)
			sys.exit(1)

	# Import located here, because on module level, a circular import would be
	# created
	import univention.config_registry_info as cri  # pylint: disable-msg=W0403
	cri.set_language('en')
	info = cri.ConfigRegistryInfo(install_mode=False)

	category = opts.get('category', None)
	if category and not info.get_category(category):
		print >> sys.stderr, 'E: unknown category: "%s"' % (category,)
		sys.exit(1)

	ucr = ConfigRegistry()
	ucr.load()

	details = _SHOW_EMPTY | _SHOW_DESCRIPTION
	if opts.get('non-empty', False):
		details &= ~_SHOW_EMPTY
	if opts.get('brief', False) or ucr.is_true('ucr/output/brief', False):
		details &= ~_SHOW_DESCRIPTION
예제 #7
0
def _get_config_registry_info():
    # Import located here, because on module level, a circular import would be
    # created
    import univention.config_registry_info as cri  # pylint: disable-msg=W0403
    cri.set_language('en')
    return cri.ConfigRegistryInfo(install_mode=False)
예제 #8
0
    search_values |= search_all
    search_keys |= search_all

    if not args:
        regex = [re.compile('')]
    else:
        try:
            regex = [re.compile(_) for _ in args]
        except re.error, ex:
            print >> sys.stderr, 'E: invalid regular expression: %s' % (ex, )
            sys.exit(1)

    # Import located here, because on module level, a circular import would be
    # created
    import univention.config_registry_info as cri  # pylint: disable-msg=W0403
    cri.set_language('en')
    info = cri.ConfigRegistryInfo(install_mode=False)

    category = opts.get('category', None)
    if category and not info.get_category(category):
        print >> sys.stderr, 'E: unknown category: "%s"' % (category, )
        sys.exit(1)

    ucr = ConfigRegistry()
    ucr.load()

    details = _SHOW_EMPTY | _SHOW_DESCRIPTION
    if opts.get('non-empty', False):
        details &= ~_SHOW_EMPTY
    if opts.get('brief', False) or ucr.is_true('ucr/output/brief', False):
        details &= ~_SHOW_DESCRIPTION
def _get_config_registry_info():
    # type: () -> cri.ConfigRegistryInfo
    cri.set_language('en')
    return cri.ConfigRegistryInfo(install_mode=False)