def MaybeDownloadApk(builder, milestone, apk, download_path, bucket): """Returns path to the downloaded APK or None if not found.""" apk_path = os.path.join(download_path, builder, milestone, apk) sha1_path = apk_path + '.sha1' base_url = os.path.join(bucket, builder, milestone) if os.path.exists(apk_path): print('%s already exists' % apk_path) return apk_path elif not os.path.exists(sha1_path): print('Skipping %s, file not found' % sha1_path) return None else: download_from_google_storage.download_from_google_storage( input_filename=sha1_path, sha1_file=sha1_path, base_url=base_url, gsutil=download_from_google_storage.Gsutil( download_from_google_storage.GSUTIL_DEFAULT_PATH), num_threads=1, directory=False, recursive=False, force=False, output=apk_path, ignore_errors=False, verbose=True, auto_platform=False, extract=False) return apk_path
def MaybeDownloadApk(builder, milestone, apk, download_path, bucket): """Returns path to the downloaded APK or None if not found.""" apk_path = os.path.join(download_path, builder, milestone, apk) sha1_path = apk_path + '.sha1' base_url = os.path.join(bucket, builder, milestone) if os.path.exists(apk_path): print '%s already exists' % apk_path return apk_path elif not os.path.exists(sha1_path): print 'Skipping %s, file not found' % sha1_path return None else: download_from_google_storage.download_from_google_storage( input_filename=sha1_path, sha1_file=sha1_path, base_url=base_url, gsutil=download_from_google_storage.Gsutil( download_from_google_storage.GSUTIL_DEFAULT_PATH), num_threads=1, directory=False, recursive=False, force=False, output=apk_path, ignore_errors=False, verbose=True, auto_platform=False, extract=False) return apk_path
def test_download_directory_no_recursive_non_force(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') self.gsutil.add_expected(0, '', '') # ls self.gsutil.add_expected( 0, '', '', lambda: shutil.copyfile(self.lorem_ipsum, output_filename)) # cp code = download_from_google_storage.download_from_google_storage( input_filename=self.base_path, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=True, recursive=False, force=False, output=None, ignore_errors=False, sha1_file=False, verbose=True, auto_platform=False, extract=False) expected_calls = [('check_call', ('ls', input_filename)), ('check_call', ('cp', input_filename, output_filename))] if sys.platform != 'win32': expected_calls.append(('check_call', ( 'stat', 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 0)
def test_download_cp_fails(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') self.gsutil.add_expected(0, '', '') self.gsutil.add_expected(101, '', 'Test error message.') code = download_from_google_storage.download_from_google_storage( input_filename=sha1_hash, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=False, recursive=False, force=True, output=output_filename, ignore_errors=False, sha1_file=False, verbose=True, auto_platform=False, extract=False) expected_calls = [('check_call', ('ls', input_filename)), ('check_call', ('cp', input_filename, output_filename))] self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 101)
def test_download_directory_no_recursive_non_force(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') self.gsutil.add_expected(0, '', '') # version self.gsutil.add_expected(0, '', '') # ls self.gsutil.add_expected(0, '', '', lambda: shutil.copyfile( self.lorem_ipsum, output_filename)) # cp code = download_from_google_storage.download_from_google_storage( input_filename=self.base_path, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=True, recursive=False, force=False, output=None, ignore_errors=False, sha1_file=False, verbose=True, auto_platform=False, extract=False) expected_calls = [ ('check_call', ('version',)), ('check_call', ('ls', input_filename)), ('check_call', ('cp', input_filename, output_filename))] if sys.platform != 'win32': expected_calls.append( ('check_call', ('stat', 'gs://sometesturl/7871c8e24da15bad8b0be2c36edc9dc77e37727f'))) self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 0)
def test_download_cp_fails(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') self.gsutil.add_expected(0, '', '') # ls self.gsutil.add_expected(101, '', 'Test error message.') code = download_from_google_storage.download_from_google_storage( input_filename=sha1_hash, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=False, recursive=False, force=True, output=output_filename, ignore_errors=False, sha1_file=False, verbose=True, auto_platform=False, extract=False) expected_calls = [ ('check_call', ('ls', input_filename)), ('check_call', ('cp', input_filename, output_filename)) ] self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 101)
def _DownloadFromBucket(bucket_path, sha1_file, destination, verbose, is_dry_run): '''Downloads the file designated by the provided sha1 from a cloud bucket.''' download_from_google_storage.download_from_google_storage( input_filename=sha1_file, base_url=bucket_path, gsutil=_InitGsutil(is_dry_run), num_threads=1, directory=None, recursive=False, force=False, output=destination, ignore_errors=False, sha1_file=sha1_file, verbose=verbose, auto_platform=True, extract=False)
def Download(arguments): """Download files based on sha1 files in a third_party dir from gcs""" bucket_url, local_path = _CheckPaths(arguments.bucket_path, arguments.local_path) download_from_google_storage.download_from_google_storage( local_path, bucket_url, gsutil=arguments.gsutil, num_threads=1, directory=True, recursive=True, force=False, output=None, ignore_errors=False, sha1_file=None, verbose=arguments.verbose, auto_platform=False, extract=False)
def test_download_directory_no_recursive_non_force(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') code = download_from_google_storage.download_from_google_storage( input_filename=self.base_path, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=True, recursive=False, force=False, output=None, ignore_errors=False, sha1_file=False) expected_calls = [('check_call', ('ls', input_filename)), ('check_call', ('cp', '-q', input_filename, output_filename))] self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 0)
def test_download_directory_no_recursive_non_force(self): sha1_hash = '7871c8e24da15bad8b0be2c36edc9dc77e37727f' input_filename = '%s/%s' % (self.base_url, sha1_hash) output_filename = os.path.join(self.base_path, 'uploaded_lorem_ipsum.txt') code = download_from_google_storage.download_from_google_storage( input_filename=self.base_path, base_url=self.base_url, gsutil=self.gsutil, num_threads=1, directory=True, recursive=False, force=False, output=None, ignore_errors=False, sha1_file=False) expected_calls = [ ('check_call', ('ls', input_filename)), ('check_call', ('cp', '-q', input_filename, output_filename))] self.assertEqual(self.gsutil.history, expected_calls) self.assertEqual(code, 0)