File: make_release_zip.py

package info (click to toggle)
torchat 0.9.9.550-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 772 kB
  • sloc: python: 5,527; makefile: 45; sh: 5
file content (199 lines) | stat: -rw-r--r-- 5,835 bytes parent folder | download | duplicates (3)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# !!!                                          !!!
# !!!  THIS SCRIPT WILL DELETE THE BIN FOLDER  !!!
# !!!                                          !!!
# !!!  and all its contents and then it will   !!!
# !!!      create a new one from scratch.      !!!
# !!!          You have been warned.           !!!
# !!!                                          !!!
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

# this is RUN ON WINDOWS and
# needs some tools installed:
#
#   python 2.7.x
#   wxpython 2.8 (the unicode version)
#   upx.exe (must be in the PATH)
#   pythonwin extensions (needed by pyinstaller)
#   pyinstaller latest trunk (in c:\pyinst\)
#
#   also put a copy of tor.exe into src/Tor
#
# run make_windows_binary.py from within the src directory and
# you should end up with the zip files in the ../release folder
# and a fresh bin folder to test the newly created torchat.exe

import version
import os
import sys
import shutil
import zlib
import zipfile
import glob

# pyinstaller must have been configured aleady
PYINSTALLER_PATH = "c:\\pyinst"


# ----------------------------------------------------
# first some useful helpers to zip, copy, delete files
# ----------------------------------------------------

class MyZip(zipfile.ZipFile):
    def add(self, pattern):
        for name in glob.glob(pattern):
            print "adding %s" % name
            self.write(name, name, zipfile.ZIP_DEFLATED)

def unlink(patterns):
    """delete files. takes a list of names or patterns"""
    for pattern in patterns:
        print "trying to unlink %s" % pattern
        for name in glob.glob(pattern):
            try:
                os.unlink(name)
                print "unlinked %s" % name
            except:
                print "could not unlink %s" % name

def copy(patterns):
    """copy files. takes a list of tuples of which
    the first element is a name or pattern and the
    second one is is the destination directory"""
    for pattern, dest_dir in patterns:
        print "trying to copy %s to %s" % (pattern, dest_dir)
        for name in glob.glob(pattern):
            try:
                shutil.copy(name, dest_dir)
                print "copied %s" % name
            except:
                print "could not copy %s" % name

def zip(zipfile_name, patterns):
    """add files to the archive zipfile_name.
    Takes a list of filenames or wildcard patterns"""
    print "\nopening %s" % zipfile_name
    archive = MyZip(zipfile_name, "a")
    zlib.Z_DEFAULT_COMPRESSION = zlib.Z_BEST_COMPRESSION
    for pattern in patterns:
        archive.add(pattern)
    print "closing %s" % zipfile_name
    archive.close()

def zipSrc(zipfile_name):
    zip(zipfile_name, [
        "doc\\*",
        "src\\*.py",
        "src\\*.spec",
        "src\\*.bat",
        "src\\portable.txt",
        "src\\changelog.txt",
        "src\\LICENSE",

        "src\\translations\\*.txt",
        "src\\translations\\lang_*.py",
        "src\\translations\\insert_missing.py",
        "src\\translations\\__init__.py",

        "src\\SocksiPy\\*.py",
        "src\\SocksiPy\\BUGS",
        "src\\SocksiPy\\LICENSE",
        "src\\SocksiPy\\README",

        "src\\icons\\*.png",
        "src\\icons\\*.ico",

        "src\\Tor\\tor.sh",
        "src\\Tor\\torrc.txt"
    ])

def zipBin(zipfile_name):
    zip(zipfile_name, [
        "bin\\*",
        "bin\\Tor\\*",
        "bin\\icons\\*"
    ])

def clean(folder):
    print "\ncleaning %s" % folder
    unlink([
        "%s\\*.pyo" % folder,
        "%s\\*.pyc" % folder,
        "%s\\*.log" % folder,
        "%s\\*.tmp" % folder,
        "%s\\*~" % folder,
        "%s\\*offline*" % folder,
        "%s\\*incoming*" % folder,
        "%s\\DEADJOE" % folder
    ])

def cleanSrc():
    clean(".")
    clean("translations")
    clean("SocksiPy")

# ------------------
# and here it begins
# ------------------

try:
    os.mkdir("..\\release")
except:
    pass

if not os.path.exists("Tor\\tor.exe"):
    print "!!! need a copy of tor.exe in the src\\Tor folder"
    sys.exit()

# clean up the src directory
cleanSrc()
os.system("rmdir /S /Q dist")
os.system("rmdir /S /Q build")

# build the .exe with pyinstaller
# the following will result in a command line like this::
# "c:\Python27\python.exe c:\pyinst\Build.py torchat_windows.spec"
cmd = sys.executable \
    + " " + os.path.join(PYINSTALLER_PATH, 'Build.py') \
    + " torchat_windows.spec"

print "\n\n" + cmd
os.system(cmd)

# check for success
if not os.path.exists("dist\\torchat.exe"):
    print "!!! pyinstaller did not run properly"
    sys.exit()

# now we have all files we need. We now put together
# the contents of the bin folder exactly as it will be
# in the final zip file. First make an empty bin folder.
print "\n\nputting together the contents of the bin folder"
os.system("rmdir /S /Q ..\\bin")
os.system("mkdir ..\\bin")
os.system("mkdir ..\\bin\\icons")
os.system("mkdir ..\\bin\\Tor")

#now copy the needed files to bin
copy([
    ("dist\\torchat.exe", "..\\bin"),
    ("portable.txt", "..\\bin"),
    ("Tor\\tor.exe", "..\\bin\\Tor"),
    ("Tor\\torrc.txt", "..\\bin\\Tor"),
    ("icons\\*.png", "..\\bin\\icons"),
    ("icons\\*.ico", "..\\bin\\icons"),
])

print "\n\ncreating the zip files"
os.chdir("..")
bin_zip_filename = "release\\torchat-windows-%s.zip" % version.VERSION
src_zip_filename = "release\\torchat-source-%s.zip" % version.VERSION
unlink([bin_zip_filename, src_zip_filename])

# torchat-windows-x.x.x.x.zip
zipBin(bin_zip_filename)
zipSrc(bin_zip_filename)

# torchat-source-x.x.x.x.zip
zipSrc(src_zip_filename)