Differences From Artifact [f7f101f5bf]:

To Artifact [b7808bf08a]:


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
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







-
-
+
+
-
-
+
-
-
+
+
-
-
+















-
-
+
+
-
-
+
-
-
-
+







    The .valid() helper only asserts the api: string, or skips existing
    modules, and if they're more recent.
    While .depends() compares minimum versions against existing modules.

    In practice there's little need for full-blown dependency resolving
    for application-level modules.

    Attributes
    ----------
    | Attributes | | |
    |------------|---------|-----------------------------------------------------|
    api : list
        allowed api: identifiers for .valid() stream checks
    | api        | list    | allowed api: identifiers for .valid() stream checks |
    log : logging
        warning handler
    | system_deps| bool    | check `bin:app` or `python:package` dependencies    |
    | log        | logging | warning handler                                     |
    have : dict
        accumulated list of existing/virtual plugins
    | have       | dict    | accumulated list of existing/virtual plugins        |
    """

    # supported APIs
    api = ["python", "streamtuner2"]

    # debugging
    log = logging.getLogger("pluginconf.dependency")

    # ignore bin:… or python:… package in depends
    system_deps = False

    def __init__(self, add=None, core=["st2", "uikit", "config", "action"]):
        """
        Prepare list of known plugins and versions in self.have={}

        Parameters
        ----------
        | Parameters | | |
        |------------|---------|------------------------------------------------------|
        add : dict
            name to pmd list of existing/core/virtual plugins (can define
        | add        | dict    | namepmd of existing/core plugins (incl ver or deps) |
            versions or own dependencies)
        core : list
            name list of virtual plugins
        | core       | list    | name list of virtual plugins                         |
        """
        self.have = {
            "python": {"version": sys.version}
        }

        # inject virtual modules
        for name, meta in (add or {}).items():
119
120
121
122
123
124
125





126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

144







145
146
147
148
149
150
151
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144

145
146
147
148
149
150
151
152
153
154
155
156
157
158







+
+
+
+
+


















+
-
+
+
+
+
+
+
+







                    self.have[alias] = self.have[name]

    def valid(self, new_plugin):
        """
        Plugin pre-screening from online repository stream.
        Fields are $name, $file, $dist, api, id, depends, etc
        Exclude installed or for newer-version presence.

        | Parameters  | | |
        |-------------|---------|------------------------------------------------------|
        | new_plugin  | dict    | online properties of available plugin                |
        | **Returns** | bool    | is updatatable                                       |
        """
        if not "$name" in new_plugin:
            self.log.warning(".valid() checks online plugin lists, requires $name")
        name = new_plugin.get("$name", "__invalid")
        have_ver = self.have.get(name, {}).get("version", "0")
        if name.find("__") == 0:
            self.log.debug("wrong/no id")
        elif new_plugin.get("api") not in self.api:
            self.log.debug("not in allowed APIs")
        elif {new_plugin.get("status"), new_plugin.get("priority")} & {"obsolete", "broken"}:
            self.log.debug("wrong status (obsolete/broken)")
        elif have_ver >= new_plugin.get("version", "0.0"):
            self.log.debug("newer version already installed")
        else:
            return True
        return False

    def depends(self, plugin):
        """
        """ Verify depends: and breaks: against existing plugins/modules """
        Verify depends: and breaks: against existing plugins/modules

        | Parameters  | | |
        |-------------|---------|------------------------------------------------------|
        | plugin      | dict    | plugin meta properties of (new?) plugin              |
        | **Returns** | bool    | matches up with existing .have{} installation        |
        """
        result = True
        if plugin.get("depends"):
            result &= self.and_or(self.split(plugin["depends"]), self.have)
        if plugin.get("breaks"):
            result &= self.neither(self.split(plugin["breaks"]), self.have)
        self.log.debug("plugin '%s' matching requirements: %i", plugin["id"], result)
        return result