1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 here = os.path.realpath(__file__)
11 src_path = (os.path.normpath(os.path.join(here, '..', '..', '..')))
12 sys.path.append(os.path.normpath(os.path.join(src_path, '..', 'depot_tools')))
14 USAGE = 'The utility uploads .png files to ' \
15 'chrome-os-oobe-ui-screenshot-testing Google Storage bucket.\n' \
16 '-i:\n\tdirectory with .png files which have to be uploaded\n' \
17 '-o (optional):\n\tdirectory to store generated .sha1 files. ' \
18 'Is set to chrome/browser/chromeos/login/screenshot_testing' \
19 '/golden_screenshots by default\n--help:\n\thelp'
22 import upload_to_google_storage
23 import download_from_google_storage
27 # Creating a list of files which need to be uploaded to Google Storage:
28 # all .png files from the directory containing golden screenshots.
30 for file in os.listdir(png_path):
31 if file.endswith('.png'):
32 target.append(os.path.join(png_path, file))
34 # Creating a standard gsutil object, assuming there are depot_tools
35 # and everything related is set up already.
36 gsutil_path = os.path.abspath(os.path.join(src_path, '..', 'depot_tools',
37 'third_party', 'gsutil',
39 gsutil = download_from_google_storage.Gsutil(gsutil_path,
41 bypass_prodaccess=True)
43 # URL of the bucket used for storing screenshots.
44 bucket_url = 'gs://chrome-os-oobe-ui-screenshot-testing'
46 # Uploading using the most simple way,
47 # see depot_tools/upload_to_google_storage.py to have better understanding
48 # of this False and 1 arguments.
49 upload_to_google_storage.upload_to_google_storage(target, bucket_url, gsutil,
50 False, False, 1, False)
52 print 'All images are uploaded to Google Storage.'
54 def move_sha1(from_path, to_path):
55 from shutil import move
56 for file in os.listdir(from_path):
57 if (file.endswith('.sha1')):
58 old_place = os.path.join(from_path, file)
59 new_place = os.path.join(to_path, file)
60 if not os.path.exists(os.path.dirname(new_place)):
61 os.makedirs(os.path.dirname(new_place))
62 move(old_place, new_place)
66 sha1_path = os.path.join(src_path,
67 'chrome', 'browser', 'chromeos', 'login',
68 'screenshot_testing', 'golden_screenshots')
70 opts, args = getopt.getopt(argv,'i:o:', ['--help'])
71 except getopt.GetoptError:
87 png_path = os.path.abspath(png_path)
88 sha1_path = os.path.abspath(sha1_path)
91 move_sha1(png_path, sha1_path)
93 # TODO(elizavetai): Can this git stuff be done automatically?
94 print 'Please add new .sha1 files from ' \
98 if __name__ == "__main__":