forked from ckan/ckanext-report
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from qld-gov-au/develop
Develop to master
- Loading branch information
Showing
33 changed files
with
843 additions
and
353 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[flake8] | ||
# @see https://flake8.pycqa.org/en/latest/user/configuration.html?highlight=.flake8 | ||
|
||
exclude = | ||
ckan | ||
scripts | ||
|
||
# Extended output format. | ||
format = pylint | ||
|
||
# Show the source of errors. | ||
show_source = True | ||
|
||
max-complexity = 10 | ||
max-line-length = 127 | ||
|
||
# List ignore rules one per line. | ||
ignore = | ||
C901 | ||
W503 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
name: Tests | ||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.6' | ||
- name: Cache pip | ||
uses: actions/cache@v2 | ||
with: | ||
# This path is specific to Ubuntu | ||
path: ~/.cache/pip | ||
# Look to see if there is a cache hit for the corresponding requirements file | ||
key: ${{ runner.os }}-pip-flake8-${{ hashFiles('requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip-flake8- | ||
${{ runner.os }}- | ||
- name: Install requirements | ||
run: pip install flake8 pycodestyle | ||
- name: Check syntax | ||
run: flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics --exclude ckan | ||
|
||
test: | ||
needs: lint | ||
strategy: | ||
matrix: | ||
ckan-version: [2.9, 2.9-py2, 2.8, 2.7] | ||
fail-fast: false | ||
|
||
name: CKAN ${{ matrix.ckan-version }} | ||
runs-on: ubuntu-latest | ||
container: | ||
image: openknowledge/ckan-dev:${{ matrix.ckan-version }} | ||
services: | ||
solr: | ||
image: ckan/ckan-solr-dev:${{ matrix.ckan-version }} | ||
postgres: | ||
image: ckan/ckan-postgres-dev:${{ matrix.ckan-version }} | ||
env: | ||
POSTGRES_USER: postgres | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: postgres | ||
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 | ||
redis: | ||
image: redis:3 | ||
env: | ||
CKAN_SQLALCHEMY_URL: postgresql://ckan_default:pass@postgres/ckan_test | ||
CKAN_DATASTORE_WRITE_URL: postgresql://datastore_write:pass@postgres/datastore_test | ||
CKAN_DATASTORE_READ_URL: postgresql://datastore_read:pass@postgres/datastore_test | ||
CKAN_SOLR_URL: http://solr:8983/solr/ckan | ||
CKAN_REDIS_URL: redis://redis:6379/1 | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Cache pip | ||
uses: actions/cache@v2 | ||
with: | ||
# This path is specific to Ubuntu | ||
path: ~/.cache/pip | ||
# Look to see if there is a cache hit for the corresponding requirements file | ||
key: ${{ runner.os }}-pip-${{ hashFiles('*requirements.txt') }} | ||
restore-keys: | | ||
${{ runner.os }}-pip- | ||
${{ runner.os }}- | ||
- name: Install requirements | ||
run: | | ||
pip install -r requirements-dev.txt | ||
pip install -e . | ||
# Replace default path to CKAN core config file with the one on the container | ||
sed -i -e 's/use = config:.*/use = config:\/srv\/app\/src\/ckan\/test-core.ini/' test.ini | ||
- name: Setup extension (CKAN >= 2.9) | ||
if: ${{ matrix.ckan-version != '2.7' && matrix.ckan-version != '2.8' }} | ||
run: | | ||
ckan -c test.ini db init | ||
ckan -c test.ini report initdb | ||
ckan -c test.ini report generate tagless-datasets | ||
- name: Setup extension (CKAN < 2.9) | ||
if: ${{ matrix.ckan-version == '2.7' || matrix.ckan-version == '2.8' }} | ||
run: | | ||
paster --plugin=ckan db init -c test.ini | ||
paster --plugin=ckanext-report report initdb -c test.ini | ||
paster --plugin=ckanext-report report generate tagless-datasets -c test.ini | ||
- name: Run tests | ||
run: pytest --ckan-ini=test.ini --cov=ckanext.report --disable-warnings ckanext/report/tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# encoding: utf-8 | ||
|
||
import click | ||
|
||
from ckanext.report.cli.command import Reporting | ||
|
||
# Click commands for CKAN 2.9 and above | ||
|
||
|
||
@click.group() | ||
def report(): | ||
""" XLoader commands | ||
""" | ||
pass | ||
|
||
|
||
@report.command() | ||
def list(): | ||
""" Lists the reports | ||
""" | ||
cmd = Reporting() | ||
cmd.list() | ||
|
||
|
||
@report.command() | ||
def initdb(): | ||
""" Initialize the database tables for this extension | ||
""" | ||
cmd = Reporting() | ||
cmd.initdb() | ||
|
||
|
||
@report.command() | ||
@click.argument(u'report_names') | ||
def generate(report_names): | ||
""" | ||
Generate and cache reports - all of them unless you specify | ||
a comma separated list of them. | ||
""" | ||
cmd = Reporting() | ||
report_list = [s.strip() for s in report_names.split(',')] | ||
cmd.generate(report_list) | ||
|
||
|
||
@report.command() | ||
@click.argument(u'report_name') | ||
@click.argument(u'options', nargs=-1) | ||
def generate_for_options(report_name, options): | ||
""" | ||
Generate and cache a report for one combination of option values. | ||
You can leave it with the defaults or specify options | ||
as more parameters: key1=value key2=value | ||
""" | ||
cmd = Reporting() | ||
report_options = {} | ||
for option_arg in options: | ||
if '=' not in option_arg: | ||
raise click.BadParameter( | ||
'Option needs an "=" sign in it', | ||
options) | ||
equal_pos = option_arg.find('=') | ||
key, value = option_arg[:equal_pos], option_arg[equal_pos + 1:] | ||
if value == '': | ||
value = None # this is what the web i/f does with params | ||
report_options[key] = value | ||
cmd.generate_for_options(report_name, report_options) | ||
|
||
|
||
def get_commands(): | ||
return [report] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# encoding: utf-8 | ||
|
||
import logging | ||
import time | ||
|
||
|
||
class Reporting(): | ||
|
||
def __init__(self): | ||
self.log = logging.getLogger("ckanext.report.cli") | ||
|
||
def initdb(self): | ||
from ckanext.report import model | ||
model.init_tables() | ||
self.log.info('Report table is setup') | ||
|
||
def list(self): | ||
from ckanext.report.report_registry import ReportRegistry | ||
registry = ReportRegistry.instance() | ||
for plugin, report_name, report_title in registry.get_names(): | ||
report = registry.get_report(report_name) | ||
date = report.get_cached_date() | ||
print('%s: %s %s' % (plugin, report_name, | ||
date.strftime('%d/%m/%Y %H:%M') if date else '(not cached)')) | ||
|
||
def generate(self, report_list=None): | ||
from ckanext.report.report_registry import ReportRegistry | ||
timings = {} | ||
|
||
self.log.info("Running reports => %s", report_list) | ||
registry = ReportRegistry.instance() | ||
if report_list: | ||
for report_name in report_list: | ||
s = time.time() | ||
registry.get_report(report_name).refresh_cache_for_all_options() | ||
timings[report_name] = time.time() - s | ||
else: | ||
s = time.time() | ||
registry.refresh_cache_for_all_reports() | ||
timings["All Reports"] = time.time() - s | ||
|
||
self.log.info("Report generation complete %s", timings) | ||
|
||
def generate_for_options(self, report_name, options): | ||
from ckanext.report.report_registry import ReportRegistry | ||
self.log.info("Running report => %s", report_name) | ||
registry = ReportRegistry.instance() | ||
report = registry.get_report(report_name) | ||
all_options = report.add_defaults_to_options(options, | ||
report.option_defaults) | ||
report.refresh_cache(all_options) |
Oops, something went wrong.