summaryrefslogtreecommitdiff
path: root/distribution/bin/makeubuntupackages.py
blob: 5a7826b09e4a29a506bb00c59a685a85ba7966f3 (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
117
118
119
120
121
122
123
124
125
126
127
#!/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 "-p [core|all]    Distribution you want to build"
    print "                     * core builds the core distribution"
    print "                     * all builds the main distribution"
    print ""
    print "Example:"
    print ""
    print "makeubuntupackages.py -p all -b ./tmp -d ./dist-HEAD"
    print

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


verbose = 0
buildDir = None
distributionDir = None
distribution = 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 == "-p":
        distribution = a

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

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

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

if distribution != "all" and distribution != "core":
    print "Unknown distribution: " + distribution
    usage()
    sys.exit(1)


sourceDir = "ice3.5-3.5.1" if distribution == "all" else "ice3.5++-3.5.1"
distFile = "ice3.5_3.5.1.orig.tar.gz" if distribution == "all" else "ice3.5++_3.5.1.orig.tar.gz"
distFiles = "distfiles-3.5.1.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):
    if len(cmd) > 0:
        if 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-3.5.1/src/deb/%s/debian --strip-components 4" \
    % (distFiles, distribution), verbose)
runCommand("dpkg-buildpackage", verbose)