Skip to content

Commit

Permalink
chore: pin version
Browse files Browse the repository at this point in the history
  • Loading branch information
smotornyuk committed Mar 12, 2024
1 parent b423341 commit 2424843
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 43 deletions.
92 changes: 53 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,77 +1,91 @@
# ckanext-files

Upload and use standalone files. No resources, no datasets, just files.

Files as first-class citizens of CKAN. Upload, manage, remove files directly
and attach them to datasets, resources, etc.

## Requirements


Compatibility with core CKAN versions:

| CKAN version | Compatible? |
|--------------|-------------|
| 2.8 | yes |
| 2.9 | yes |
| 2.10 | yes |
| master | yes |

CKAN v2.8 and v2.9 are supported by ckanext-files v0.2. Starting from v1.0 this
extension switches to CKAN support policy of two latest CKAN releases. I.e,
ckanext-files v1.0 supports only CKAN v2.10 and v2.11.

alembic==1.4
v0.2 will not receive any new features, only bug-fixes.

It's recommended to install the extension via pip, so you probably have all the
requirements pinned already. If you are using GitHub version of this extension,
stick to the vX.Y.Z tags to avoid breaking changes. Check the changelog before
upgrading the extension.

## Installation

To install ckanext-files:

1. Install the extension
```sh
# minimal installation
pip install ckanext-files

pip install ckanext-files
# Google Cloud Storage support
pip install 'ckanext-files[gcstorage]'
```

1. Add `files` to the `ckan.plugins` setting in your CKAN
config file.

1. Updgrade DB

ckan db upgrade -p files
1. Run DB migrations
```sh
# CKAN >= v2.9 with alembic
ckan db upgrade -p files
## API
# CKAN == v2.8
paster --plugin=ckanext-files files -c ckan.ini initdb
```

Each API action has corresponding auth-function with the same name. By default
only sysadmin can pass auth check(unless different behavior explicitly
mentioned in action description). Whenever you are using this extension feel
free to redefine these auth-functions using `tk.chained_auth_function`.
## Usage

Some of API actions has `kind` parameter. It defines which folder will store
the file, which config options will be applied, etc. Default value is
`ckanext_files_file`

* `files_file_create`

Create new `file` entity.
## Configuration

Parameters:
* `name` Name for the uploaded file.
* `upload` File itself
* `kind` Type of uploaded file.
* `extras` Dictionary with any details that can be used for your needs.
There are two types of config options for ckanext-files:
* Global configuration affects the common behavior of the extension
* Storage configuration changes behavior of the specific storage and never
affects anything outside of the storage

Returns:
* `id: str` Unique ID of the new `file`.
* `name: str` Name for the `file`.
* `url: str` File itself
* `kind: str` Type of uploaded file.
* `uploaded_at: datetime.datetime` File creation date
* `extras: Optional[dict[str, Any]]` Dictionary with any details that can be used for your needs.
Depending on the type of the storage, available options for storage change. For
example, `files:fs` storage type requires `path` option that controls
filesystem path where uploads are stored. `files:redis` storage type accepts
`prefix` option that defines Redis' key prefix of files stored in Redis. All
storage specific options always have form
`ckanext.files.storage.<STORAGE>.<OPTION>`:
* `files_file_show`
```ini
ckanext.files.storage.memory.prefix = xxx:
# or
ckanext.files.storage.my_drive.path = /tmp/hello
```
Show `file` detiles.
Below is the list of non-storage specific options. Details of the specific
storage type can be found in the dedicated section of the storage type.
Parameters:
* `id: str`: ID or name of file entity
```ini
Returns: same as `files_file_create`
# Default storage used for upload when no explicit storage specified
# (optional, default: default)
ckanext.files.default_storage = default
# Configuration of the named storage.
# (optional, default: )
ckanext.files.storage.<NAME>.<OPTION> =
## Config settings
# Allowed size for uploaded file in MB.
# (optional, default: 2).
ckanext.files.kind.<KIND>.max_size = 2
```
2 changes: 1 addition & 1 deletion ckanext/files/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def storages():
# type: () -> dict[str, dict[str, Any]]
"""Mapping of storage names to their settings."""

storages = defaultdict(lambda: defaultdict(dict)) # type: dict[str, dict[str, Any]]
storages = defaultdict(dict) # type: dict[str, dict[str, Any]]
prefix_len = len(STORAGE_PREFIX)
for k, v in tk.config.items():
if not k.startswith(STORAGE_PREFIX):
Expand Down
4 changes: 2 additions & 2 deletions ckanext/files/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ def declare_config_options(self, declaration, key):
separators=(",", ":"),
)

declaration.declare(storage_key.type).append_validators(
declaration.declare(storage_key.type, settings.get("type")).append_validators(
"one_of({})".format(available_adapters),
)
).set_description("Storage adapter used by the storage")

adapter = base.adapters.get(settings.get("type"))
if not adapter:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = ckanext-files
version = 0.1.0
version = 0.2.0
description =
long_description = file: README.md
long_description_content_type = text/markdown
Expand Down

0 comments on commit 2424843

Please sign in to comment.