~ubuntu-branches/ubuntu/quantal/torchat/quantal

« back to all changes in this revision

Viewing changes to make_release_zip.py

  • Committer: Bazaar Package Importer
  • Author(s): Ulises Vitulli
  • Date: 2011-04-16 23:35:04 UTC
  • Revision ID: james.westby@ubuntu.com-20110416233504-j4dulunjoc224vfp
Tags: upstream-0.9.9.534
ImportĀ upstreamĀ versionĀ 0.9.9.534

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
2
# !!!                                          !!!
 
3
# !!!  THIS SCRIPT WILL DELETE THE BIN FOLDER  !!!
 
4
# !!!                                          !!!
 
5
# !!!  and all its contents and then it will   !!!
 
6
# !!!      create a new one from scratch.      !!!
 
7
# !!!          You have been warned.           !!!
 
8
# !!!                                          !!!
 
9
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
10
 
 
11
# this is RUN ON WINDOWS and
 
12
# needs some tools installed:
 
13
#
 
14
#   python 2.7.x
 
15
#   wxpython 2.8 (the unicode version)
 
16
#   upx.exe (must be in the PATH)
 
17
#   pythonwin extensions (needed by pyinstaller)
 
18
#   pyinstaller latest trunk (in c:\pyinst\)
 
19
#
 
20
#   also put a copy of tor.exe into src/Tor
 
21
#
 
22
# run make_windows_binary.py from within the src directory and
 
23
# you should end up with the zip files in the ../release folder
 
24
# and a fresh bin folder to test the newly created torchat.exe
 
25
 
 
26
import version
 
27
import os
 
28
import sys
 
29
import shutil
 
30
import zlib
 
31
import zipfile
 
32
import glob
 
33
 
 
34
# pyinstaller must have been configured aleady
 
35
PYINSTALLER_PATH = "c:\\pyinst"
 
36
 
 
37
 
 
38
# ----------------------------------------------------
 
39
# first some useful helpers to zip, copy, delete files
 
40
# ----------------------------------------------------
 
41
 
 
42
class MyZip(zipfile.ZipFile):
 
43
    def add(self, pattern):
 
44
        for name in glob.glob(pattern):
 
45
            print "adding %s" % name
 
46
            self.write(name, name, zipfile.ZIP_DEFLATED)
 
47
 
 
48
def unlink(patterns):
 
49
    """delete files. takes a list of names or patterns"""
 
50
    for pattern in patterns:
 
51
        print "trying to unlink %s" % pattern
 
52
        for name in glob.glob(pattern):
 
53
            try:
 
54
                os.unlink(name)
 
55
                print "unlinked %s" % name
 
56
            except:
 
57
                print "could not unlink %s" % name
 
58
 
 
59
def copy(patterns):
 
60
    """copy files. takes a list of tuples of which
 
61
    the first element is a name or pattern and the
 
62
    second one is is the destination directory"""
 
63
    for pattern, dest_dir in patterns:
 
64
        print "trying to copy %s to %s" % (pattern, dest_dir)
 
65
        for name in glob.glob(pattern):
 
66
            try:
 
67
                shutil.copy(name, dest_dir)
 
68
                print "copied %s" % name
 
69
            except:
 
70
                print "could not copy %s" % name
 
71
 
 
72
def zip(zipfile_name, patterns):
 
73
    """add files to the archive zipfile_name.
 
74
    Takes a list of filenames or wildcard patterns"""
 
75
    print "\nopening %s" % zipfile_name
 
76
    archive = MyZip(zipfile_name, "a")
 
77
    zlib.Z_DEFAULT_COMPRESSION = zlib.Z_BEST_COMPRESSION
 
78
    for pattern in patterns:
 
79
        archive.add(pattern)
 
80
    print "closing %s" % zipfile_name
 
81
    archive.close()
 
82
 
 
83
def zipSrc(zipfile_name):
 
