Debian Codegraph @

src/buildstream_plugins/sourcemirrors/simple_mirror.py

raw
1 #
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at
5 #
6 # http://www.apache.org/licenses/LICENSE-2.0
7 #
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
13
14 """
15 simple_mirror - plugin for simplifying mirror definitions
16 =========================================================
17
18 .. note::
19
20 The ``simple_mirror`` plugin is available *Since 2.4.0*
21
22 **Usage:**
23
24 .. code:: yaml
25
26 - name: my-mirror
27 kind: simple_mirror
28 config:
29 url: https://example.com/mirrors/{alias}/
30 aliases:
31 - my-alias
32 - another-alias
33
34 This plugin simplifies defining mirrors for projects where the mirrors follow
35 a predictable URL format that only varies with the alias name.
36 """
37
38 from posixpath import join
39 from buildstream import SourceMirror
40
41
42 class SimpleMirror(SourceMirror):
43 BST_MIN_VERSION = "2.2"
44
45 def configure(self, node):
46 node.validate_keys(["url", "aliases"])
47 self.set_supported_aliases(node.get_str_list("aliases"))
48
49 self.url = node.get_str("url")
50
51 def translate_url(self, *, alias, alias_url, source_url, extra_data):
52 base_url = self.url.format(alias=alias)
53 translated_url = join(base_url, source_url)
54
55 return translated_url
56
57
58 def setup():
59 return SimpleMirror