コード例 #1
0
 def _call_prescript(self, app, args, **kwargs):
     ext = self.prescript_ext
     self.debug('Calling prescript (%s)' % ext)
     if not ext:
         return True
     script = app.get_cache_file(ext)
     # check here to not bother asking for a password
     # otherwise self._call_script could handle it, too
     if not os.path.exists(script):
         self.debug('%s does not exist' % script)
         return True
     with NamedTemporaryFile('r+b') as error_file:
         with self._get_password_file(args) as pwdfile:
             if not pwdfile:
                 self.warn('Could not get password')
                 return False
             kwargs['version'] = app.version
             kwargs['error_file'] = error_file.name
             kwargs['binddn'] = self._get_userdn(args)
             kwargs['bindpwdfile'] = pwdfile
             locale = get_locale()
             if locale:
                 kwargs['locale'] = locale
             success = self._call_cache_script(app, ext, **kwargs)
             if not success:
                 for line in error_file:
                     self.fatal(line)
             return success
コード例 #2
0
    def list_config(cls, app):
        cls.debug('Finding all configuration options for %s' % app.id)
        filename = app.get_cache_file('univention-config-registry-variables')
        if not os.path.exists(filename):
            return []
        parser = ConfigParser.ConfigParser()
        with open(filename, 'rb') as fp:
            parser.readfp(fp)
        locale = get_locale()
        try:
            _ucr = cls._get_app_ucr(app)
        except NoDatabaseFound:
            _ucr = {}

        def _get_cfg(config, sec, name, split=False):
            try:
                val = config.get(sec, name)
            except ConfigParser.NoOptionError:
                return None
            else:
                if split:
                    val = shlex.split(val)
                return val

        variables = []
        for section in parser.sections():
            variable = {'id': section}
            variable['description'] = _get_cfg(
                parser, section, 'Description[%s]' % locale) or _get_cfg(
                    parser, section, 'Description[en]')
            variable['labels'] = _get_cfg(
                parser, section, 'Labels[%s]' % locale,
                split=True) or _get_cfg(
                    parser, section, 'Labels[en]', split=True)
            variable['values'] = _get_cfg(parser,
                                          section,
                                          'values',
                                          split=True)
            variable['type'] = _get_cfg(parser, section, 'type')
            if variable['type'] == 'boolean':
                variable['type'] = 'bool'
            default = _get_cfg(parser, section, 'default')
            value = _ucr.get(section, default)
            if variable['type'] == 'bool':
                value = ucr_evaluated_as_true(value)
            variable['value'] = value
            advanced = _get_cfg(parser, section, 'advanced')
            if advanced:
                advanced = ucr_evaluated_as_true(advanced)
            variable['advanced'] = advanced
            variables.append(variable)
        return variables
コード例 #3
0
 def all_from_file(cls, fname, locale=None):
     if locale is None:
         locale = get_locale()
     ret = []
     parser = read_ini_file(fname)
     for section in parser.sections():
         try:
             obj = cls.from_parser(parser, section, locale)
         except (NoValueError, ParseError) as exc:
             ini_logger.warn('%s: %s' % (fname, exc))
         else:
             ret.append(obj)
     return ret
コード例 #4
0
	def _run_update_certificates_script(self, app):
		ext = 'update_certificates'
		with NamedTemporaryFile('r+b') as error_file:
			kwargs = {}
			kwargs['version'] = app.version
			kwargs['error_file'] = error_file.name
			locale = get_locale()
			if locale:
				kwargs['locale'] = locale
			success = self._call_cache_script(app, ext, **kwargs)
			if success is False:
				for line in error_file:
					self.fatal(line)
			return success
コード例 #5
0
 def _run_configure_script(self, app, action):
     ext = 'configure_host'
     with NamedTemporaryFile('r+b') as error_file:
         kwargs = {}
         kwargs['version'] = app.version
         kwargs['error_file'] = error_file.name
         locale = get_locale()
         if locale:
             kwargs['locale'] = locale
         success = self._call_cache_script(app, ext, action, **kwargs)
         if success is False:
             for line in error_file:
                 self.fatal(line)
         return success
コード例 #6
0
def default_locale():
    return get_locale() or 'en'