Commits

dgc committed 4414811

aws/all tools: support supplemental config files on command line

Comments (0)

Files changed (3)

 import re
 import uuid
 
-# We will need aws fairly early and it's lightweight.
+import aws
+from aws import error, status, usage
+
 # boto is not needed until we've done validity checking on args, and
 # is somewhat slow to import, so we'll defer it.
-import aws
-from aws import error, status, usage
 boto = None
 
 # place command options here for usage() to use
 
 
 def main(args):
-	sess = aws.awsuser()
+	user = None
+	conffiles = []
 
 	try:
-		opts, args = getopt.getopt(args, 'hu:', ['help', 'user='])
+		opts, args = getopt.getopt(args, 'hu:c:', ['help', 'user=', 'conffile='])
 	except getopt.GetoptError, e:
 		error(str(e))
 		usage(fp=sys.stdout)
 			return 0
 
 		if opt in ('-u', '--user'):
-			sess = aws.awsuser(arg)
+			user = arg
+
+		if opt in ('-c', '--conffile'):
+			conffiles.append(arg)
 
 	if len(args) < 1:
 		usage(fp=sys.stderr)
 		error('the "boto" module is required. try "easy_install boto".')
 		return 5
 
+	sess = aws.awsuser(user, conffiles=conffiles)
 	sess.iam = boto.connect_iam(sess.awsid, sess.secret)
 	rc = aws.dispatch(sess, verb, args)
 	if rc == 2:
 import re
 import pprint
 
-# We will need aws fairly early and it's lightweight.
+import aws
+from aws import error, status, usage
+
 # boto is not needed until we've done validity checking on args, and
 # is somewhat slow to import, so we'll defer it.
-import aws
-from aws import error, status, usage
 boto = None
 
 # place command options here for usage() to use
 
 
 def main(args):
-	sess = aws.awsuser()
+	user = None
+	conffiles = []
 
 	try:
-		opts, args = getopt.getopt(args, 'hu:', ['help', 'user='])
+		opts, args = getopt.getopt(args, 'hu:c:', ['help', 'user=', 'conffile='])
 	except getopt.GetoptError, e:
 		error(str(e))
 		usage(fp=sys.stdout)
 			return 0
 
 		if opt in ('-u', '--user'):
-			sess = aws.awsuser(arg)
+			user = arg
+
+		if opt in ('-c', '--conffile'):
+			conffiles.append(arg)
 
 	if len(args) < 1:
 		usage(fp=sys.stderr)
 		error('the "boto" module is required. try "easy_install boto".')
 		return 5
 
+	sess = aws.awsuser(user, conffiles=conffiles)
 	sess.sns = boto.connect_sns(sess.awsid, sess.secret)
 	rc = aws.dispatch(sess, verb, args)
 	if rc == 2:
 class awsuser(object):
 	userdir = os.path.expanduser(os.path.join('~', '.aws'))
 
-	def __init__(self, user=None, awsid=None, secret=None, host=None, userdir=None):
+	def __init__(self, user=None, awsid=None, secret=None, host=None, userdir=None, conffiles=[]):
 		self.user = user
 		self.awsid = awsid
 		self.secret = secret
 		if userdir:
 			self.userdir = os.path.expanduser(userdir)
 
-		self.readconf()
+		self.readconf(conffiles)
 
 		# If no user provided, find default user
 		if self.user is None and self.cfg.has_option('aws', 'user'):
 			self.secret = self.cfg.get('aws', 'secret')
 
 
-	def readconf(self):
+	def readconf(self, conffiles):
 		self.cfg = ConfigParser.RawConfigParser()
 		self.cfg.read(os.path.join(self.userdir, 'aws.ini'))
+		for file in conffiles:
+			self.cfg.read(os.path.expanduser(file))
 
 
 	@staticmethod
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.