| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 elif sz < 1000000000: | 43 elif sz < 1000000000: |
| 44 sz = str(int(sz / 100000) / 10.0) + 'M' | 44 sz = str(int(sz / 100000) / 10.0) + 'M' |
| 45 else: | 45 else: |
| 46 sz = str(int(sz / 100000000) / 10.0) + 'G' | 46 sz = str(int(sz / 100000000) / 10.0) + 'G' |
| 47 return sz | 47 return sz |
| 48 | 48 |
| 49 | 49 |
| 50 def GetPathInfo(path, options): | 50 def GetPathInfo(path, options): |
| 51 """Collect size, date, md5 for a give gsd path.""" | 51 """Collect size, date, md5 for a give gsd path.""" |
| 52 # Check current state. | 52 # Check current state. |
| 53 cmd = [options.gsutil, 'ls', '-l', path] | 53 cmd = [options.gsutil, 'ls', '-L', path] |
| 54 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 54 p = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 55 p_stdout, _ = p.communicate() | 55 p_stdout, _ = p.communicate() |
| 56 assert p.returncode == 0 | 56 assert p.returncode == 0 |
| 57 # Extract intersting fields. | 57 # Extract intersting fields. |
| 58 fields = {} | 58 fields = {} |
| 59 fields['size'] = FixupSize(re.search('\tObject size:\t([0-9]+)\n', | 59 fields['size'] = FixupSize(re.search('\tObject size:\t([0-9]+)\n', |
| 60 p_stdout).group(1)) | 60 p_stdout).group(1)) |
| 61 fields['md5'] = re.search('\tMD5:\t([^\n]+)\n', p_stdout).group(1) | 61 fields['md5'] = re.search('\tMD5:\t([^\n]+)\n', p_stdout).group(1) |
| 62 fields['date'] = re.search('\tLast mod:\t([^\n]+)\n', p_stdout).group(1) | 62 fields['date'] = re.search('\tLast mod:\t([^\n]+)\n', p_stdout).group(1) |
| 63 return fields | 63 return fields |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 dest='gsutil', help='path to gsutil') | 201 dest='gsutil', help='path to gsutil') |
| 202 options, args = parser.parse_args(argv) | 202 options, args = parser.parse_args(argv) |
| 203 if len(args) != 2 or not args[1].startswith('gs://'): | 203 if len(args) != 2 or not args[1].startswith('gs://'): |
| 204 parser.print_help() | 204 parser.print_help() |
| 205 return 1 | 205 return 1 |
| 206 return GenerateIndexes(args[1], options) | 206 return GenerateIndexes(args[1], options) |
| 207 | 207 |
| 208 | 208 |
| 209 if __name__ == '__main__': | 209 if __name__ == '__main__': |
| 210 sys.exit(main(sys.argv)) | 210 sys.exit(main(sys.argv)) |
| OLD | NEW |