Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Merge pull request #17 from NaturalHistoryMuseum/josh/ckan-upgrade-2.9
Browse files Browse the repository at this point in the history
CKAN 2.9.x upgrade
  • Loading branch information
jrdh committed Mar 9, 2021
2 parents e456c31 + 55cf4b6 commit 423a65a
Show file tree
Hide file tree
Showing 32 changed files with 439 additions and 300 deletions.
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[run]
relative_files = True
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ __pycache__/
pip-log.txt
pip-delete-this-directory.txt

.idea
.coverage
21 changes: 9 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
dist: trusty
language: python

python:
- "2.7"
sudo: required

install:
- sh ckanext/ckanpackager/tests/bin/build.sh
language: python

services:
- redis-server
- postgresql
- docker

addons:
postgresql: "9.4"
# we need coveralls and this also prevents travis from running pip install -r requirements.txt
install: pip install coveralls

script: coverage run --source=ckanext.ckanpackager setup.py nosetests --ckan --with-pylons=ckanext/ckanpackager/tests/bin/test.ini --nologcapture --debug=ckantest,ckanext.ckanpackager --rednose
script:
- docker-compose build
- docker-compose run ckan

after_success: coveralls

21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2014 Philippe Duchesne

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

[![Travis](https://img.shields.io/travis/NaturalHistoryMuseum/ckanext-ckanpackager/master.svg?style=flat-square)](https://travis-ci.org/NaturalHistoryMuseum/ckanext-ckanpackager)
[![Coveralls](https://img.shields.io/coveralls/github/NaturalHistoryMuseum/ckanext-ckanpackager/master.svg?style=flat-square)](https://coveralls.io/github/NaturalHistoryMuseum/ckanext-ckanpackager)
[![CKAN](https://img.shields.io/badge/ckan-2.9.0a-orange.svg?style=flat-square)](https://github.com/ckan/ckan)
[![CKAN](https://img.shields.io/badge/ckan-2.9.1-orange.svg?style=flat-square)](https://github.com/ckan/ckan)
[![Python](https://img.shields.io/badge/python-3.6%20%7C%203.7%20%7C%203.8-blue.svg?style=flat-square)](https://www.python.org/)

_A CKAN extension that provides a user interface to download resources with [ckanpackager](http://github.com/NaturalHistoryMuseum/ckanpackager)._

Expand Down Expand Up @@ -80,7 +81,7 @@ Name|Description|Options
1. Initialise the database table:

```bash
paster --plugin=ckanext-ckanpackager initdb -c $CONFIG_FILE
ckan -c $CONFIG_FILE ckanpackager initdb
```

# Usage
Expand Down Expand Up @@ -109,12 +110,11 @@ toolkit.get_action('packager_stats')(
## Commands

### `initdb`
Initialises the ckanpackager database table.
Initialises the ckanpackager database tables.

1.
```bash
paster --plugin=ckanext-ckanpackager initdb -c $CONFIG_FILE
```
```bash
ckan -c $CONFIG_FILE ckanpackager initdb
```

## Templates

Expand All @@ -128,10 +128,24 @@ Add the following snippet to templates where you want the button to appear:


# Testing

_Test coverage is currently extremely limited._

To run the tests, use nosetests inside your virtualenv. The `--nocapture` flag will allow you to see the debug statements.
To run the tests in this extension, there is a Docker compose configuration available in this
repository to make it easy.

To run the tests against ckan 2.9.x on Python3:

1. Build the required images
```bash
nosetests --ckan --with-pylons=$TEST_CONFIG_FILE --where=$INSTALL_FOLDER/src/ckanext-ckanpackager --nologcapture --nocapture
docker-compose build
```

2. Then run the tests.
The root of the repository is mounted into the ckan container as a volume by the Docker compose
configuration, so you should only need to rebuild the ckan image if you change the extension's
dependencies.
```bash
docker-compose run ckan
```

The ckan image uses the Dockerfile in the `docker/` folder which is based on `openknowledge/ckan-dev:2.9-py2`.
28 changes: 28 additions & 0 deletions ckanext/ckanpackager/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import click

from ckan import model
from .model.stat import ckanpackager_stats_table


def get_commands():
return [ckanpackager]


@click.group()
def ckanpackager():
'''
The CKAN Packager CLI.
'''
pass


@ckanpackager.command(name='initdb')
def init_db():
'''
Initialise the ckanpackager tables.
'''
if not ckanpackager_stats_table.exists(model.meta.engine):
ckanpackager_stats_table.create(model.meta.engine)
click.secho('Created ckanpackager_stats table', fg='green')
else:
click.secho('ckanpackager_stats already exists, skipping init', fg='green')
13 changes: 0 additions & 13 deletions ckanext/ckanpackager/commands/__init__.py

This file was deleted.

37 changes: 0 additions & 37 deletions ckanext/ckanpackager/commands/initdb.py

This file was deleted.

3 changes: 1 addition & 2 deletions ckanext/ckanpackager/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
class ICkanPackager(interfaces.Interface):
''' '''

def before_package_request(self, resource_id, package_id, packager_url,
request_params):
def before_package_request(self, resource_id, package_id, packager_url, request_params):
'''Allows modification of the packager url and request parameters right before
the request is sent to the
ckanpackager backend. Must return both as a tuple.
Expand Down
8 changes: 4 additions & 4 deletions ckanext/ckanpackager/lib/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@


def should_show_format_options(resource_id):
'''Determines whether the format options should be shown for a given resource id.
'''
Determines whether the format options should be shown for a given resource id.
:param resource_id: the resource's id
:returns: True if they should be shown, False if not
'''
resource = toolkit.get_action(u'resource_show')({}, dict(id=resource_id))
resource = toolkit.get_action('resource_show')({}, dict(id=resource_id))
# currently we just predicate on whether the resource is in the datastore or not
return resource.get(u'datastore_active', False)
return resource.get('datastore_active', False)

0 comments on commit 423a65a

Please sign in to comment.