Пример #1
0
	def load_config_and_cmd_line(self, argv=sys.argv[1:]):
		# we scan the command line first in case the user wants to
		# override the default config file location
		args, left_over = self.cmd_parser.parse_known_args(args=argv, namespace=SeqalConfig.Args())

		# load the config for this program, if the file exists
		config = SealConfigFile()

		# was a config file different from the default specified on the command line?
		try:
			if args.seal_config != self.cmd_parser.get_default("seal_config"):
				# in this case, make sure it exists and is readable
				if not os.path.exists(args.seal_config):
					raise SeqalConfigError("The specified Seal config file %s doens't exist" % args.seal_config)
				if not os.access(args.seal_config, os.R_OK):
					raise SeqalConfigError("The specified Seal config file %s isn't readable" % args.seal_config)
				config.read(args.seal_config) # no problems.  Load the file.
			else:
				# check the default path.  If the file exists and is readable we'll load it
				if os.path.exists(args.seal_config):
					if os.access(args.seal_config, os.R_OK):
						config.read(args.seal_config)
					else:
						print >>sys.stderr, "WARNING:  Seal config file %s exists but isn't readable" % args.seal_config
		except FormatError as e: # catch errors from parsing the config file
			raise SeqalConfigError("Error in Seal configuration file %s\n%s" % (args.seal_config, str(e)))

		# override configuration properties from file with the ones
		# provided on the command line.
		for name, value in config.items(SeqalConfig.ConfigSection):
			if not args.properties.has_key(name):
				args.properties[name] = value

		return args, left_over
Пример #2
0
 def setUp(self):
     self.emptyConfig = SealConfigFile()
     self.config = SealConfigFile()