|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
import os |
|
3
|
|
|
from click import Argument |
|
4
|
|
|
|
|
5
|
|
|
from groundwork.patterns import GwCommandsPattern, GwRecipesPattern |
|
6
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
class GwRecipesBuilder(GwCommandsPattern, GwRecipesPattern): |
|
9
|
|
|
""" |
|
10
|
|
|
Provides commands for listing and building recipes via command line interface. |
|
11
|
|
|
|
|
12
|
|
|
Provided commands: |
|
13
|
|
|
|
|
14
|
|
|
* recipe_list |
|
15
|
|
|
* recipe_build |
|
16
|
|
|
|
|
17
|
|
|
Provides also the recipe **gw_package**, which can be used to setup a groundwork related python package. |
|
18
|
|
|
Content of the package: |
|
19
|
|
|
|
|
20
|
|
|
* setup.py: Preconfigured and ready to use. |
|
21
|
|
|
* groundwork package structure: Directories for applications, patterns, plugins and recipes. |
|
22
|
|
|
* Simple, runnable example of a groundwork application and plugins. |
|
23
|
|
|
* usable test, supported by py.test and tox. |
|
24
|
|
|
* expandable documentation, supported by sphinx and the groundwork sphinx template. |
|
25
|
|
|
* .gitignore |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
This code is hardly based on Cookiecutter's main.py file: |
|
29
|
|
|
https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/main.py |
|
30
|
|
|
""" |
|
31
|
|
|
def __init__(self, *args, **kwargs): |
|
32
|
|
|
self.name = self.__class__.__name__ |
|
33
|
|
|
super().__init__(*args, **kwargs) |
|
34
|
|
|
|
|
35
|
|
|
def activate(self): |
|
36
|
|
|
self.commands.register("recipe_list", "Lists all recipes", self._recipe_list) |
|
37
|
|
|
self.commands.register("recipe_build", "Builds a given recipe", self._recipe_build, |
|
38
|
|
|
params=[Argument(("recipe",), required=True)]) |
|
39
|
|
|
|
|
40
|
|
|
self.recipes.register("gw_package", |
|
41
|
|
|
os.path.abspath(os.path.join(os.path.dirname(__file__), "../recipes/gw_package")), |
|
42
|
|
|
description="Groundwork basic package. Includes places for " |
|
43
|
|
|
"apps, plugins, patterns and recipes.", |
|
44
|
|
|
final_words="Recipe Installation is done.\n\n" |
|
45
|
|
|
"For installation run: 'python setup.py develop' \n" |
|
46
|
|
|
"For documentation run: 'make html' inside doc folder " |
|
47
|
|
|
"(after installation!)\n\n" |
|
48
|
|
|
"For more information, please take a look into the README file " |
|
49
|
|
|
"to know how to go on.\n" |
|
50
|
|
|
"For help visit: https://groundwork.readthedocs.io\n\n" |
|
51
|
|
|
"Have fun with your groundwork package.") |
|
52
|
|
|
|
|
53
|
|
|
def deactivate(self): |
|
54
|
|
|
pass |
|
55
|
|
|
|
|
56
|
|
|
def _recipe_list(self): |
|
57
|
|
|
print("Recipes:") |
|
58
|
|
|
for key, recipe in self.app.recipes.get().items(): |
|
59
|
|
|
print(" %s by plugin '%s' - %s" % (recipe.name, recipe.plugin.name, recipe.description)) |
|
60
|
|
|
|
|
61
|
|
|
def _recipe_build(self, recipe): |
|
62
|
|
|
recipe_obj = self.app.recipes.get(recipe) |
|
63
|
|
|
if recipe_obj is None: |
|
64
|
|
|
print("Recipe %s not found." % recipe) |
|
65
|
|
|
else: |
|
66
|
|
|
recipe_obj.build() |
|
67
|
|
|
|