File: config.py

package info (click to toggle)
nomacs 3.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,560 kB
  • sloc: cpp: 49,511; python: 718; sh: 241; xml: 175; makefile: 22
file content (88 lines) | stat: -rw-r--r-- 2,391 bytes parent folder | download | duplicates (2)
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
import os

class Config(object):

    def __init__(self, params, name: str):
        self.__dict__.update(params)
        self.name = name

        self.additional_cmake_args = []

        self.defaults()
        self.check()

    def check(self):

        # check if all directories exist
        for key in self.__dict__:

            p = self.__dict__[key]

            if p:
                if key.endswith("path"):
                    if not os.path.exists(p):
                        print("[WARNING] %s path does not exist: %s" % (key, p))
                    else:
                        self.__dict__[key] = Config.normpath(p)

        if "builddir" in self.__dict__:
            self.builddir = Config.normpath(self.builddir)

    @staticmethod
    def normpath(path: str):
        tmp = os.path.abspath(path)
        # cmake has issues with windows path separators
        tmp = tmp.replace("\\", "/")
        return tmp

    def defaults(self):

        # "debug" builds debug and release
        if "buildconfig" not in self.__dict__ or not self.buildconfig:
            self.buildconfig = "debug"

        # call install?
        if "install" not in self.__dict__:
            self.install = True

        # if set to True, we'll run a dry run (only configure cmake)
        if "cmakeonly" not in self.__dict__:
            self.cmakeonly = False

        # if set, we can skip builds
        if "binaryfile" not in self.__dict__:
            self.binaryfile = ""

        # if true, we will always rebuild
        if "force" not in self.__dict__:
            self.force = False

        if "srcpath" not in self.__dict__ or not self.srcpath:
            self.srcpath = os.path.join(self.repopath, self.name)

        # this is not called 'path' because it won't exist until we call cmake
        if "builddir" not in self.__dict__ or not self.builddir:
            self.builddir = os.path.join(self.repopath, "build")
        else:
            self.builddir = os.path.abspath(self.builddir)

    def cmake_args(self):

        return ""

    def cmake_build_args(self):
    
        return ""

    def __str__(self):

        keyvals = [key + ": " + str(self.__dict__[key])
                   for key in self.__dict__]
        return "\n".join(keyvals)

    def is_built(self):

        if self.force:
            return False

        return os.path.isfile(self.binaryfile)