8
import sys, os, getopt, tarfile, gzip, time, io, platform, shutil, subprocess
19
opts, args = getopt.getopt(
22
["srcdir=", "bindir=", "major=", "minor=", "dfsg", "check"],
24
except getopt.GetoptError:
28
if o in ("-s", "--srcdir"):
29
print("{} is deprecated -- ignoring".format(o))
30
if o in ("-b", "--bindir"):
38
wta = "--worktree-attributes"
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")
52
info = os.popen("git rev-list HEAD").read()
53
revision = "%04d" % (info.count("\n"))
55
verfile = open("{}/src/Build/Version.h".format(bindir), "rb")
56
verstream = io.BytesIO(verfile.read())
62
PACKAGE_NAME = "freecad"
63
version = "{}.{}.{}".format(version_major, version_minor, revision)
65
DIRNAME = "%(p)s-%(v)s" % {"p": PACKAGE_NAME, "v": version}
66
TARNAME = DIRNAME + ".tar"
67
TGZNAME = DIRNAME + ".tar.gz"
69
TGZNAME = DIRNAME + "-dfsg.tar.gz"
71
verinfo = tarfile.TarInfo(DIRNAME + "/src/Build/Version.h")
73
verinfo.size = len(verstream.getvalue())
74
verinfo.mtime = time.time()
77
print(("git archive --prefix={}/ HEAD".format(DIRNAME)))
79
print(("git archive {} --prefix={}/ HEAD".format(wta, DIRNAME)))
81
if platform.system() == "Windows":
83
"git archive {} --prefix={}/ --output={} HEAD".format(wta, DIRNAME, TARNAME)
86
tar = tarfile.TarFile(mode="a", name=TARNAME)
87
tar.addfile(verinfo, verstream)
90
out = gzip.open(TGZNAME, "wb")
91
tardata = open(TARNAME, "rb")
92
out.write(tardata.read())
97
cmd_line = ["git", "archive"]
100
cmd_line.append("--prefix={}/".format(DIRNAME))
101
cmd_line.append("HEAD")
103
tardata = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
104
out, err = tardata.communicate()
105
tarstream = io.BytesIO(out)
107
tar = tarfile.TarFile(mode="a", fileobj=tarstream)
108
tar.addfile(verinfo, verstream)
111
out = gzip.open(TGZNAME, "wb")
112
out.write(tarstream.getvalue())
116
os.remove("src/.gitattributes")
117
print(("Created " + TGZNAME))
120
archive = tarfile.open(mode="r:gz", name=TGZNAME)
121
archive.extractall(bindir)
122
builddir = os.path.join(bindir, DIRNAME)
128
shutil.rmtree(builddir)
131
if __name__ == "__main__":