Autofill: Add WalletIntegrationAvailable() to components.
[chromium-blink-merge.git] / native_client_sdk / src / tools / genhttpfs.py
blob8cd7e50d32b3c44d27ba44d7618a89806e4ce5f8
1 #!/usr/bin/env python
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
4 # found in the LICENSE file.
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
8 with glob and directories are recursed to form a list of files.
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.
12 """
14 import argparse
15 import glob
16 import os
17 import sys
18 import urllib
20 class Error(Exception):
21 pass
24 def main(args):
25 parser = argparse.ArgumentParser(description=__doc__)
26 parser.add_argument('-C', '--srcdir',
27 help='Change directory.', dest='srcdir', default=None)
28 parser.add_argument('-o', '--output',
29 help='Output file name.', dest='output', default=None)
30 parser.add_argument('-v', '--verbose',
31 help='Verbose output.', dest='verbose',
32 action='store_true')
33 parser.add_argument('-r', '--recursive',
34 help='Recursive search.', action='store_true')
35 parser.add_argument('paths', nargs='+')
36 options = parser.parse_args(args)
38 if options.output:
39 outfile = open(options.output, 'w')
40 else:
41 outfile = sys.stdout
43 if options.srcdir:
44 os.chdir(options.srcdir)
46 # Generate a set of unique file names bases on the input globs
47 fileset = set()
48 for fileglob in options.paths:
49 filelist = glob.glob(fileglob)
50 if not filelist:
51 raise Error('Could not find match for "%s".\n' % fileglob)
52 for filename in filelist:
53 if os.path.isfile(filename):
54 fileset |= set([filename])
55 continue
56 if os.path.isdir(filename) and options.recursive:
57 for root, _, files in os.walk(filename):
58 fileset |= set([os.path.join(root, name) for name in files])
59 continue
60 raise Error('Can not handle path "%s".\n' % filename)
62 cwd = os.path.abspath(os.getcwd())
63 cwdlen = len(cwd)
64 for filename in sorted(fileset):
65 relname = os.path.abspath(filename)
66 if cwd not in relname:
67 raise Error('%s is not relative to CWD %s.\n' % filename, cwd)
68 relname = relname[cwdlen:]
69 stat = os.stat(filename)
70 mode = '-r--'
71 name = urllib.quote(relname)
72 outfile.write('%s %d %s\n' % (mode, stat.st_size, name))
74 return 0
77 if __name__ == '__main__':
78 try:
79 sys.exit(main(sys.argv[1:]))
80 except Error, e:
81 sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
82 sys.exit(1)