-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
106 lines (82 loc) · 3.61 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from modules.core.props import Property
from modules import cbpi
from flask import g, request, url_for, redirect
import json
import sys
from flask import Blueprint, request, send_from_directory
from importlib import import_module
from modules import socketio, cbpi
#from git import Repo
import os
import requests
import yaml
#import shutil
blueprint = Blueprint('ChangePluginsRepositorory', __name__)
modules = {}
def merge(source, destination):
"""
Helper method to merge two dicts
:param source:
:param destination:
:return:
"""
for key, value in source.items():
if isinstance(value, dict):
# get node or create one
node = destination.setdefault(key, {})
merge(value, node)
else:
destination[key] = value
return destination
@blueprint.route('/list', methods=['GET'])
def plugins():
"""
Read the central plugin yaml to get a list of all official plugins
:return:
"""
mergedPlugins = ""
#response = requests.get("https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml")
parameterName = "Plugins_Repository"
pluginsFileOnRepository = cbpi.get_config_parameter(parameterName, None)
parameterName = "Plugins_Repository_MergeWithOriginal"
parameterToVerify = cbpi.get_config_parameter(parameterName, None)
# Make request to plugins file on repository
response = requests.get(pluginsFileOnRepository)
mergedPlugins = yaml.load(response.text)
if parameterToVerify is not None and parameterToVerify == "Yes":
# Make request to plugins file on repository
if pluginsFileOnRepository != "https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml" :
responseToOriginal = requests.get("https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml")
mergedPlugins = merge(yaml.load(responseToOriginal.text), mergedPlugins)
cbpi.cache["plugins"] = merge(mergedPlugins, cbpi.cache["plugins"])
for key, value in cbpi.cache["plugins"].iteritems():
value["installed"] = os.path.isdir("./modules/plugins/%s/" % (key))
return json.dumps(cbpi.cache["plugins"])
@cbpi.initalizer(order=9998)
def init(cbpi):
cbpi.app.register_blueprint(blueprint, url_prefix='/api/ChangePluginsRepositorory/editor')
class ConnectionInterceptorToChangePluginsRepository:
@cbpi.app.before_request
def before_request():
# check if route is the ones envoled in recipe import
if request.url_rule is not None and request.url_rule.rule == "/api/editor/list":
parameterToVerify = cbpi.get_config_parameter("Plugins_Repository", None)
if parameterToVerify is not None:
return redirect('api/ChangePluginsRepositorory/editor/list')
@cbpi.initalizer(order=9999)
def init(cbpi):
"""
Initializer for ChangePluginsRepository
:param app: the flask app
:return: None
"""
# Verifies if parameter was definied previously
# Creates the missing parameter
parameterName = "Plugins_Repository"
parameterToVerify = cbpi.cache.get("config").get(parameterName)
if parameterToVerify is None:
cbpi.add_config_parameter(parameterName, "https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml", "text", "Plugins file on repository")
parameterName = "Plugins_Repository_MergeWithOriginal"
parameterToVerify = cbpi.get_config_parameter(parameterName,None)
if parameterToVerify is None:
cbpi.add_config_parameter(parameterName, "No", "select", "Plugins file on repository",['Yes','No'])