summaryrefslogtreecommitdiffstats
path: root/native_client_sdk/src/tools
diff options
context:
space:
mode:
authorsbc <sbc@chromium.org>2014-08-29 16:20:47 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-29 23:26:01 +0000
commitf024036686219f4714c0f30dbb9dc7d5ef456333 (patch)
treea9c725d0e5242f5c6f6239bb79754bf43eb93202 /native_client_sdk/src/tools
parent89acb2b4701183644758bc8c84ff832613739aab (diff)
downloadchromium_src-f024036686219f4714c0f30dbb9dc7d5ef456333.zip
chromium_src-f024036686219f4714c0f30dbb9dc7d5ef456333.tar.gz
chromium_src-f024036686219f4714c0f30dbb9dc7d5ef456333.tar.bz2
[NaCl SDK] genhttpfs.py: allow filenames with spaces in them.
Allow special characters such as spaces in filenames. Also includes some general cleanup, and documentation. Review URL: https://codereview.chromium.org/15854004 Cr-Commit-Position: refs/heads/master@{#292713}
Diffstat (limited to 'native_client_sdk/src/tools')
-rwxr-xr-xnative_client_sdk/src/tools/genhttpfs.py36
1 files changed, 22 insertions, 14 deletions
diff --git a/native_client_sdk/src/tools/genhttpfs.py b/native_client_sdk/src/tools/genhttpfs.py
index b6c848b..4e9aa92 100755
--- a/native_client_sdk/src/tools/genhttpfs.py
+++ b/native_client_sdk/src/tools/genhttpfs.py
@@ -3,23 +3,27 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-# This scripts generates a manifest file for the MountHttp file system.
-# Files and directory paths are specified on the command-line. The names
-# with glob and directories are recursed to form a list of files.
-#
-# For each file, the mode bits, size and path relative to the CWD are written
-# to the output file which is stdout by default.
-#
+"""This script generates a manifest file for nacl_io's HTTP file-system.
+Files and directory paths are specified on the command-line. The names
+with glob and directories are recursed to form a list of files.
+
+For each file, the mode bits, size and path relative to the CWD are written
+to the output file which is stdout by default.
+"""
import glob
import optparse
import os
import sys
+import urllib
+
+class Error(Exception):
+ pass
def main(argv):
- parser = optparse.OptionParser(
- usage='Usage: %prog [options] filename ...')
+ parser = optparse.OptionParser(description=__doc__,
+ usage='Usage: %prog [options] <filename>...')
parser.add_option('-C', '--srcdir',
help='Change directory.', dest='srcdir', default=None)
parser.add_option('-o', '--output',
@@ -39,12 +43,15 @@ def main(argv):
if options.srcdir:
os.chdir(options.srcdir)
+ if not args:
+ parser.error("One or more pathnames must be specified. See --help.")
+
# Generate a set of unique file names bases on the input globs
fileset = set()
for fileglob in args:
filelist = glob.glob(fileglob)
if not filelist:
- raise RuntimeError('Could not find match for "%s".\n' % fileglob)
+ raise Error('Could not find match for "%s".\n' % fileglob)
for filename in filelist:
if os.path.isfile(filename):
fileset |= set([filename])
@@ -53,18 +60,19 @@ def main(argv):
for root, _, files in os.walk(filename):
fileset |= set([os.path.join(root, name) for name in files])
continue
- raise RuntimeError('Can not handle path "%s".\n' % filename)
+ raise Error('Can not handle path "%s".\n' % filename)
cwd = os.path.abspath(os.getcwd())
cwdlen = len(cwd)
for filename in sorted(fileset):
relname = os.path.abspath(filename)
if cwd not in relname:
- raise RuntimeError('%s is not relative to CWD %s.\n' % filename, cwd)
+ raise Error('%s is not relative to CWD %s.\n' % filename, cwd)
relname = relname[cwdlen:]
stat = os.stat(filename)
mode = '-r--'
- outfile.write('%s %d %s\n' % (mode, stat.st_size, relname))
+ name = urllib.quote(relname)
+ outfile.write('%s %d %s\n' % (mode, stat.st_size, name))
return 0
@@ -72,6 +80,6 @@ def main(argv):
if __name__ == '__main__':
try:
sys.exit(main(sys.argv[1:]))
- except OSError, e:
+ except Error, e:
sys.stderr.write('%s: %s\n' % (os.path.basename(__file__), e))
sys.exit(1)