Test Failed
Pull Request — master (#2)
by Heiko 'riot'
06:45
created

isomer.ui.store.component   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 88
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A Store.__init__() 0 2 1
A Store.get_store_inventory() 0 17 1
A Store.install() 0 15 1
1
#!/usr/bin/env python
2
# -*- coding: UTF-8 -*-
3
4
# Isomer - The distributed application framework
5
# ==============================================
6
# Copyright (C) 2011-2020 Heiko 'riot' Weinen <[email protected]> and others.
7
#
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU Affero General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
12
#
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
# GNU Affero General Public License for more details.
17
#
18
# You should have received a copy of the GNU Affero General Public License
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
21
"""
22
23
Module: store.component
24
=======================
25
26
Store management component.
27
28
"""
29
from isomer.misc.path import get_path
30
from isomer.tool import get_next_environment
31
from isomer.events.client import send
32
from isomer.ui.store import DEFAULT_STORE_URL
33
from isomer.ui.store.inventory import get_store, get_inventory
34
from isomer.ui.store import get_store_inventory, install, remove, update, update_all
35
from isomer.component import ConfigurableComponent, handler
36
from isomer.ui.instance import notify_restart_required
37
38
39
class Store(ConfigurableComponent):
40
    """Software store for Isomer"""
41
42
    configprops = {
43
        'store_url': {
44
            'type': 'string',
45
            'title': 'Store URL',
46
            'description': 'Specify alternate store url (Default:%s)'
47
                           % DEFAULT_STORE_URL,
48
            'default': DEFAULT_STORE_URL
49
        }
50
    }
51
52
    def __init__(self, *args, **kwargs):
53
        super(Store, self).__init__('STORE', *args, **kwargs)
54
55
    @handler(get_store_inventory)
56
    def get_store_inventory(self, event):
57
        """Fetch store inventory and transmit back to client."""
58
59
        store_inventory = get_store(self.config.store_url)
60
        local_inventory = get_inventory(self.context)
61
62
        response = {
63
            'component': 'isomer.ui.store',
64
            'action': 'get_store_inventory',
65
            'data': {
66
                'store': store_inventory,
67
                'local': local_inventory
68
            }
69
        }
70
71
        self.fireEvent(send(event.client.uuid, response))
72
73
    @handler(install)
74
    def install(self, event):
75
        """Installs a new Isomer package on the running instance"""
76
        self.log("Installing package:", event.data)
77
78
        instance_config = self.context.obj["instance_configuration"]
79
        # repository = get_path("lib", "repository")
80
81
        environments = instance_config["environments"]
82
83
        active = instance_config["environment"]
84
85
        next_environment = get_next_environment(self.context)
86
87
        self.fireEvent(notify_restart_required(reason="Module installed: " + event.data))
88