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

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 5 years, 11 months 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
« no previous file with comments | « native_client_sdk/src/tools/fix_manifest.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 argparse
14 import glob 15 import glob
15 import optparse
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(args):
25 parser = optparse.OptionParser(description=__doc__, 25 parser = argparse.ArgumentParser(description=__doc__)
26 usage='Usage: %prog [options] <filename>...') 26 parser.add_argument('-C', '--srcdir',
27 parser.add_option('-C', '--srcdir', 27 help='Change directory.', dest='srcdir', default=None)
28 help='Change directory.', dest='srcdir', default=None) 28 parser.add_argument('-o', '--output',
29 parser.add_option('-o', '--output', 29 help='Output file name.', dest='output', default=None)
30 help='Output file name.', dest='output', default=None) 30 parser.add_argument('-v', '--verbose',
31 parser.add_option('-v', '--verbose', 31 help='Verbose output.', dest='verbose',
32 help='Verbose output.', dest='verbose', 32 action='store_true')
33 action='store_true') 33 parser.add_argument('-r', '--recursive',
34 parser.add_option('-r', '--recursive', 34 help='Recursive search.', action='store_true')
35 help='Recursive search.', action='store_true') 35 parser.add_argument('paths', nargs='+')
36 options, args = parser.parse_args(argv) 36 options = parser.parse_args(args)
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:
47 parser.error("One or more pathnames must be specified. See --help.")
48
49 # Generate a set of unique file names bases on the input globs 46 # Generate a set of unique file names bases on the input globs
50 fileset = set() 47 fileset = set()
51 for fileglob in args: 48 for fileglob in options.paths:
52 filelist = glob.glob(fileglob) 49 filelist = glob.glob(fileglob)
53 if not filelist: 50 if not filelist:
54 raise Error('Could not find match for "%s".\n' % fileglob) 51 raise Error('Could not find match for "%s".\n' % fileglob)
55 for filename in filelist: 52 for filename in filelist:
56 if os.path.isfile(filename): 53 if os.path.isfile(filename):
57 fileset |= set([filename]) 54 fileset |= set([filename])
58 continue 55 continue
59 if os.path.isdir(filename) and options.recursive: 56 if os.path.isdir(filename) and options.recursive:
60 for root, _, files in os.walk(filename): 57 for root, _, files in os.walk(filename):
61 fileset |= set([os.path.join(root, name) for name in files]) 58 fileset |= set([os.path.join(root, name) for name in files])
(...skipping 14 matching lines...) Expand all
76 73
77 return 0 74 return 0
78 75
79 76
80 if __name__ == '__main__': 77 if __name__ == '__main__':
81 try: 78 try:
82 sys.exit(main(sys.argv[1:])) 79 sys.exit(main(sys.argv[1:]))
83 except Error, e: 80 except Error, e:
84 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e)) 81 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
85 sys.exit(1) 82 sys.exit(1)
OLDNEW
« no previous file with comments | « native_client_sdk/src/tools/fix_manifest.py ('k') | native_client_sdk/src/tools/getos.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698