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 #12 from qld-gov-au/QOL-9161-upstream-sync
QOL-9161 sync from upstream and fix bugs
- Loading branch information
Showing
30 changed files
with
502 additions
and
366 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
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
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
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,75 @@ | ||
#!/bin/sh | ||
|
||
# Call either 'ckan' (from CKAN >= 2.9) or 'paster' (from CKAN <= 2.8) | ||
# with appropriate syntax, depending on what is present on the system. | ||
# This is intended to smooth the upgrade process from 2.8 to 2.9. | ||
# Eg: | ||
# ckan_cli jobs list | ||
# could become either: | ||
# paster --plugin=ckan jobs list -c /etc/ckan/default/production.ini | ||
# or: | ||
# ckan -c /etc/ckan/default/production.ini jobs list | ||
|
||
# This script is aware of the VIRTUAL_ENV environment variable, and will | ||
# attempt to respect it with similar behaviour to commands like 'pip'. | ||
# Eg placing this script in a virtualenv 'bin' directory will cause it | ||
# to call the 'ckan' or 'paster' command in that directory, while | ||
# placing this script elsewhere will cause it to rely on the VIRTUAL_ENV | ||
# variable, or if that is not set, the system PATH. | ||
|
||
# Since the positioning of the CKAN configuration file is central to the | ||
# differences between 'paster' and 'ckan', this script needs to be aware | ||
# of the config file location. It will use the CKAN_INI environment | ||
# variable if it exists, or default to /etc/ckan/default/production.ini. | ||
|
||
# If 'paster' is being used, the default plugin is 'ckan'. A different | ||
# plugin can be specified by setting the PASTER_PLUGIN environment | ||
# variable. This variable is irrelevant if using the 'ckan' command. | ||
|
||
CKAN_INI="${CKAN_INI:-/etc/ckan/default/production.ini}" | ||
PASTER_PLUGIN="${PASTER_PLUGIN:-ckan}" | ||
# First, look for a command alongside this file | ||
ENV_DIR=$(dirname "$0") | ||
if [ -f "$ENV_DIR/ckan" ]; then | ||
COMMAND=ckan | ||
elif [ -f "$ENV_DIR/paster" ]; then | ||
COMMAND=paster | ||
elif [ "$VIRTUAL_ENV" != "" ]; then | ||
# If command not found alongside this file, check the virtualenv | ||
ENV_DIR="$VIRTUAL_ENV/bin" | ||
if [ -f "$ENV_DIR/ckan" ]; then | ||
COMMAND=ckan | ||
elif [ -f "$ENV_DIR/paster" ]; then | ||
COMMAND=paster | ||
fi | ||
else | ||
# if no virtualenv is active, try the system path | ||
if (which ckan > /dev/null 2>&1); then | ||
ENV_DIR=$(dirname $(which ckan)) | ||
COMMAND=ckan | ||
elif (which paster > /dev/null 2>&1); then | ||
ENV_DIR=$(dirname $(which paster)) | ||
COMMAND=paster | ||
else | ||
echo "Unable to locate 'ckan' or 'paster' command" >&2 | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ "$COMMAND" = "ckan" ]; then | ||
# adjust args to match ckan expectations | ||
COMMAND=$(echo "$1" | sed -e 's/create-test-data/seed/') | ||
echo "Using 'ckan' command from $ENV_DIR with config ${CKAN_INI} to run $COMMAND..." >&2 | ||
shift | ||
exec $ENV_DIR/ckan -c ${CKAN_INI} $COMMAND "$@" $CLICK_ARGS | ||
elif [ "$COMMAND" = "paster" ]; then | ||
# adjust args to match paster expectations | ||
COMMAND=$1 | ||
echo "Using 'paster' command from $ENV_DIR with config ${CKAN_INI} to run $COMMAND..." >&2 | ||
shift | ||
if [ "$1" = "show" ]; then shift; fi | ||
exec $ENV_DIR/paster --plugin=$PASTER_PLUGIN $COMMAND "$@" -c ${CKAN_INI} | ||
else | ||
echo "Unable to locate 'ckan' or 'paster' command in $ENV_DIR" >&2 | ||
exit 1 | ||
fi |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# encoding: utf-8 | ||
|
||
# this is a namespace package | ||
try: | ||
import pkg_resources | ||
|
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,37 @@ | ||
# encoding: utf-8 | ||
|
||
import six | ||
|
||
from flask import Blueprint, make_response | ||
|
||
from ckan.plugins import toolkit | ||
|
||
from .utils import report_index as index, report_view | ||
|
||
|
||
report = Blueprint(u'report', __name__) | ||
|
||
|
||
def redirect_to_index(): | ||
return toolkit.redirect_to('/report') | ||
|
||
|
||
def view(report_name, organization=None, refresh=False): | ||
body, headers = report_view(report_name, organization, refresh) | ||
if headers: | ||
response = make_response(body) | ||
for key, value in six.iteritems(headers): | ||
response.headers[key] = value | ||
return response | ||
else: | ||
return body | ||
|
||
|
||
report.add_url_rule(u'/report', 'index', view_func=index) | ||
report.add_url_rule(u'/reports', 'reports', view_func=redirect_to_index) | ||
report.add_url_rule(u'/report/<report_name>', view_func=view, methods=('GET', 'POST')) | ||
report.add_url_rule(u'/report/<report_name>/<organization>', 'org', view_func=view, methods=('GET', 'POST',)) | ||
|
||
|
||
def get_blueprints(): | ||
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,57 @@ | ||
# encoding: utf-8 | ||
|
||
import click | ||
|
||
from . import utils | ||
|
||
|
||
def get_commands(): | ||
return [report] | ||
|
||
|
||
@click.group() | ||
def report(): | ||
"""Generates reports""" | ||
pass | ||
|
||
|
||
@report.command() | ||
def initdb(): | ||
"""Creates necessary db tables""" | ||
utils.initdb() | ||
click.secho(u'Report table is setup', fg=u"green") | ||
|
||
|
||
@report.command() | ||
@click.argument(u'report_list', required=False) | ||
def generate(report_list): | ||
""" | ||
Generate and cache reports - all of them unless you specify | ||
a comma separated list of them. | ||
""" | ||
if report_list: | ||
report_list = [s.strip() for s in report_list.split(',')] | ||
timings = utils.generate(report_list) | ||
|
||
click.secho(u'Report generation complete %s' % timings, fg=u"green") | ||
|
||
|
||
@report.command() | ||
def list(): | ||
""" Lists the reports | ||
""" | ||
utils.list_reports() | ||
|
||
|
||
@report.command() | ||
@click.argument(u'report_name') | ||
@click.argument(u'report_options', nargs=-1) | ||
def generate_for_options(report_name, report_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 | ||
""" | ||
message = utils.generate_for_options(report_name, report_options) | ||
if message: | ||
click.secho(message, fg=u"red") |
Oops, something went wrong.