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

Side by Side Diff: gsd_generate_index.py

Issue 11348025: Fix GenerateIndex for gsutil directories by stripping colon off directory names. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/gsd_generate_index/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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/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
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 def strip_colon(dir_str): return dir_str.rstrip(':')
174 objects = map(strip_colon, objects)
Isaac (away) 2012/10/29 23:49:24 use lambda fun or else list comprehension: object
173 # Find common prefixes. 175 # Find common prefixes.
174 directories = set() 176 directories = set()
175 for o in objects: 177 for o in objects:
176 part = posixpath.dirname(o) 178 part = posixpath.dirname(o)
177 while part.startswith(path): 179 while part.startswith(path):
178 directories.add(part) 180 directories.add(part)
179 part = posixpath.dirname(part) 181 part = posixpath.dirname(part)
180 objects += list(directories) 182 objects += list(directories)
181 # Generate index for each directory. 183 # Generate index for each directory.
182 index_list = [i for i in directories 184 index_list = [i for i in directories
(...skipping 27 matching lines...) Expand all
210 dest='gsutil', help='path to gsutil') 212 dest='gsutil', help='path to gsutil')
211 options, args = parser.parse_args(argv) 213 options, args = parser.parse_args(argv)
212 if len(args) != 2 or not args[1].startswith('gs://'): 214 if len(args) != 2 or not args[1].startswith('gs://'):
213 parser.print_help() 215 parser.print_help()
214 return 1 216 return 1
215 return GenerateIndexes(args[1], options) 217 return GenerateIndexes(args[1], options)
216 218
217 219
218 if __name__ == '__main__': 220 if __name__ == '__main__':
219 sys.exit(main(sys.argv)) 221 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698