def _GetStagedFile(self, file_str): """Validate file URI and register it for uploading if it is local.""" drive, _ = os.path.splitdrive(file_str) uri = six.moves.urllib.parse.urlsplit(file_str, allow_fragments=False) # Determine the file is local to this machine if no scheme besides a drive # is passed. file:// URIs are interpreted as living on VMs. is_local = drive or not uri.scheme if not is_local: # Non-local files are already staged. # TODO(b/36057257): Validate scheme. return file_str if not os.path.exists(file_str): raise files.Error('File Not Found: [{0}].'.format(file_str)) if self._staging_dir is None: # we raise this exception only if there are files to stage but the staging # location couldn't be determined. In case where files are already staged # this exception is not raised raise exceptions.ArgumentError( 'Could not determine where to stage local file {0}. When submitting ' 'a job to a cluster selected via --cluster-labels, either\n' '- a staging bucket must be provided via the --bucket argument, or\n' '- all provided files must be non-local.'.format(file_str)) basename = os.path.basename(file_str) self.files_to_stage.append(file_str) staged_file = six.moves.urllib.parse.urljoin(self._staging_dir, basename) return staged_file
def testSaveWithError(self): fake_cred = self.GetFakeCred('*****@*****.**') self.mock_webflow.return_value = fake_cred self.StartObjectPatch( files, 'PrivatizeFile').side_effect = files.Error('Error') with self.assertRaisesRegex(creds.CredentialFileSaveError, 'Error saving Application'): self.Login()
def _GetStagedFile(self, file_str): """Validate file URI and register it for uploading if it is local.""" drive, _ = os.path.splitdrive(file_str) uri = six.moves.urllib.parse.urlsplit(file_str, allow_fragments=False) # Determine the file is local to this machine if no scheme besides a drive # is passed. file:// URIs are interpreted as living on VMs. is_local = drive or not uri.scheme if not is_local: # Non-local files are already staged. Let the API determine URI validation return file_str if not os.path.exists(file_str): raise files.Error('File Not Found: [{0}].'.format(file_str)) basename = os.path.basename(file_str) self.files_to_stage.append(file_str) staged_file = six.moves.urllib.parse.urljoin(self._staging_dir, basename) return staged_file
def testGetModulePathObject(self): self.assertEqual( 'googlecloudsdk.core.util.files:Error', module_util.GetModulePath(files.Error('Something happened')))
def testSaveWithError(self): self.StartObjectPatch(files, 'PrivatizeFile').side_effect = files.Error('Error') with self.assertRaisesRegex(creds.CredentialFileSaveError, 'Error saving Application'): self.Login()