OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2008-2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2008-2010 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 """Generate index.html files for a Google Storage for Developers directory. | 6 """Generate index.html files for a Google Storage for Developers directory. |
7 | 7 |
8 Google Storage for Developers provides only a raw set of objects. | 8 Google Storage for Developers provides only a raw set of objects. |
9 For some buckets we would like to be able to support browsing of the directory | 9 For some buckets we would like to be able to support browsing of the directory |
10 tree. This utility will generate the needed index and upload/update it. | 10 tree. This utility will generate the needed index and upload/update it. |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 163 |
164 def GenerateIndexes(path, options): | 164 def GenerateIndexes(path, options): |
165 """Generate all relevant indexes for a given gsd path.""" | 165 """Generate all relevant indexes for a given gsd path.""" |
166 # Get a list of objects under this prefix. | 166 # Get a list of objects under this prefix. |
167 cmd = [options.gsutil, 'ls', posixpath.join(path, '*')] | 167 cmd = [options.gsutil, 'ls', posixpath.join(path, '*')] |
168 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 168 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
169 p_stdout, _ = p.communicate() | 169 p_stdout, _ = p.communicate() |
170 assert p.returncode == 0 | 170 assert p.returncode == 0 |
171 objects = str(p_stdout).splitlines() | 171 objects = str(p_stdout).splitlines() |
172 objects = [o for o in objects if posixpath.basename(o) != GENERATED_INDEX] | 172 objects = [o for o in objects if posixpath.basename(o) != GENERATED_INDEX] |
| 173 objects = [path.rstrip(':') for path in objects] |
173 # Find common prefixes. | 174 # Find common prefixes. |
174 directories = set() | 175 directories = set() |
175 for o in objects: | 176 for o in objects: |
176 part = posixpath.dirname(o) | 177 part = posixpath.dirname(o) |
177 while part.startswith(path): | 178 while part.startswith(path): |
178 directories.add(part) | 179 directories.add(part) |
179 part = posixpath.dirname(part) | 180 part = posixpath.dirname(part) |
180 objects += list(directories) | 181 objects += list(directories) |
181 # Generate index for each directory. | 182 # Generate index for each directory. |
182 index_list = [i for i in directories | 183 index_list = [i for i in directories |
(...skipping 27 matching lines...) Expand all Loading... |
210 dest='gsutil', help='path to gsutil') | 211 dest='gsutil', help='path to gsutil') |
211 options, args = parser.parse_args(argv) | 212 options, args = parser.parse_args(argv) |
212 if len(args) != 2 or not args[1].startswith('gs://'): | 213 if len(args) != 2 or not args[1].startswith('gs://'): |
213 parser.print_help() | 214 parser.print_help() |
214 return 1 | 215 return 1 |
215 return GenerateIndexes(args[1], options) | 216 return GenerateIndexes(args[1], options) |
216 | 217 |
217 | 218 |
218 if __name__ == '__main__': | 219 if __name__ == '__main__': |
219 sys.exit(main(sys.argv)) | 220 sys.exit(main(sys.argv)) |
OLD | NEW |