summaryrefslogtreecommitdiff
path: root/distribution/bin/makeubuntupackages.py
blob: 0c755cbeb20c3b49466f7044ee740aee15c66774 (plain)
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
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2014 ZeroC, Inc. All rights reserved.
#
# This copy of Ice is licensed to you under the terms described in the
# ICE_LICENSE file included in this distribution.
#
# **********************************************************************

import os, sys, fnmatch, re, getopt, atexit, shutil, subprocess

#
# Program usage.
#
def usage():
    print
    print "Options:"
    print "-h               Show this message."
    print "-v               Be verbose."
    print "-b DIR           Directory to build the packages"
    print "-d DIR           Directory with Ice source distribution"
    print "-k KEYID         Id of the Key used to sign the packages"
    print "Example:"
    print ""
    print "makeubuntupackages.py -b trusty -d dist-HEAD -k 748BB043"
    print

#
# Check arguments
#
try:
    opts, args = getopt.getopt(sys.argv[1:], "hvb:d:k:")
except getopt.GetoptError:
    print sys.argv[0] + ": unknown option"
    print
    usage()
    sys.exit(1)


verbose = 0
buildDir = None
distributionDir = None
keyid = None

for (o, a) in opts:
    if o == "-h":
        usage()
        sys.exit(0)
    elif o == "-v":
        verbose = 1
    elif o == "-b":
        buildDir = a
    elif o == "-d":
        distributionDir = a
    elif o == "-k":
        keyid = a

if buildDir == None:
    print "Missing -b argument"
    usage()
    sys.exit(1)

if distributionDir == None:
    print "Missing -d argument"
    usage()
    sys.exit(1)

buildpackageOps = ("-k%s" % keyid) if keyid != None else "-us -uc"

sourceDir = "zeroc-ice@debmmver@-@debver@"
distFile = "zeroc-ice@debmmver@_@debver@.orig.tar.gz"
distFiles = "distfiles-@ver@.tar.gz"

buildDir = os.path.abspath(os.path.join(os.getcwd(), buildDir))
sourceDir = os.path.abspath(os.path.join(buildDir, sourceDir))
distributionDir = os.path.abspath(os.path.join(os.getcwd(), distributionDir))

distFile = os.path.join(distributionDir, distFile)
distFiles = os.path.join(distributionDir, distFiles)

if not os.path.exists(buildDir):
    os.mkdir(buildDir)
else:
    if not os.listdir(buildDir) == []:
        print "Build dir `%s' not empty" % (buildDir)
        sys.exit(1)

if not os.path.exists(distFiles):
    print "File not exists %s " % (distFiles)
    print "Path `%s' doesn't appears to contain a valid distribution" % (distributionDir)
    sys.exit(1)

if not os.path.exists(distFile):
    print "File not exists %s " % (distFile)
    print "Path `%s' doesn't appears to contain a valid distribution" % (distributionDir)
    sys.exit(1)


def runCommand(cmd, verbose):
    print(cmd)
    if os.system(cmd) != 0:
        sys.exit(1)

os.chdir(buildDir)
runCommand("tar zxf %s " % (distFile), verbose)
shutil.copy(distFile, buildDir)

os.chdir(sourceDir)
runCommand("tar zxf %s distfiles-@ver@/src/deb/debian --strip-components 3" % distFiles, verbose)
os.chdir(os.path.join(sourceDir, "debian"))
runCommand("tar zxf %s distfiles-@ver@/src/unix/README.Linux --strip-components 3" % distFiles, verbose)
runCommand("tar zxf %s distfiles-@ver@/src/unix/JGOODIES_LICENSE --strip-components 3" % distFiles, verbose)

os.chdir(sourceDir)
runCommand("dpkg-buildpackage %s -j8" % buildpackageOps, verbose)