예제 #1
0
	def write(self, stream, entries = None, printMinimal = False, printState = False,
			printUnused = True, printSource = False, printDefault = True, printTight = False):
		if not entries:
			entries = self.iterContent()
		config = {}
		for entry in entries:
			if printUnused or entry.accessed:
				if printDefault or not entry.source.startswith('<default'):
					if printState or not entry.option.startswith('#'):
						config.setdefault(entry.section, {}).setdefault(entry.option, []).append(entry)
		for section in sorted(config):
			if not printTight:
				stream.write('[%s]\n' % section)
			for option in sorted(config[section]):
				entryList = sorted(config[section][option], key = lambda e: e.order)
				if printMinimal:
					entryList = ConfigEntry.simplifyEntries(entryList)
				for entry in entryList:
					if printTight:
						stream.write('[%s] ' % section)
					for idx, line in enumerate(entry.format().splitlines()):
						if printSource and (idx == 0) and entry.source:
							if len(line) < 33:
								stream.write('%-35s; %s\n' % (line, entry.source))
							else:
								stream.write('; source: %s\n%s\n' % (entry.source, line))
						else:
							stream.write(line + '\n')
			if not printTight:
				stream.write('\n')
예제 #2
0
	def _addEntry(self, container, section, option, value, source):
		option = option.strip()
		opttype = '='
		if option[-1] in imap(itemgetter(0), ConfigEntry.OptTypeDesc.keys()):
			opttype = option[-1] + '='
			option = option[:-1].strip()
		container.append(ConfigEntry(section.strip(), option, value.strip(), opttype, source))
예제 #3
0
 def get(self, option_list, default_str, persistent):
     # Return old and current merged config entries
     entry_old = None
     if self._container_old.enabled:  # If old container is enabled => return stored entry
         entry_old = ConfigEntry.combine_entries(
             self._match_entries(self._container_old, option_list))
     # Process current entry
     (entry_default, entry_default_fallback) = self._get_default_entries(
         option_list, default_str, persistent, entry_old)
     entry_cur = self.get_entry(option_list, entry_default,
                                entry_default_fallback)
     if entry_cur is None:
         raise ConfigError(
             '"[%s] %s" does not exist!' %
             (self._get_section(specific=False), option_list[-1]))
     description = 'Using user supplied %s'
     if persistent and entry_default.used:
         description = 'Using persistent    %s'
     elif entry_default.used and (entry_cur.value != entry_default.value):
         description = 'Using modified default value %s'
     elif entry_default.used:
         description = 'Using default value %s'
     elif '!' in entry_cur.section:
         description = 'Using dynamic value %s'
     self._log.log(logging.INFO2, description,
                   entry_cur.format(print_section=True))
     return (entry_old, entry_cur)
예제 #4
0
 def _addEntry(self, container, section, option, value, source):
     option = option.strip()
     opttype = '='
     if option[-1] in ['+', '-', '*', '?', '^']:
         opttype = option[-1] + '='
         option = option[:-1].strip()
     container.append(
         ConfigEntry(section.strip(), option, value.strip(), opttype,
                     source))
예제 #5
0
 def _add_entry(self, container, section, option, value, source):
     opttype = '='
     try:
         option = option.strip()
         if option[-1] in imap(itemgetter(0),
                               ConfigEntry.map_opt_type2desc.keys()):
             opttype = option[-1] + '='
             option = option[:-1].strip()
         container.append(
             ConfigEntry(section.strip(), option, value.strip(), opttype,
                         source))
     except Exception:
         raise ConfigError(
             'Unable to register config value [%s] %s %s %s (from %s)' %
             (section, option, opttype, value, source))
예제 #6
0
	def _getEntry(self, option_list, defaultEntry, defaultEntry_fallback):
		if defaultEntry.value != noDefault:
			self._curContainer.setDefault(defaultEntry)
		# Assemble matching config entries and combine them
		entries = self._matchEntries(self._curContainer, option_list)
		if defaultEntry.value != noDefault:
			entries.append(defaultEntry_fallback)
		self._log.log(logging.DEBUG1, 'Used config entries:')
		for entry in entries:
			self._log.log(logging.DEBUG1, '  %s (%s | %s)', entry.format(printSection = True), entry.source, entry.order)
		curEntry = ConfigEntry.combineEntries(entries)
		# Ensure that fallback default value is stored in persistent storage
		if (defaultEntry.value != noDefault) and defaultEntry_fallback.used:
			self._curContainer.setDefault(defaultEntry_fallback)
		return curEntry
예제 #7
0
	def write(self, stream, print_minimal=False, print_source=False, print_oneline=False, **kwarg):
		config = self._prepare_write(**kwarg)
		for section in sorted(config):
			if not print_oneline:
				stream.write('[%s]\n' % section)
			for option in sorted(config[section]):
				entry_list = sorted(config[section][option], key=lambda e: e.order)
				if print_minimal:
					entry_list = ConfigEntry.simplify_entries(entry_list)
				for entry in entry_list:
					source = ''
					if print_source:
						source = entry.source
					stream.write(entry.format(print_section=print_oneline, source=source) + '\n')
			if not print_oneline:
				stream.write('\n')
예제 #8
0
	def get_entry(self, option_list, entry_default, entry_default_fallback):
		if not unspecified(entry_default.value):
			self._container_cur.set_default_entry(entry_default)
		# Assemble matching config entries and combine them
		entries = self._match_entries(self._container_cur, option_list)
		if not unspecified(entry_default.value):
			entries.append(entry_default_fallback)
		self._log.log(logging.DEBUG1, 'Used config entries:')
		for entry in entries:
			self._log.log(logging.DEBUG1, '  %s (%s | %s)',
				entry.format(print_section=True), entry.source, entry.order)
		entry_cur = ConfigEntry.combine_entries(entries)
		# Ensure that fallback default value is stored in persistent storage
		if entry_default_fallback.used and not unspecified(entry_default.value):
			self._container_cur.set_default_entry(entry_default_fallback)
		return entry_cur
예제 #9
0
 def _getEntry(self, option_list, defaultEntry, defaultEntry_fallback):
     if defaultEntry.value != noDefault:
         self._curContainer.setDefault(defaultEntry)
     # Assemble matching config entries and combine them
     entries = self._matchEntries(self._curContainer, option_list)
     if defaultEntry.value != noDefault:
         entries.append(defaultEntry_fallback)
     self._log.log(logging.DEBUG1, 'Used config entries:')
     for entry in entries:
         self._log.log(logging.DEBUG1, '  %s (%s | %s)',
                       entry.format(printSection=True), entry.source,
                       entry.order)
     curEntry = ConfigEntry.combineEntries(entries)
     # Ensure that fallback default value is stored in persistent storage
     if (defaultEntry.value != noDefault) and defaultEntry_fallback.used:
         self._curContainer.setDefault(defaultEntry_fallback)
     return curEntry
예제 #10
0
	def get(self, option_list, default_str, persistent):
		oldEntry = None
		if self._oldContainer.enabled: # If old container is enabled => return stored entry
			oldEntry = ConfigEntry.combineEntries(self._matchEntries(self._oldContainer, option_list))
		# Process current entry
		(defaultEntry, defaultEntry_fallback) = self._getDefaultEntries(option_list, default_str, persistent, oldEntry)
		curEntry = self._getEntry(option_list, defaultEntry, defaultEntry_fallback)
		if curEntry is None:
			raise ConfigError('"[%s] %s" does not exist!' % (self._getSection(specific = False), option_list[0]))
		description = 'Using user supplied %s'
		if persistent and defaultEntry.used:
			description = 'Using persistent    %s'
		elif defaultEntry.used:
			description = 'Using default value %s'
		elif '!' in curEntry.section:
			description = 'Using dynamic value %s'
		self._log.log(logging.INFO2, description, curEntry.format(printSection = True))
		return (oldEntry, curEntry)
