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 #4982 from f-osorio/4799-extension-template-docume…
…ntation 4799 extension template documentation
- Loading branch information
Showing
34 changed files
with
2,066 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# encoding: utf-8 | ||
|
||
import os | ||
import sys | ||
import click | ||
from ckan.cli import error_shout | ||
from cookiecutter.main import cookiecutter | ||
|
||
|
||
@click.group(name=u'generate', | ||
short_help=u"Generate empty extension files to expand CKAN.") | ||
def generate(): | ||
pass | ||
|
||
|
||
@generate.command(name=u'extension', short_help=u"Create empty extension.") | ||
@click.option(u'-o', u'--output-dir', help=u"Location to put the generated " | ||
u"template.", | ||
default=u'.') | ||
def extension(output_dir): | ||
cur_loc = os.path.dirname(os.path.abspath(__file__)) | ||
os.chdir(cur_loc) | ||
os.chdir(u'../../contrib/cookiecutter/ckan_extension/') | ||
template_loc = os.getcwd() | ||
|
||
# Prompt user for information | ||
click.echo(u"\n") | ||
name = click.prompt(u"Extenion's name", default=u"must begin 'ckanext-'") | ||
author = click.prompt(u"Author's name", default=u"") | ||
email = click.prompt(u"Author's email", default=u"") | ||
github = click.prompt(u"Your Github user or organization name", | ||
default=u"") | ||
description = click.prompt(u"Brief description of the project", | ||
default=u"") | ||
keywords = click.prompt(u"List of keywords (seperated by spaces)", | ||
default=u"CKAN") | ||
|
||
# Ensure one instance of 'CKAN' in keywords | ||
keywords = keywords.strip().split() | ||
keywords = [keyword for keyword in keywords | ||
if keyword not in (u'ckan', u'CKAN')] | ||
keywords.insert(0, u'CKAN') | ||
keywords = u' '.join(keywords) | ||
|
||
# Set short name and plugin class name | ||
project_short = name[8:].lower().replace(u'-', u'_') | ||
plugin_class_name = project_short.title().replace(u'_', u'') + u'Plugin' | ||
|
||
context = {u"project": name, | ||
u"description": description, | ||
u"author": author, | ||
u"author_email": email, | ||
u"keywords": keywords, | ||
u"github_user_name": github, | ||
u"project_shortname": project_short, | ||
u"plugin_class_name": plugin_class_name, | ||
u"_source": u"cli"} | ||
|
||
if output_dir == u'.': | ||
os.chdir(u'../../../..') | ||
output_dir = os.getcwd() | ||
|
||
if not name.startswith(u"ckanext-"): | ||
print(u"\nERROR: Project name must start with 'ckanext-' > {}" | ||
.format(name)) | ||
sys.exit(1) | ||
|
||
cookiecutter(template_loc, no_input=True, extra_context=context, | ||
output_dir=output_dir) |
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,3 @@ | ||
language: python | ||
install: pip install flake8 | ||
script: flake8 . --exit-zero |
Oops, something went wrong.