Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(191)

Side by Side Diff: native_client_sdk/src/tools/genhttpfs.py

Issue 720233003: [NaCl SDK] Convert python scripts from optparse to argparse. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """This script generates a manifest file for nacl_io's HTTP file-system. 6 """This script generates a manifest file for nacl_io's HTTP file-system.
7 Files and directory paths are specified on the command-line. The names 7 Files and directory paths are specified on the command-line. The names
8 with glob and directories are recursed to form a list of files. 8 with glob and directories are recursed to form a list of files.
9 9
10 For each file, the mode bits, size and path relative to the CWD are written 10 For each file, the mode bits, size and path relative to the CWD are written
11 to the output file which is stdout by default. 11 to the output file which is stdout by default.
12 """ 12 """
13 13
14 import glob 14 import glob
15 import optparse 15 import argparse
binji 2014/11/13 23:57:04 sort
Sam Clegg 2014/11/30 17:55:13 Done.
16 import os 16 import os
17 import sys 17 import sys
18 import urllib 18 import urllib
19 19
20 class Error(Exception): 20 class Error(Exception):
21 pass 21 pass
22 22
23 23
24 def main(argv): 24 def main(argv):
25 parser = optparse.OptionParser(description=__doc__, 25 parser = argparse.ArgumentParser(description=__doc__,
26 usage='Usage: %prog [options] <filename>...') 26 usage='Usage: %prog [options] <filename>...')
binji 2014/11/13 23:57:04 remove usage
Sam Clegg 2014/11/30 17:55:13 Done.
27 parser.add_option('-C', '--srcdir', 27 parser.add_argument('-C', '--srcdir',
28 help='Change directory.', dest='srcdir', default=None) 28 help='Change directory.', dest='srcdir', default=None)
29 parser.add_option('-o', '--output', 29 parser.add_argument('-o', '--output',
30 help='Output file name.', dest='output', default=None) 30 help='Output file name.', dest='output', default=None)
31 parser.add_option('-v', '--verbose', 31 parser.add_argument('-v', '--verbose',
32 help='Verbose output.', dest='verbose', 32 help='Verbose output.', dest='verbose',
33 action='store_true') 33 action='store_true')
34 parser.add_option('-r', '--recursive', 34 parser.add_argument('-r', '--recursive',
35 help='Recursive search.', action='store_true') 35 help='Recursive search.', action='store_true')
36 options, args = parser.parse_args(argv) 36 options, args = parser.parse_args(argv)
binji 2014/11/13 23:57:04 options =
Sam Clegg 2014/11/30 17:55:13 Done.
37 37
38 if options.output: 38 if options.output:
39 outfile = open(options.output, 'w') 39 outfile = open(options.output, 'w')
40 else: 40 else:
41 outfile = sys.stdout 41 outfile = sys.stdout
42 42
43 if options.srcdir: 43 if options.srcdir:
44 os.chdir(options.srcdir) 44 os.chdir(options.srcdir)
45 45
46 if not args: 46 if not args:
binji 2014/11/13 23:57:03 add positional args
Sam Clegg 2014/11/30 17:55:13 Done.
47 parser.error("One or more pathnames must be specified. See --help.") 47 parser.error("One or more pathnames must be specified. See --help.")
48 48
49 # Generate a set of unique file names bases on the input globs 49 # Generate a set of unique file names bases on the input globs
50 fileset = set() 50 fileset = set()
51 for fileglob in args: 51 for fileglob in args:
52 filelist = glob.glob(fileglob) 52 filelist = glob.glob(fileglob)
53 if not filelist: 53 if not filelist:
54 raise Error('Could not find match for "%s".\n' % fileglob) 54 raise Error('Could not find match for "%s".\n' % fileglob)
55 for filename in filelist: 55 for filename in filelist:
56 if os.path.isfile(filename): 56 if os.path.isfile(filename):
(...skipping 19 matching lines...) Expand all
76 76
77 return 0 77 return 0
78 78
79 79
80 if __name__ == '__main__': 80 if __name__ == '__main__':
81 try: 81 try:
82 sys.exit(main(sys.argv[1:])) 82 sys.exit(main(sys.argv[1:]))
83 except Error, e: 83 except Error, e:
84 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 84 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
85 sys.exit(1) 85 sys.exit(1)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698