Repository navigation
Expand file tree
/
Copy pathmakedist.py
More file actions
133 lines (111 loc) · 3.67 KB
/
Copy pathmakedist.py
File metadata and controls
133 lines (111 loc) · 3.67 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#! python
# SPDX-License-Identifier: LGPL-2.1-or-later
# (c) 2006 Werner Mayer LGPL
#
# Python script to make source tarballs.
#
import sys, os, getopt, tarfile, gzip, time, io, platform, shutil, subprocess
def main():
bindir = "."
major = "0"
minor = "0"
dfsg = False
check = False
wta = None
try:
opts, args = getopt.getopt(
sys.argv[1:],
"sb:",
["srcdir=", "bindir=", "major=", "minor=", "dfsg", "check"],
)
except getopt.GetoptError:
pass
for o, a in opts:
if o in ("-s", "--srcdir"):
print("{} is deprecated -- ignoring".format(o))
if o in ("-b", "--bindir"):
bindir = a
if o in ("--major"):
major = a
if o in ("--minor"):
minor = a
if o in ("--dfsg"):
dfsg = True
wta = "--worktree-attributes"
if o in ("--check"):
check = True
if dfsg:
gitattr = open("src/.gitattributes", "w")
gitattr.write("zipios++ export-ignore\n")
gitattr.write("Pivy-0.5 export-ignore\n")
gitattr.write("Pivy export-ignore\n")
gitattr.write("3Dconnexion export-ignore\n")
gitattr.write("Kuka export-ignore\n")
gitattr.close()
# revision number
info = os.popen("git rev-list HEAD").read()
revision = "%04d" % (info.count("\n"))
verfile = open("{}/src/Build/Version.h".format(bindir), "rb")
verstream = io.BytesIO(verfile.read())
verfile.close()
version_major = major
version_minor = minor
PACKAGE_NAME = "freecad"
version = "{}.{}.{}".format(version_major, version_minor, revision)
DIRNAME = "%(p)s-%(v)s" % {"p": PACKAGE_NAME, "v": version}
TARNAME = DIRNAME + ".tar"
TGZNAME = DIRNAME + ".tar.gz"
if dfsg:
TGZNAME = DIRNAME + "-dfsg.tar.gz"
verinfo = tarfile.TarInfo(DIRNAME + "/src/Build/Version.h")
verinfo.mode = 0o660
verinfo.size = len(verstream.getvalue())
verinfo.mtime = time.time()
if wta is None:
print(("git archive --prefix={}/ HEAD".format(DIRNAME)))
else:
print(("git archive {} --prefix={}/ HEAD".format(wta, DIRNAME)))
if platform.system() == "Windows":
os.popen(
"git archive {} --prefix={}/ --output={} HEAD".format(wta, DIRNAME, TARNAME)
).read()
tar = tarfile.TarFile(mode="a", name=TARNAME)
tar.addfile(verinfo, verstream)
tar.close()
out = gzip.open(TGZNAME, "wb")
tardata = open(TARNAME, "rb")
out.write(tardata.read())
out.close()
tardata.close()
os.remove(TARNAME)
else:
cmd_line = ["git", "archive"]
if not wta is None:
cmd_line.append(wta)
cmd_line.append("--prefix={}/".format(DIRNAME))
cmd_line.append("HEAD")
tardata = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = tardata.communicate()
tarstream = io.BytesIO(out)
tar = tarfile.TarFile(mode="a", fileobj=tarstream)
tar.addfile(verinfo, verstream)
tar.close()
out = gzip.open(TGZNAME, "wb")
out.write(tarstream.getvalue())
out.close()
if dfsg:
os.remove("src/.gitattributes")
print(("Created " + TGZNAME))
# Unpack and build
if check:
archive = tarfile.open(mode="r:gz", name=TGZNAME)
archive.extractall(bindir)
builddir = os.path.join(bindir, DIRNAME)
cwd = os.getcwd()
os.chdir(builddir)
os.system("cmake .")
os.system("make")
os.chdir(cwd)
shutil.rmtree(builddir)
if __name__ == "__main__":
main()