84
    zip(zipfile_name, [
 
85
        "doc\\*",
 
86
        "src\\*.py",
 
87
        "src\\*.spec",
 
88
        "src\\*.bat",
 
89
        "src\\portable.txt",
 
90
        "src\\changelog.txt",
 
91
        "src\\LICENSE",
 
92
 
 
93
        "src\\translations\\*.txt",
 
94
        "src\\translations\\lang_*.py",
 
95
        "src\\translations\\insert_missing.py",
 
96
        "src\\translations\\__init__.py",
 
97
 
 
98
        "src\\SocksiPy\\*.py",
 
99
        "src\\SocksiPy\\BUGS",
 
100
        "src\\SocksiPy\\LICENSE",
 
101
        "src\\SocksiPy\\README",
 
102
 
 
103
        "src\\icons\\*.png",
 
104
        "src\\icons\\*.ico",
 
105
 
 
106
        "src\\Tor\\tor.sh",
 
107
        "src\\Tor\\torrc.txt"
 
108
    ])
 
109
 
 
110
def zipBin(zipfile_name):
 
111
    zip(zipfile_name, [
 
112
        "bin\\*",
 
113
        "bin\\Tor\\*",
 
114
        "bin\\icons\\*"
 
115
    ])
 
116
 
 
117
def clean(folder):
 
118
    print "\ncleaning %s" % folder
 
119
    unlink([
 
120
        "%s\\*.pyo" % folder,
 
121
        "%s\\*.pyc" % folder,
 
122
        "%s\\*.log" % folder,
 
123
        "%s\\*.tmp" % folder,
 
124
        "%s\\*~" % folder,
 
125
        "%s\\*offline*" % folder,
 
126
        "%s\\*incoming*" % folder,
 
127
        "%s\\DEADJOE" % folder
 
128
    ])
 
129
 
 
130
def cleanSrc():
 
131
    clean(".")
 
132
    clean("translations")
 
133
    clean("SocksiPy")
 
134
 
 
135
# ------------------
 
136
# and here it begins
 
137
# ------------------
 
138
 
 
139
try:
 
140
    os.mkdir("..\\release")
 
141
except:
 
142
    pass
 
143
 
 
144
if not os.path.exists("Tor\\tor.exe"):
 
145
    print "!!! need a copy of tor.exe in the src\\Tor folder"
 
146
    sys.exit()
 
147
 
 
148
# clean up the src directory
 
149
cleanSrc()
 
150
os.system("rmdir /S /Q dist")
 
151
os.system("rmdir /S /Q build")
 
152
 
 
153
# build the .exe with pyinstaller
 
154
# the following will result in a command line like this::
 
155
# "c:\Python27\python.exe c:\pyinst\Build.py torchat_windows.spec"
 
156
cmd = sys.executable \
 
157
    + " " + os.path.join(PYINSTALLER_PATH, 'Build.py') \
 
158
    + " torchat_windows.spec"
 
159
 
 
160
print "\n\n" + cmd
 
161
os.system(cmd)
 
162
 
 
163
# check for success
 
164
if not os.path.exists("dist\\torchat.exe"):
 
165
    print "!!! pyinstaller did not run properly"
 
166
    sys.exit()
 
167
 
 
168
# now we have all files we need. We now put together
 
169
# the contents of the bin folder exactly as it will be
 
170
# in the final zip file. First make an empty bin folder.
 
171
print "\n\nputting together the contents of the bin folder"
 
172
os.system("rmdir /S /Q ..\\bin")
 
173
os.system("mkdir ..\\bin")
 
174
os.system("mkdir ..\\bin\\icons")
 
175
os.system("mkdir ..\\bin\\Tor")
 
176
 
 
177
#now copy the needed files to bin
 
178
copy([
 
179
    ("dist\\torchat.exe", "..\\bin"),
 
180
    ("portable.txt", "..\\bin"),
 
181
    ("Tor\\tor.exe", "..\\bin\\Tor"),
 
182
    ("Tor\\torrc.txt", "..\\bin\\Tor"),
 
183
    ("icons\\*.png", "..\\bin\\icons"),
 
184
    ("icons\\*.ico", "..\\bin\\icons"),
 
185
])
 
186
 
 
187
print "\n\ncreating the zip files"
 
188
os.chdir("..")
 
189
bin_zip_filename = "release\\torchat-windows-%s.zip" % version.VERSION
 
190
src_zip_filename = "release\\torchat-source-%s.zip" % version.VERSION
 
191
unlink([bin_zip_filename, src_zip_filename])
 
192
 
 
193
# torchat-windows-x.x.x.x.zip
 
194
zipBin(bin_zip_filename)
 
195
zipSrc(bin_zip_filename)
 
196
 
 
197
# torchat-source-x.x.x.x.zip
 
198
zipSrc(src_zip_filename)
 
199