summaryrefslogtreecommitdiff
path: root/php/makedist.py
blob: 74443c6d109c8631e9abcd0a32c68919892cf268 (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
#!/usr/bin/env python
# **********************************************************************
#
# Copyright (c) 2003
# ZeroC, Inc.
# Billerica, MA, USA
#
# All Rights Reserved.
#
# Ice is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# **********************************************************************

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

#
# Program usage.
#
def usage():
    print "Usage: " + sys.argv[0] + " [options] [tag]"
    print
    print "Options:"
    print "-h    Show this message."
    print
    print "If no tag is specified, HEAD 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 os.path.isdir(fullpath) and not os.path.islink(fullpath):
            result.extend(find(fullpath, patt))
        elif fnmatch.fnmatch(x, patt):
            result.append(fullpath)
    return result

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

if not os.environ.has_key("ICE_HOME"):
    print "The ICE_HOME environment variable is not set."
    sys.exit(1)

#
# Remove any existing "dist" directory and create a new one.
#
distdir = "dist"
if os.path.exists(distdir):
    shutil.rmtree(distdir)
os.mkdir(distdir)
os.chdir(distdir)

#
# Export sources from CVS.
#
os.system("cvs -d cvs.mutablerealms.com:/home/cvsroot export " + tag + " icephp")

#
# Remove files.
#
filesToRemove = [ \
    os.path.join("icephp", "makedist.py"), \
    ]
filesToRemove.extend(find("icephp", ".dummy"))
for x in filesToRemove:
    os.remove(x)

#
# Get IcePHP version.
#
config = open(os.path.join("icephp", "src", "ice", "php_ice.h"), "r")
version = re.search("ICEPHP_STRING_VERSION \"([0-9\.]*)\"", config.read()).group(1)

#
# Create archives.
#
icephpver = "IcePHP-" + version
os.rename("icephp", icephpver)
os.system("tar cvzf " + icephpver + ".tar.gz " + icephpver)
os.system("zip -9r " + icephpver + ".zip " + icephpver)

#
# Copy files (README, etc.).
#

#
# Done.
#
shutil.rmtree(icephpver)