| #!/usr/bin/env python3 |
| |
| import sys |
| import optparse |
| import os |
| |
| root_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) |
| sys.path.insert(0, root_dir + "/third_party/depot_tools/") |
| import upload_to_google_storage |
| |
| def main(): |
| parser = optparse.OptionParser(upload_to_google_storage.USAGE_STRING) |
| parser.add_option('-b', '--bucket', |
| default='dpranke-chromium-website-exp-storage', |
| help='Google Storage bucket to upload to.') |
| parser.add_option('-e', '--boto', help='Specify a custom boto file.') |
| parser.add_option('-f', '--force', action='store_true', |
| help='Force upload even if remote file exists.') |
| parser.add_option('-g', '--gsutil_path', |
| default=upload_to_google_storage.GSUTIL_DEFAULT_PATH, |
| help='Path to the gsutil script.') |
| parser.add_option('-m', '--use_md5', action='store_true', |
| help='Generate MD5 files when scanning, and don\'t check ' |
| 'the MD5 checksum if a .md5 file is found.') |
| parser.add_option('-t', '--num_threads', default=1, type='int', |
| help='Number of uploader threads to run.') |
| parser.add_option('-s', '--skip_hashing', action='store_true', |
| help='Skip hashing if .sha1 file exists.') |
| parser.add_option('-0', '--use_null_terminator', action='store_true', |
| help='Use \\0 instead of \\n when parsing ' |
| 'the file list from stdin. This is useful if the input ' |
| 'is coming from "find ... -print0".') |
| parser.add_option('-z', '--gzip', metavar='ext', |
| help='Gzip files which end in ext. ' |
| 'ext is a comma-separated list') |
| (options, args) = parser.parse_args() |
| |
| # Enumerate our inputs. |
| input_filenames = upload_to_google_storage.get_targets(args, parser, |
| options.use_null_terminator) |
| |
| if options.archive: |
| if not upload_to_google_storage.validate_archive_dirs(input_filenames): |
| parser.error('Only directories just below cwd are valid entries when ' |
| 'using the --archive argument. Entries can not contain .. ' |
| ' and entries can not be symlinks. Entries was %s' % |
| input_filenames) |
| return 1 |
| input_filenames = upload_to_google_storage.create_archives(input_filenames) |
| |
| # Make sure we can find a working instance of gsutil. |
| if os.path.exists(upload_to_google_storage.GSUTIL_DEFAULT_PATH): |
| gsutil = upload_to_google_storage.Gsutil( |
| upload_to_google_storage.GSUTIL_DEFAULT_PATH, boto_path=options.boto) |
| else: |
| gsutil = None |
| for path in os.environ["PATH"].split(os.pathsep): |
| if os.path.exists(path) and 'gsutil' in os.listdir(path): |
| gsutil = upload_to_google_storage.Gsutil(os.path.join(path, 'gsutil'), |
| boto_path=options.boto) |
| if not gsutil: |
| parser.error('gsutil not found in %s, bad depot_tools checkout?' % |
| upload_to_google_storage.GSUTIL_DEFAULT_PATH) |
| |
| base_url = 'gs://%s' % options.bucket |
| |
| add_to_ignore(input_filenames) |
| |
| return upload_to_google_storage.upload_to_google_storage( |
| input_filenames, base_url, gsutil, options.force, options.use_md5, |
| options.num_threads, options.skip_hashing, options.gzip) |
| |
| def add_to_ignore(lob_file): |
| with open(root_dir + "/.gitignore", 'a+') as ignore_file: |
| for lob_file in lob_file: |
| if os.path.exists(lob_file): |
| ignore_file.write('\n' + lob_file) |
| |
| if __name__ == '__main__': |
| try: |
| sys.exit(main()) |
| except KeyboardInterrupt: |
| sys.stderr.write('interrupted\n') |
| sys.exit(1) |