예제 #11
0
 def get_entry(self, option_list, entry_default, entry_default_fallback):
     if not unspecified(entry_default.value):
         self._container_cur.set_default_entry(entry_default)
     # Assemble matching config entries and combine them
     entries = self._match_entries(self._container_cur, option_list)
     if not unspecified(entry_default.value):
         entries.append(entry_default_fallback)
     self._log.log(logging.DEBUG1, 'Used config entries:')
     for entry in entries:
         self._log.log(logging.DEBUG1, '  %s (%s | %s)',
                       entry.format(print_section=True), entry.source,
                       entry.order)
     entry_cur = ConfigEntry.combine_entries(entries)
     # Ensure that fallback default value is stored in persistent storage
     if entry_default_fallback.used and not unspecified(
             entry_default.value):
         self._container_cur.set_default_entry(entry_default_fallback)
     return entry_cur
예제 #12
0
	def get(self, option_list, default_str, persistent):
		# Return old and current merged config entries
		entry_old = None
		if self._container_old.enabled:  # If old container is enabled => return stored entry
			entry_old = ConfigEntry.combine_entries(self._match_entries(self._container_old, option_list))
		# Process current entry
		(entry_default, entry_default_fallback) = self._get_default_entries(
			option_list, default_str, persistent, entry_old)
		entry_cur = self.get_entry(option_list, entry_default, entry_default_fallback)
		if entry_cur is None:
			raise ConfigError('"[%s] %s" does not exist!' % (
				self._get_section(specific=False), option_list[-1]))
		description = 'Using user supplied %s'
		if persistent and entry_default.used:
			description = 'Using persistent    %s'
		elif entry_default.used and (entry_cur.value != entry_default.value):
			description = 'Using modified default value %s'
		elif entry_default.used:
			description = 'Using default value %s'
		elif '!' in entry_cur.section:
			description = 'Using dynamic value %s'
		self._log.log(logging.INFO2, description, entry_cur.format(print_section=True))
		return (entry_old, entry_cur)
예제 #13
0
 def write(self,
           stream,
           printMinimal=False,
           printSource=False,
           printTight=False,
           **kwarg):
     config = self._prepare_write(**kwarg)
     for section in sorted(config):
         if not printTight:
             stream.write('[%s]\n' % section)
         for option in sorted(config[section]):
             entryList = sorted(config[section][option],
                                key=lambda e: e.order)
             if printMinimal:
                 entryList = ConfigEntry.simplifyEntries(entryList)
             for entry in entryList:
                 source = ''
                 if printSource:
                     source = entry.source
                 stream.write(
                     entry.format(printSection=printTight, source=source) +
                     '\n')
         if not printTight:
             stream.write('\n')
예제 #14
0
 def get(self, option_list, default_str, persistent):
     oldEntry = None
     if self._oldContainer.enabled:  # If old container is enabled => return stored entry
         oldEntry = ConfigEntry.combineEntries(
             self._matchEntries(self._oldContainer, option_list))
     # Process current entry
     (defaultEntry, defaultEntry_fallback) = self._getDefaultEntries(
         option_list, default_str, persistent, oldEntry)
     curEntry = self._getEntry(option_list, defaultEntry,
                               defaultEntry_fallback)
     if curEntry is None:
         raise ConfigError(
             '"[%s] %s" does not exist!' %
             (self._getSection(specific=False), option_list[0]))
     description = 'Using user supplied %s'
     if persistent and defaultEntry.used:
         description = 'Using persistent    %s'
     elif defaultEntry.used:
         description = 'Using default value %s'
     elif '!' in curEntry.section:
         description = 'Using dynamic value %s'
     self._log.log(logging.INFO2, description,
                   curEntry.format(printSection=True))
     return (oldEntry, curEntry)
예제 #15
0
 def _createEntry(self, option_list, value, opttype, source, specific,
                  reverse):
     section = self._getSection(specific)
     if reverse:
         section += '!'
     return ConfigEntry(section, option_list[0], value, opttype, source)