Esempio n. 1
0
def replog(method, scope, ucr, var, old_value, value=None):
    """
	This function writes a new entry to replication logfile if
	this feature has been enabled.
	"""
    if ucr.is_true('ucr/replog/enabled', False):
        if method == 'set':
            varvalue = "%s=%s" % (var, escape_value(value))
        else:
            varvalue = "'%s'" % var

        scope_arg = ''
        if scope == ConfigRegistry.LDAP:
            scope_arg = '--ldap-policy '
        elif scope == ConfigRegistry.FORCED:
            scope_arg = '--force '
        elif scope == ConfigRegistry.SCHEDULE:
            scope_arg = '--schedule '

        if old_value is None:
            old_value = "[Previously undefined]"

        log = '%s: %s %s%s old:%s\n' % (time.strftime("%Y-%m-%d %H:%M:%S"),
                                        method, scope_arg, varvalue, old_value)
        try:
            if not os.path.isfile(REPLOG_FILE):
                os.close(os.open(REPLOG_FILE, os.O_CREAT, 0640))
            logfile = open(REPLOG_FILE, "a+")
            logfile.write(log)
            logfile.close()
        except EnvironmentError, ex:
            print >> sys.stderr, ("E: exception occurred while writing to " +
                                  "replication log: %s" % (ex, ))
            exception_occured()
Esempio n. 2
0
def replog(method, scope, ucr, var, old_value, value=None):
	"""
	This function writes a new entry to replication logfile if
	this feature has been enabled.
	"""
	if ucr.is_true('ucr/replog/enabled', False):
		if method == 'set':
			varvalue = "%s=%s" % (var, escape_value(value))
		else:
			varvalue = "'%s'" % var

		scope_arg = ''
		if scope == ConfigRegistry.LDAP:
			scope_arg = '--ldap-policy '
		elif scope == ConfigRegistry.FORCED:
			scope_arg = '--force '
		elif scope == ConfigRegistry.SCHEDULE:
			scope_arg = '--schedule '

		if old_value is None:
			old_value = "[Previously undefined]"

		log = '%s: %s %s%s old:%s\n' % (time.strftime("%Y-%m-%d %H:%M:%S"),
				method, scope_arg, varvalue, old_value)
		try:
			if not os.path.isfile(REPLOG_FILE):
				os.close(os.open(REPLOG_FILE, os.O_CREAT, 0640))
			logfile = open(REPLOG_FILE, "a+")
			logfile.write(log)
			logfile.close()
		except EnvironmentError, ex:
			print >> sys.stderr, ("E: exception occurred while writing to " +
				"replication log: %s" % (ex,))
			exception_occured()
Esempio n. 3
0
def filter_shell(args, text):  # pylint: disable-msg=W0613
	"""Filter output for shell: escape keys."""
	out = []
	for line in text:
		try:
			var, value = line.split(': ', 1)
		except ValueError:
			var = line
			value = ''
		out.append('%s=%s' % (key_shell_escape(var), escape_value(value)))
	return out