Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: run.py

Issue 6569732794744832: Issue 2200 - PART I/II - Migrate to argparse (Closed)
Left Patch Set: Issue 2200 - PART I/II - Migrate to argparse Created April 7, 2015, 3:36 p.m.
Right Patch Set: Issue 2200 - PART I/II - Migrate to argparse Created April 7, 2015, 3:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « kick.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # coding: utf-8 2 # coding: utf-8
3 3
4 import argparse 4 import argparse
5 import sys 5 import sys
6 import os 6 import os
7 import re 7 import re
8 import subprocess 8 import subprocess
9 import yaml 9 import yaml
10 10
11 def createArgumentParser(**kwargs): 11 def createArgumentParser(**kwargs):
12 parser = argparse.ArgumentParser(**kwargs) 12 parser = argparse.ArgumentParser(**kwargs)
13 parser.add_argument( 13 parser.add_argument(
14 '-u', '--user', metavar='<user>', dest='user', type=str, default='vagrant', 14 '-u', '--user', metavar='user', dest='user', type=str, default='vagrant',
Wladimir Palant 2015/04/07 15:50:25 Please remove < and > from metavar here as well.
mathias 2015/04/07 15:56:22 Done.
15 help='user name for use with SSH, must exist on all hosts' 15 help='user name for use with SSH, must exist on all hosts'
16 ) 16 )
17 17
18 return parser 18 return parser
19 19
20 def parseOptions(args): 20 def parseOptions(args):
21 description = 'Run a command on the given hosts or groups of hosts' 21 description = 'Run a command on the given hosts or groups of hosts'
22 parser = createArgumentParser(description=description) 22 parser = createArgumentParser(description=description)
23 parser.add_argument( 23 parser.add_argument(
24 '-i', '--ignore-errors', action='store_true', dest='ignore_errors', 24 '-i', '--ignore-errors', action='store_true', dest='ignore_errors',
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 87
88 if __name__ == '__main__': 88 if __name__ == '__main__':
89 options = parseOptions(sys.argv[1:]) 89 options = parseOptions(sys.argv[1:])
90 selectedHosts = resolveHostList(options.hosts) 90 selectedHosts = resolveHostList(options.hosts)
91 if len(selectedHosts) == 0: 91 if len(selectedHosts) == 0:
92 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do' 92 print >>sys.stderr, 'No valid hosts or groups specified, nothing to do'
93 sys.exit(0) 93 sys.exit(0)
94 for host in selectedHosts: 94 for host in selectedHosts:
95 print >>sys.stderr, 'Running on %s...' % host 95 print >>sys.stderr, 'Running on %s...' % host
96 runCommand(options.user, host, options.args, options.ignore_errors) 96 runCommand(options.user, host, options.args, options.ignore_errors)
LEFTRIGHT
« kick.py ('k') | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld