summaryrefslogtreecommitdiff
path: root/rb/makewindist.py
blob: b1664c516dc674f86b048588bceb0afe20e7ffd6 (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
128
129
130
131
132
133
134
135
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003-2007 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.
#
# **********************************************************************

#
# NOTE: This script is only temporary!
#


import os, sys, shutil, fnmatch, re, glob

#
# Show usage information.
#
def usage():
    print "Usage: " + sys.argv[0] + " [options] [build-dir]"
    print
    print "Options:"
    print "-h    Show this message."
    print "-v    Be verbose."
    print
    print "Where build-dir is the directory containing a source build."
    print "If not specified, the current directory is used."

#
# Find files matching a pattern.
#
def find(path, patt):
    result = [ ]
    files = os.listdir(path)
    for x in files:
        fullpath = os.path.join(path, x);
        if fnmatch.fnmatch(x, patt):
            result.append(fullpath)
        if os.path.isdir(fullpath) and not os.path.islink(fullpath):
            result.extend(find(fullpath, patt))
    return result

#
# Are we on Windows?
#
win32 = sys.platform.startswith("win") or sys.platform.startswith("cygwin")
if not win32:
    print "This script is only for Windows!"
    sys.exit(1)

#
# Check arguments
#
buildDir = "."
verbose = 0
for x in sys.argv[1:]:
    if x == "-h":
        usage()
        sys.exit(0)
    elif x == "-v":
        verbose = 1
    elif x.startswith("-"):
        print sys.argv[0] + ": unknown option `" + x + "'"
        print
        usage()
        sys.exit(1)
    else:
        buildDir = x

if not os.path.exists(buildDir):
    print "error: " + buildDir + " not found."
    usage()
    sys.exit(1)

if not os.path.exists(os.path.join(buildDir, "README.txt")):
    print "error: " + buildDir + " must contain a compiled CVS repository or export directory."
    sys.exit(1)

#
# Get Ice version.
#
config = open(os.path.join(buildDir, "config", "Make.rules"), "r")
version = re.search("^VERSION[ \t]+=[^\d]*([\d\.]+)", config.read(), re.M).group(1)

distDir = "IceRuby-" + version
archive = distDir + "-bin-win32.zip"
if os.path.exists(distDir):
    shutil.rmtree(distDir)
if os.path.exists(archive):
    os.remove(archive)
os.mkdir(distDir)

shutil.copytree(os.path.join(buildDir, "bin"), os.path.join(distDir, "bin"))
shutil.copytree(os.path.join(buildDir, "certs"), os.path.join(distDir, "certs"))
shutil.copytree(os.path.join(buildDir, "demo"), os.path.join(distDir, "demo"))
shutil.copytree(os.path.join(buildDir, "ruby"), os.path.join(distDir, "ruby"))

shutil.copyfile(os.path.join(buildDir, "README.txt"), os.path.join(distDir, "README.txt"))
shutil.copyfile(os.path.join(buildDir, "LICENSE"), os.path.join(distDir, "LICENSE"))
shutil.copyfile(os.path.join(buildDir, "ICE_LICENSE"), os.path.join(distDir, "ICE_LICENSE"))

#
# Remove files.
#
print "Removing unnecessary files..."
filesToRemove = []
filesToRemove.extend(find(distDir, "Makefile"))
filesToRemove.extend(find(distDir, "*.mak"))
filesToRemove.extend(find(distDir, "*.dsp"))
filesToRemove.extend(find(distDir, "*.dsw"))
filesToRemove.extend(find(distDir, ".dummy"))
filesToRemove.extend(find(distDir, "*.plg"))
for x in filesToRemove:
    os.remove(x)
for x in find(distDir, "CVS"):
    shutil.rmtree(x)

#
# Create archives.
#
print "Creating distribution archive..."
if verbose:
    quiet = ""
else:
    quiet = "-q"
os.system("zip -9ry " + quiet + " " + archive + " " + distDir)

#
# Done.
#
print "Cleaning up..."
shutil.rmtree(distDir)
print "Done."