-
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.
Rearange the cli commands, into one folder, separated by subcommands
- Loading branch information
Showing
5 changed files
with
95 additions
and
1 deletion.
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,52 @@ | ||
# encoding: utf-8 | ||
|
||
import os | ||
|
||
import click | ||
from flask import Flask, current_app | ||
from flask.cli import AppGroup, with_appcontext | ||
from werkzeug.serving import run_simple | ||
|
||
from ckan.common import config | ||
from ckan.config.environment import load_environment | ||
from ckan.config.middleware import make_app | ||
|
||
|
||
click_config_option = click.option( | ||
'-c', | ||
'--config', | ||
default=None, | ||
metavar='CONFIG', | ||
help=u'Config file to use (default: development.ini)') | ||
|
||
|
||
def load_config(config=None): | ||
|
||
from paste.deploy import appconfig | ||
from paste.script.util.logging_config import fileConfig | ||
|
||
if config: | ||
filename = os.path.abspath(config) | ||
config_source = u'-c parameter' | ||
elif os.environ.get(u'CKAN_INI'): | ||
filename = os.environ.get(u'CKAN_INI') | ||
config_source = u'$CKAN_INI' | ||
else: | ||
default_filename = u'development.ini' | ||
filename = os.path.join(os.getcwd(), default_filename) | ||
if not os.path.exists(filename): | ||
# give really clear error message for this common situation | ||
msg = u'ERROR: You need to specify the CKAN config (.ini) '\ | ||
u'file path.'\ | ||
u'\nUse the --config parameter or set environment ' \ | ||
u'variable CKAN_INI or have {}\nin the current directory.' \ | ||
.format(default_filename) | ||
exit(msg) | ||
|
||
if not os.path.exists(filename): | ||
msg = u'Config file not found: %s' % filename | ||
msg += u'\n(Given by: %s)' % config_source | ||
exit(msg) | ||
|
||
fileConfig(filename) | ||
return appconfig(u'config:' + filename) |
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,15 @@ | ||
# encoding: utf-8 | ||
|
||
import os | ||
|
||
import click | ||
|
||
|
||
@click.group() | ||
@click.help_option(u'-h', u'--help') | ||
def ckan(*args, **kwargs): | ||
pass | ||
|
||
|
||
from ckan.cli.server.server import run | ||
ckan.add_command(run) |
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,27 @@ | ||
# encoding: utf-8 | ||
|
||
import os | ||
|
||
import click | ||
from flask import Flask, current_app | ||
from flask.cli import AppGroup, with_appcontext | ||
from werkzeug.serving import run_simple | ||
|
||
from ckan.common import config | ||
from ckan.config.environment import load_environment | ||
|
||
from ckan.config.middleware import make_app | ||
from ckan.cli import load_config, click_config_option | ||
from ckan.cli.cli import ckan | ||
|
||
@ckan.command(u'run', short_help=u'Start development server') | ||
@click.help_option(u'-h', u'--help') | ||
@click_config_option | ||
@click.option(u'-H', u'--host', default=u'localhost', help=u'Set host') | ||
@click.option(u'-p', u'--port', default=5000, help=u'Set port') | ||
@click.option(u'-r', u'--reloader', default=True, help=u'Use reloader') | ||
def run(config, host, port, reloader): | ||
u'''Runs development server''' | ||
conf = load_config(config) | ||
app = make_app(conf.global_conf, **conf.local_conf) | ||
run_simple(host, port, app, use_reloader=reloader, use_evalex=True) |
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