FreeCAD

Форк
0
/
makedist.py 
132 строки · 3.6 Кб
1
#! python
2
# -*- coding: utf-8 -*-
3
# (c) 2006 Werner Mayer LGPL
4
#
5
# Python script to make source tarballs.
6
#
7

8
import sys, os, getopt, tarfile, gzip, time, io, platform, shutil, subprocess
9

10

11
def main():
12
    bindir = "."
13
    major = "0"
14
    minor = "0"
15
    dfsg = False
16
    check = False
17
    wta = None
18
    try:
19
        opts, args = getopt.getopt(
20
            sys.argv[1:],
21
            "sb:",
22
            ["srcdir=", "bindir=", "major=", "minor=", "dfsg", "check"],
23
        )
24
    except getopt.GetoptError:
25
        pass
26

27
    for o, a in opts:
28
        if o in ("-s", "--srcdir"):
29
            print("{} is deprecated -- ignoring".format(o))
30
        if o in ("-b", "--bindir"):
31
            bindir = a
32
        if o in ("--major"):
33
            major = a
34
        if o in ("--minor"):
35
            minor = a
36
        if o in ("--dfsg"):
37
            dfsg = True
38
            wta = "--worktree-attributes"
39
        if o in ("--check"):
40
            check = True
41

42
    if dfsg:
43
        gitattr = open("src/.gitattributes", "w")
44
        gitattr.write("zipios++    export-ignore\n")
45
        gitattr.write("Pivy-0.5    export-ignore\n")
46
        gitattr.write("Pivy    export-ignore\n")
47
        gitattr.write("3Dconnexion    export-ignore\n")
48
        gitattr.write("Kuka    export-ignore\n")
49
        gitattr.close()
50

51
    # revision number
52
    info = os.popen("git rev-list HEAD").read()
53
    revision = "%04d" % (info.count("\n"))
54

55
    verfile = open("{}/src/Build/Version.h".format(bindir), "rb")
56
    verstream = io.BytesIO(verfile.read())
57
    verfile.close()
58

59
    version_major = major
60
    version_minor = minor
61

62
    PACKAGE_NAME = "freecad"
63
    version = "{}.{}.{}".format(version_major, version_minor, revision)
64

65
    DIRNAME = "%(p)s-%(v)s" % {"p": PACKAGE_NAME, "v": version}
66
    TARNAME = DIRNAME + ".tar"
67
    TGZNAME = DIRNAME + ".tar.gz"
68
    if dfsg:
69
        TGZNAME = DIRNAME + "-dfsg.tar.gz"
70

71
    verinfo = tarfile.TarInfo(DIRNAME + "/src/Build/Version.h")
72
    verinfo.mode = 0o660
73
    verinfo.size = len(verstream.getvalue())
74
    verinfo.mtime = time.time()
75

76
    if wta is None:
77
        print(("git archive --prefix={}/ HEAD".format(DIRNAME)))
78
    else:
79
        print(("git archive {} --prefix={}/ HEAD".format(wta, DIRNAME)))
80

81
    if platform.system() == "Windows":
82
        os.popen(
83
            "git archive {} --prefix={}/ --output={} HEAD".format(wta, DIRNAME, TARNAME)
84
        ).read()
85

86
        tar = tarfile.TarFile(mode="a", name=TARNAME)
87
        tar.addfile(verinfo, verstream)
88
        tar.close()
89

90
        out = gzip.open(TGZNAME, "wb")
91
        tardata = open(TARNAME, "rb")
92
        out.write(tardata.read())
93
        out.close()
94
        tardata.close()
95
        os.remove(TARNAME)
96
    else:
97
        cmd_line = ["git", "archive"]
98
        if not wta is None:
99
            cmd_line.append(wta)
100
        cmd_line.append("--prefix={}/".format(DIRNAME))
101
        cmd_line.append("HEAD")
102

103
        tardata = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
104
        out, err = tardata.communicate()
105
        tarstream = io.BytesIO(out)
106

107
        tar = tarfile.TarFile(mode="a", fileobj=tarstream)
108
        tar.addfile(verinfo, verstream)
109
        tar.close()
110

111
        out = gzip.open(TGZNAME, "wb")
112
        out.write(tarstream.getvalue())
113
        out.close()
114

115
    if dfsg:
116
        os.remove("src/.gitattributes")
117
    print(("Created " + TGZNAME))
118
    # Unpack and build
119
    if check:
120
        archive = tarfile.open(mode="r:gz", name=TGZNAME)
121
        archive.extractall(bindir)
122
        builddir = os.path.join(bindir, DIRNAME)
123
        cwd = os.getcwd()
124
        os.chdir(builddir)
125
        os.system("cmake .")
126
        os.system("make")
127
        os.chdir(cwd)
128
        shutil.rmtree(builddir)
129

130

131
if __name__ == "__main__":
132
    main()
133

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.