reviewboard.scmtools.managers¶
- class ToolQuerySet(model=None, query=None, using=None, hints=None)[source]¶
Bases:
QuerySet
QuerySet for accessing database-registered SCMTools.
This provides some basic caching capabilities to ensure that common lookups of tools don’t hit the database any more than necessary.
- get(*args, **kwargs)[source]¶
Return a Tool registration from the database.
If querying directly by ID, this will return a cached entry, if available.
If the cache is empty, all database registrations will be queried immediately and cached.
And other queries will proceed as normal, uncached.
- Parameters:
- Returns:
The queried Tool, if found.
- Return type:
- Raises:
reviewboard.scmtools.models.Tool.DoesNotExist – The queried Tool could not be found.
reviewboard.scmtools.models.Tool.MultipleObjectsReturned – Multiple Tools matching the query were found.
- __annotations__ = {}¶
- class ToolManager(*args, **kwargs)[source]¶
Bases:
Manager
Manages Tool models.
Any get() operations performed (directly or indirectly through a ForeignKey) will go through a cache to attempt to minimize Tool lookups.
The Tool cache is never cleared, but as Tool objects should never be modified by hand (they’re registered when doing an rb-site upgrade, and then the server process must be reloaded), this shouldn’t be a problem.
- register_from_entrypoints()[source]¶
Register tools from any package-provided Python Entrypoints.
This will add any new tools that aren’t already in the database.
- Returns:
The list of new tools added to the database.
- Return type:
- get_queryset()[source]¶
Return a QuerySet for Tool models.
- Returns:
The new QuerySet instance.
- Return type:
- clear_tool_cache()[source]¶
Clear the internal cache of Tools.
This is intended for unit tests, and won’t be called during production.
- __annotations__ = {}¶
- __slotnames__ = []¶
- class RepositoryManager(*args, **kwargs)[source]¶
Bases:
Manager
A manager for Repository models.
- accessible(user, *, visible_only=True, local_site=None, distinct=True)[source]¶
Return a queryset for repositories accessible by the given user.
For superusers, all public and private repositories will be returned.
For regular users, only repositories that are public or that the user is on the access lists for (directly or through a review group) will be returned.
For anonymous users, only public repositories will be returned.
The returned list is further filtered down based on the
visible_only
andlocal_site
parameters.Changed in version 6.0: Removed the
show_all_local_sites
argument.Changed in version 5.0: Deprecated
show_all_local_sites
and added support for settinglocal_site
toLocalSite.ALL
.Changed in version 3.0.24: Added the
distinct
parameter.- Parameters:
user (
django.contrib.auth.models.User
) – The user that must have access to any returned repositories.visible_only (
bool
, optional) – Whether only visible repositories should be returned.local_site (
reviewboard.site.models.LocalSite
or :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:`` :class:``reviewboard.site.models.LocalSite.ALL
, optional) –A specific Local Site that the repositories must be associated with. By default, this will only return repositories not part of a site.
This may be
LocalSite.ALL
.Changed in version 5.0: Added support for
LocalSite.ALL
.distinct (
bool
, optional) –Whether to return distinct results.
Turning this off can increase performance. It’s on by default for backwards-compatibility.
- Returns:
The resulting queryset.
- Return type:
- accessible_ids(*args, **kwargs)[source]¶
Return IDs of repositories that are accessible by the given user.
This wraps
accessible()
and takes the same arguments (with the exception ofdistinct
, which is ignored).Callers should not assume order.
Changed in version 3.0.24: In prior versions, the order was not specified, but was generally numeric order. This should still be true, but officially, we no longer guarantee any order of results.
- Parameters:
*args (
tuple
) – Positional arguments to pass toaccessible()
.**kwargs (
dict
) – Keyword arguments to pass toaccessible()
.
- Returns:
The list of IDs.
- Return type:
- get_best_match(repo_identifier, local_site=None)[source]¶
Return a repository best matching the provided identifier.
This is used when a consumer provides a repository identifier of some form (database ID, repository name, path, or mirror path), and needs a single repository back.
If the identifier appears to be a numeric database ID, then an attempt will be made to fetch based on that ID.
Otherwise, this will perform a lookup, fetching all repositories where a name, path, or mirror path match the identifier. If multiple entries are found, the following checks are performed in order to locate a match:
Is there a single visible repository? If so, return that.
Is there a single repository name matching the identifier? If so, return that.
Is there a single repository with a path matching the identifier? If so, return that.
Is there a single repository with a mirror path matching the identifier? If so, return that.
Anything else will cause the lookup to fail.
Note
This does not check whether a user has access to the repository. Access does not influence any of the checks. The caller is expected to check for access permissions using
is_accessible_by()
on the resulting repository.- Parameters:
repo_identifier (
unicode
) – An identifier used to look up a repository.local_site (
reviewboard.site.models.LocalSite
, optional) – An optional Local Site to restrict repositories to.
- Returns:
The resulting repository, if one is found.
- Return type:
- Raises:
reviewboard.scmtools.models.Repository.DoesNotExist – A repository could not be found.
reviewboard.scmtools.models.Repository.MultipleObjectsReturned – Too many repositories matching the identifier were found.
- __annotations__ = {}¶
- __slotnames__ = []¶