def _api_get_src(self, repository, path, revision, base_commit_id): # If a base commit ID is provided, use it. It may not be provided, # though, and in this case, we need to use the provided revision, # which will work for Mercurial but not for Git. # # If not provided, and using Git, we'll give the user a File Not # Found error with some info on what they need to do to correct # this. if base_commit_id: revision = base_commit_id elif repository.tool.name == 'Git': raise FileNotFoundError( path, revision, detail='The necessary revision information needed to find ' 'this file was not provided. Use RBTools 0.5.2 or ' 'newer.') url = self._build_api_url( 'repositories/%s/%s/raw/%s/%s' % (quote(self._get_repository_owner(repository)), quote(self._get_repository_name(repository)), quote(revision), quote(path))) return self._api_get(url, raw_content=True)
def _api_get_src(self, repository, path, revision, base_commit_id): # If a base commit ID is provided, use it. It may not be provided, # though, and in this case, we need to use the provided revision, # which will work for Mercurial but not for Git. # # If not provided, and using Git, we'll give the user a File Not # Found error with some info on what they need to do to correct # this. if base_commit_id: revision = base_commit_id elif repository.tool.name == "Git": raise FileNotFoundError( path, revision, detail="The necessary revision information needed to find " "this file was not provided. Use RBTools 0.5.2 or " "newer.", ) url = self._build_api_url( "repositories/%s/%s/raw/%s/%s" % ( quote(self._get_repository_owner(repository)), quote(self._get_repository_name(repository)), quote(revision), quote(path), ) ) return self._api_get(url, raw_content=True)
def _api_get_node(self, repository, path, revision, base_commit_id, contents=False): # Unless we're fetching raw content, we optimistically want to # grab the metadata for the file. That's going to be a lot smaller # than the file contents in most cases. However, we can only do that # with a base_commit_id. If we don't have that, we fall back on # fetching the full file contents. raw_content = contents or not base_commit_id if raw_content: url_path = "blob?id=%s&name=%s" % (quote(revision), quote(os.path.basename(path))) else: url_path = "node.json?path=%s&revision=%s&contents=0" % (quote(path), quote(base_commit_id)) url = self._build_api_url( self._get_repository_account_domain(repository), "repositories/%s/%s" % (repository.extra_data["beanstalk_repo_name"], url_path), ) return self._api_get(url, raw_content=True)
def _api_get_node(self, repository, path, revision, base_commit_id, contents=False): # Unless we're fetching raw content, we optimistically want to # grab the metadata for the file. That's going to be a lot smaller # than the file contents in most cases. However, we can only do that # with a base_commit_id. If we don't have that, we fall back on # fetching the full file contents. raw_content = (contents or not base_commit_id) if raw_content: url_path = ('blob?id=%s&name=%s' % (quote(revision), quote(os.path.basename(path)))) else: url_path = ('node.json?path=%s&revision=%s&contents=0' % (quote(path), quote(base_commit_id))) url = self._build_api_url( self._get_repository_account_domain(repository), 'repositories/%s/%s' % (repository.extra_data['beanstalk_repo_name'], url_path)) return self._api_get(url, raw_content=True)
def _do_on_path(self, cb, path, revision=HEAD): if not path: raise FileNotFoundError(path, revision) try: normpath = self.__normalize_path(path) # SVN expects to have URLs escaped. Take care to only # escape the path part of the URL. if self.client.is_url(normpath): pathtuple = urlsplit(normpath) path = pathtuple[2] if isinstance(path, six.text_type): path = path.encode('utf-8', 'ignore') normpath = urlunsplit((pathtuple[0], pathtuple[1], quote(path), '', '')) normrev = self.__normalize_revision(revision) return cb(normpath, normrev) except ClientError as e: stre = six.text_type(e) if 'File not found' in stre or 'path not found' in stre: raise FileNotFoundError(path, revision, detail=six.text_type(e)) elif 'callback_ssl_server_trust_prompt required' in stre: raise SCMError( _('HTTPS certificate not accepted. Please ensure that ' 'the proper certificate exists in %s ' 'for the user that reviewboard is running as.') % os.path.join(self.config_dir, 'auth')) elif 'callback_get_login required' in stre: raise AuthenticationError( msg=_('Login to the SCM server failed.')) else: raise SCMError(e)