pygobbler package¶
Submodules¶
pygobbler.allocate_upload_directory module¶
- pygobbler.allocate_upload_directory.allocate_upload_directory(staging)[source]¶
Allocate a subdirectory in the staging directory to prepare files for upload via
upload_directory()
.
pygobbler.approve_probation module¶
pygobbler.clone_version module¶
- pygobbler.clone_version.clone_version(project, asset, version, destination, registry)[source]¶
Clone the directory structure for a versioned asset into a separate location. This is typically used to prepare a new version for a lightweight upload.
More specifically, cloning involves creating a directory at
destination
that has the same structure as that of the specified project-asset-version. All files in the version are represented as symlinks fromdestination
to the corresponding file in theregistry
.The idea is that, whendestination
is used inupload_directory()
, the symlinks are converted into upload links. This allows users to create new versions very cheaply as duplicate files are not stored in the backend.Users can more-or-less do whatever they want inside the cloned
destination
, but the symlink targets should be read-only as they refer to immutable files in theregistry
. If a file indestination
needs to be modified, the symlink should be deleted and replaced with a new file.
pygobbler.create_project module¶
- pygobbler.create_project.create_project(project, staging, url, owners=None, uploaders=None)[source]¶
Create a new project in the registry.
- Parameters:
project (
str
) – Name of the project to create.staging (
str
) – Path to the staging directory.url (
str
) – URL for the Gobbler REST API.owners (
Optional
[List
]) – List of user IDs of the owners of this project. If not provided, the current user will be set as the sole owner.uploaders (
Optional
[List
]) – List specifying the authorized uploaders for this project. See theuploaders
field infetch_permissions()
return value for the expected format.
- Returns:
On success, the requested project is created in the registry.
pygobbler.fetch_directory module¶
- pygobbler.fetch_directory.fetch_directory(path, registry, url, cache=None, force_remote=False, overwrite=False, concurrent=1)[source]¶
Obtain the path to a directory in the registry. This may create a local copy of the subdirectory’s contents if the caller is not on the same filesystem as the registry.
- Parameters:
path (
str
) – Relative path to a subdirectory within the registry. This usually takes the form ofPROJECT/ASSET/VERSION/*
.registry (
str
) – Path to the registry.url (
str
) – URL to the Gobbler REST API. Only used for remote queries.cache (
Optional
[str
]) – Path to a cache directory. If None, an appropriate location is automatically chosen. Only used for remote access.force_remote (
bool
) – Whether to force remote access. This will download all files in thepath
via the REST API and cache them locally, even ifregistry
is present on the same filesystem.overwrite (
bool
) – Whether to overwrite existing files in the cache.concurrent (
int
) – Number of concurrent downloads.
- Return type:
- Returns:
Path to the subdirectory on the caller’s filesystem. This is either a path to the registry if it is accessible, or a path to a local cache of the registry’s contents otherwise.
pygobbler.fetch_file module¶
- pygobbler.fetch_file.fetch_file(path, registry, url, cache=None, force_remote=False, overwrite=False)[source]¶
Obtain the path to a file in the registry. This may create a local copy if the caller is not on the same filesystem as the registry.
- Parameters:
path (
str
) – Relative path to a file within the registry. This usually takes the form ofPROJECT/ASSET/VERSION/*
.registry (
str
) – Path to the registry.url (
str
) – URL to the Gobbler REST API. Only used for remote queries.cache (
Optional
[str
]) – Path to a cache directory. If None, an appropriate location is automatically chosen. Only used for remote access.force_remote (
bool
) – Whether to force remote access. This will download all files in thepath
via the REST API and cache them locally, even ifregistry
is present on the same filesystem.overwrite (
bool
) – Whether to overwrite existing files in the cache.concurrent – Number of concurrent downloads.
- Return type:
- Returns:
Path to the file on the caller’s filesystem. This is either a path to the file in the registry if it is accessible, or a path to a local cache of the registry’s contents otherwise.
pygobbler.fetch_latest module¶
- pygobbler.fetch_latest.fetch_latest(project, asset, registry, url, force_remote=False)[source]¶
Fetch the latest version of an asset of a project.
- Parameters:
project (
str
) – Name of a project.asset (
str
) – Name of an asset in theproject
.registry (
str
) – Path to the Gobbler registry.url (
str
) – URL of the REST API. Only used for remote queries.force_remote (
bool
) – Whether to force a remote query viaurl
, even if theregistry
is present on the current filesystem.
- Return type:
- Returns:
The name of the latest version of the
asset
, or None if no latest version exists.
pygobbler.fetch_manifest module¶
- pygobbler.fetch_manifest.fetch_manifest(project, asset, version, registry, url, cache=None, force_remote=False, overwrite=False)[source]¶
Fetch the manifest for a version of a project asset.
- Parameters:
project (
str
) – Name of a project.asset (
str
) – Name of an asset in theproject
.version (
str
) – Name of a version of theasset
.registry (
str
) – Path to the Gobbler registry.url (
str
) – URL of the REST API. Only used for remote queries.cache (
Optional
[str
]) – Path to a cache directory. If None, a default cache location is selected. Only used for remote queries.force_remote (
bool
) – Whether to force a remote query viaurl
, even if theregistry
is present on the current filesystem.overwrite (
bool
) – Whether to overwrite existing entries in the cache. Only used for remote queries.
- Return type:
- Returns:
Dictionary containing the manifest. Each key is a relative path to a file in this version of the project asset, and each value is a dictionary with the following fields:
size
, integer specifying the size of the file in bytes.md5sum
, string containing the file’s hex-encoded MD5 checksum.link
(optional): a list specifying the link destination for a file. This contains the stringsproject
,asset
,version
andpath
; if the link destination is also a link, anancestor
dictionary will be present containing the final location of the file after resolving all intermediate links.
pygobbler.fetch_permissions module¶
- pygobbler.fetch_permissions.fetch_permissions(project, registry, url, asset=None, force_remote=False)[source]¶
Fetch permissions for a project.
- Parameters:
project (
str
) – Name of a project.registry (
str
) – Path to the Gobbler registry.url (
str
) – URL of the REST API. Only used for remote queries.asset (
Optional
[str
]) – Name of the asset inside the project. If supplied, permissions are returned for this asset rather than the entire project.force_remote (
bool
) – Whether to force a remote query viaurl
, even if theregistry
is present on the current filesystem.
- Return type:
- Returns:
A dictionary containing the permissions for the
project
. This containsowners
, a list of strings with the user IDs of the owners of this project; anduploaders
, a list of dictionaries where each dictionary has the following fields:id
, string containing a user ID that is authorized to upload.asset
(optional), string containing the name of the asset that the uploader is allowed to upload to. If not present, there is no restriction on the uploaded asset name.version
(optional), string containing the name of the version that the uploader is allowed to upload to. If not present, there is no restriction on the uploaded version name.until
(optional), string containing the expiry date of this authorization in Internet Date/Time format. If not provided, the authorization does not expire.trusted
(optional), whether the uploader is trusted. If not provided, defaults to false.
The top-level dictionary may also contain global_write, a boolean indicating whether global writes are supported. If true, any user may create a new asset in this project, and each user can upload new versions to any asset they created under this mode.
If
asset
is provided, the returned dictionary containsowners
anduploaders
to describe the owners and uploaders, respectively, for the specifiedasset
.
pygobbler.fetch_summary module¶
- pygobbler.fetch_summary.fetch_summary(project, asset, version, registry, url, cache=None, force_remote=False, overwrite=False)[source]¶
Fetch the summary for a particular version of a project asset.
- Parameters:
project (
str
) – Name of a project.asset (
str
) – Name of an asset in theproject
.version (
str
) – Name of a version of theasset
.registry (
str
) – Path to the Gobbler registry.url (
str
) – URL of the REST API. Only used for remote queries.cache (
Optional
[str
]) – Path to a cache directory. If None, a default cache location is selected. Only used for remote queries.force_remote (
bool
) – Whether to force a remote query viaurl
, even if theregistry
is present on the current filesystem.overwrite (
bool
) – Whether to overwrite existing entries in the cache. Only used for remote queries.
- Returns:
uploader_user_id
, string containing the UID of the uploading user.upload_start_time
, string containing the upload start time in Internet Date/Time format.upload_finish_time
, string containing the upload finish time in Internet Date/Time format.on_probation
(optional), boolean indicating whether this version of the asset is a probational upload.
- Return type:
Dictionary containing summary information including
pygobbler.fetch_usage module¶
pygobbler.list_assets module¶
pygobbler.list_files module¶
- pygobbler.list_files.list_files(project, asset, version, registry, url, prefix=None, include_dotdot=True, force_remote=False)[source]¶
List the contents of a version of a project asset.
- Parameters:
project (
str
) – The name of the project.asset (
str
) – The name of the asset inproject
.version (
str
) – The name of the version of theasset
.registry (
str
) – Path to the registry.url (
str
) – URL to the Gobbler REST API. Only used for remote access.prefix (
Optional
[str
]) – Prefix for the path within this version’s subdirectory. If provided, files are only listed if they have a relative path (i.e., inside the version subdirectory) that starts with this prefix. If None, all files associated with this version are listed.include_dotdot (
bool
) – Whether to list files with path components that start with..
.force_remote (
bool
) – Whether to force remote access via the API, even ifregistry
is on the same filesystem as the caller.
- Return type:
- Returns:
List of strings containing the relative paths of files associated with the versioned asset. All paths will start with
prefix
if provided.
pygobbler.list_projects module¶
pygobbler.list_versions module¶
- pygobbler.list_versions.list_versions(project, asset, registry, url, force_remote=False)[source]¶
List all versions of a project asset.
- Parameters:
project (
str
) – The name of the project.asset (
str
) – The name of the asset inproject
.registry (
str
) – Path to the registry.url (
str
) – URL to the Gobbler REST API. Only used for remote access.force_remote (
bool
) – Whether to force remote access via the API, even ifregistry
is on the same filesystem as the caller.
- Return type:
- Returns:
List of strings containing the project names.
pygobbler.refresh_latest module¶
pygobbler.refresh_usage module¶
pygobbler.reindex_version module¶
pygobbler.reject_probation module¶
- pygobbler.reject_probation.reject_probation(project, asset, version, staging, url, force=False)[source]¶
Reject a probational upload of a version of a project’s asset.
- Parameters:
project (
str
) – The name of the project.asset (
str
) – The name of the asset of theproject
.version (
str
) – The name of the version of theasset
to reject.staging (
str
) – Path to the staging directory.url (
str
) – URL to the Gobbler REST API.force (
bool
) – Whether the version should be forcibly rejected and removed if it contains invalid files. If this needs to be set toTrue
, users may need to callrefresh_usage`()
afterwards to correct project-level usage statistics.
pygobbler.remove_asset module¶
- pygobbler.remove_asset.remove_asset(project, asset, staging, url, force=False)[source]¶
Remove an asset of a project from the registry. This should only be performed by Gobbler instance administrators. Consider running
reroute_links()
beforehand to avoid dangling references to files in this asset.- Parameters:
project (
str
) – The name of the project.asset (
str
) – The name of the asset to remove.staging (
str
) – Path to the staging directory.url (
str
) – URL to the Gobbler REST API.force (
bool
) – Whether the asset should be forcibly removed if it contains invalid files. If this needs to be set toTrue
, users may need to callrefresh_usage`()
afterwards to correct project-level usage statistics.
pygobbler.remove_project module¶
- pygobbler.remove_project.remove_project(project, staging, url)[source]¶
Remove a project from the registry. This should only be performed by Gobbler instance administrators. Consider running
reroute_links()
beforehand to avoid dangling references to files in this project.
pygobbler.remove_version module¶
- pygobbler.remove_version.remove_version(project, asset, version, staging, url, force=False)[source]¶
Remove a version of a project asset from the registry. This should only be performed by Gobbler instance administrators. Consider running
reroute_links()
beforehand to avoid dangling references to files in this version.- Parameters:
project (
str
) – The name of the project.asset (
str
) – The name of the asset of theproject
.version (
str
) – The name of the version of theasset
to remove.staging (
str
) – Path to the staging directory.force (
bool
) – Whether the version should be forcibly removed if it contains invalid files. If this needs to be set toTrue
, users may need to callrefresh_usage`()
afterwards to correct project-level usage statistics. Similarly,refresh_latest()
may also need to be called.url (
str
) – URL to the Gobbler REST API.
pygobbler.reroute_links module¶
- pygobbler.reroute_links.reroute_links(to_delete, staging, url, dry_run=False)[source]¶
Reroute symbolic links to files in directories that are to be deleted, e.g., by
remove_project()
. This preserves the validity of links within the Gobbler registry.Note that rerouting does not actually delete the directories specified in
to_delete
. Deletion requires separate invocations ofremove_project()
and friends - preferably after the user has verified that rerouting was successful!Rerouting is not necessary if
to_delete
consists only of probational versions, or projects/assets containing only probational versions. The Gobbler should never create links to files in probational version directories.- Parameters:
to_delete (
List
) – List of projects, assets or versions to be deleted. Each entry should be a dicionary containing at least theproject
name. When deleting an asset, the inner list should contain an additionalasset
name. When deleting a version, the inner list should contain additionalasset
andversion
names. Different inner lists may specify different projects, assets or versions.staging (
str
) – Path to the staging directory.url (
str
) – URL for the Gobbler REST API.dry_run (
bool
) – Whether to perform a dry run of the rerouting.
- Return type:
- Returns:
List of dictionaries. Each dictionary represents a rerouting action and contains the following fields.
path
, string containing the path to a symbolic link in the registry that was changed by rerouting.copy
, boolean indicating whether the link atpath
was replaced by a copy of its target file. IfFalse
, the link was merely updated to refer to a new target file.source
, the path to the target file that caused rerouting ofpath
. Specifically, this is a file in one of the to-be-deleted directories specified into_delete
. Ifcopy = TRUE
, this is the original linked-to file that was copied topath
.
If
dry_run = False
, the registry is modified as described by the rerouting actions. Otherwise, no modifications are performed to the registry.
pygobbler.service_info module¶
pygobbler.set_permissions module¶
- pygobbler.set_permissions.set_permissions(project, registry, staging, url, asset=None, owners=None, uploaders=None, global_write=None, append=True)[source]¶
Set the owner and uploader permissions for a project.
- Parameters:
project (
str
) – Name of the project.registry (
str
) – Path to the Gobbler registry.staging (
str
) – Path to the staging directory.url (
str
) – URL of the REST API.asset (
Optional
[str
]) – Name of the asset inside the project. If supplied, permissions are set on this asset rather than the entire project.owners (
Optional
[List
]) – List of user IDs for owners of this project. If None, no change is made to the existing owners in the project permissions.uploaders (
Optional
[Dict
]) – List of dictionaries specifying the authorized uploaders for this project. See theuploaders
field in the return value offetch_permissions()
for the expected format. If None, no change is made to the existing uploaders.global_write (
Optional
[bool
]) – Whether to enable global writes for this project, see theglobal_write
field in the return value offetch_permissions()
for more details. If None, no change is made to the global write status. Ignored ifasset
is provided.append (
bool
) – Whetherowners
anduploaders
should be appended to the existing owners and uploaders, respectively. If False, theowners
anduploaders
are used to replace the existing values in the project permissions.
pygobbler.start_gobbler module¶
- pygobbler.start_gobbler.start_gobbler(staging=None, registry=None, port=None, wait=1, version='0.4.0', overwrite=False)[source]¶
Start a test Gobbler service.
- Parameters:
registry (
Optional
[str
]) – Path to a registry directory. If None, a temporary directory is automatically created.staging (
Optional
[str
]) – Path to a registry directory. If None, a temporary directory is automatically created.port (
Optional
[int
]) – Port number for the Gobbler API to receive requests. If None, an open port is automatically chosen.wait (
float
) – Number of seconds to wait for the service to initialize before use.version (
str
) – Version of the service to run.overwrite (
bool
) – Whether to overwrite the existing Gobbler binary.
- Return type:
- Returns:
A tuple indicating whether a new test service was created (or an existing instance was re-used), the path to the staging directory, the path to the registry, and the chosen URL. If a service is already running, this function is a no-op and the configuration details of the existing service will be returned.
- pygobbler.start_gobbler.stop_gobbler()[source]¶
Stop any gobbler test service started by
start_gobbler()
. If no test service was running, this function is a no-op.
pygobbler.unpack_path module¶
pygobbler.upload_directory module¶
- pygobbler.upload_directory.upload_directory(project, asset, version, directory, staging, url, probation=False, consume=None, ignore_dot=True)[source]¶
Upload a directory as a new versioned asset of a project in the registry.
- Parameters:
project (
str
) – The name of an existing project.asset (
str
) – The name of a new or existing asset inproject
.version (
str
) – The name of a new version ofasset
.directory (
str
) – Path to a directory to be uploaded. For best performace, this should be a subdirectory ofstaging
, e.g., as created byallocate_upload_directory()
.staging (
str
) – Path to the staging directory.url (
str
) – URL for the Gobbler REST API.probation (
bool
) – Whether to upload a probational version.consume (
Optional
[bool
]) – Whether the contents ofdirectory
can be consumed by the upload process. If true, the Gobbler will attempt to move files fromdirectory
into the registry. Otherwise, the contents ofdirectory
will not be modified by the upload. Defaults to true if the contents ofdirectory
need to be copied tostaging
.ignore_dot (
bool
) – Whether to skip dotfiles indirectory
during upload.
pygobbler.version_path module¶
- pygobbler.version_path.version_path(project, asset, version, **kwargs)[source]¶
Obtain the path to a versioned asset in the registry.
- Parameters:
project – The name of the project.
asset – The name of the asset of the
project
.version – The name of the version of the
asset
to obtain.kwargs – Further arguments to
fetch_directory()
.
- Return type:
- Returns:
The path to the directory containing the desired version.