File: treeinfodata.py

package info (click to toggle)
osinfo-db 0.20250606-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 28,856 kB
  • sloc: python: 2,161; sh: 357; makefile: 94
file content (53 lines) | stat: -rw-r--r-- 1,432 bytes parent folder | download
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
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.

import configparser


class _TreeinfoData:
    def __init__(self, path, arch, family, variant, version):
        self.path = path
        self.arch = arch or ""
        self.family = family or ""
        self.variant = variant or ""
        self.version = version or ""

    def match(self, treeinfo):
        if (
            bool(treeinfo.arch.match(self.arch))
            and bool(treeinfo.family.match(self.family))
            and bool(treeinfo.variant.match(self.variant))
            and bool(treeinfo.version.match(self.version))
        ):
            return True

        return False


def get_treeinfodata(filepath):
    arch = None
    family = None
    variant = None
    version = None

    config = configparser.ConfigParser()
    with filepath.open("r") as out:
        config.read_file(out)
        arch = ""
        family = ""
        variant = ""
        version = ""

        if "arch" in config["general"]:
            arch = config["general"]["arch"]

        if "family" in config["general"]:
            family = config["general"]["family"]

        if "variant" in config["general"]:
            variant = config["general"]["variant"]

        if "version" in config["general"]:
            version = config["general"]["version"]

    return _TreeinfoData(filepath, arch, family, variant, version)