-
Notifications
You must be signed in to change notification settings - Fork 0
/
make
executable file
·268 lines (223 loc) · 8.48 KB
/
make
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
#!/usr/bin/python
# This file is part of Atarashii.
#
# Atarashii is free software: you can redistribute it and/or
# modify it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Atarashii is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Atarashii. If not, see <http://www.gnu.org/licenses/>.
# Debian Packager Creator ------------------------------------------------------
# ------------------------------------------------------------------------------
import sys, os, shutil, subprocess, hashlib, time
def getFileMD5(file):
f = open(file, 'rb')
md5 = hashlib.md5()
while True:
data = f.read(8192)
if not data:
break
md5.update(data)
f.close()
return md5.hexdigest()
def getStringMD5(string):
return hashlib.md5(string).hexdigest()
def update_init_file(commits, sha):
init_file = os.path.join(sys.path[0], 'atarashii/usr/share/pyshared/atarashii/__init__.py')
import re
f = open(init_file, 'rb')
init_data = f.read()
f.close()
countRegex = re.compile('__kittens__ = \'([0-9]+)\'''')
init_data = countRegex.sub('__kittens__ = \'%s\'' % commits, init_data)
shaRegex = re.compile('__secret__ = \'([0-9a-zA-Z]+)\'''')
init_data = shaRegex.sub('__secret__ = \'%s\'' % sha, init_data)
f = open(init_file, 'wb')
f.write(init_data)
f.close()
# Get latest commit number -----------------------------------------------------
print '\n-- Kittens are inspecting your repository ' + '-' * 37
proc = subprocess.Popen('git shortlog -s -n', shell = True, stdout = subprocess.PIPE)
stdout_value = proc.communicate()[0]
commit_count = 0
lines = stdout_value.split('\n')
for i in lines:
e = i.split('\t')[0].strip()
if e != '':
commit_count += int(e)
proc = subprocess.Popen('git log --shortstat -n 1', shell = True, stdout = subprocess.PIPE)
stdout_value = proc.communicate()[0]
commit_sha = stdout_value[7:14]
update_init_file(commit_count, commit_sha)
print ' ' + getStringMD5(str(commit_count))
print ' ' + getStringMD5(str(commit_sha))
print ' = Done!'
# Gather Information about the project -----------------------------------------
sys.path.insert(0, os.path.join(sys.path[0], 'atarashii/usr/share/pyshared'))
try:
import atarashii
finally:
sys.path.pop(0)
# Create DEBIAN directory ------------------------------------------------------
debDir = os.path.join(sys.path[0], 'atarashii/DEBIAN')
if not os.path.exists(debDir):
os.mkdir(debDir)
print '\n-- Kittens are writing your changelogs ' + '-' * 40
log = os.path.join(sys.path[0], 'changelog')
man = os.path.join(sys.path[0], 'manpage')
print ' ' + getStringMD5('Copying logs and manpage...')
log1 = os.path.join(sys.path[0], 'atarashii/usr/share/doc/atarashii/changelog')
log2 = os.path.join(sys.path[0], 'atarashii/usr/share/doc/atarashii/changelog.Debian')
man1 = os.path.join(sys.path[0], 'atarashii/usr/share/man/man1/atarashii.1')
man2 = os.path.join(sys.path[0], 'atarashii/usr/share/man/man1/atarashiigui.1')
shutil.copyfile(log, log1)
shutil.copyfile(log, log2)
shutil.copyfile(man, man1)
shutil.copyfile(man, man2)
print ' ' + getStringMD5('Removing old logs and manpage...')
try:
os.unlink(log1 + '.gz')
except:
pass
try:
os.unlink(log2 + '.gz')
except:
pass
try:
os.unlink(man1 + '.gz')
except:
pass
try:
os.unlink(man2 + '.gz')
except:
pass
print ' ' + getStringMD5('Packing new logs and manpage...')
subprocess.call(['gzip', '--best', log1])
subprocess.call(['gzip', '--best', log2])
subprocess.call(['gzip', '--best', man1])
subprocess.call(['gzip', '--best', man2])
print ' = Done!'
# Check all files --------------------------------------------------------------
print '\n-- Kittens are calculating stuff, so you don\'t have to ' + '-' * 24
m = open(os.path.join(sys.path[0], 'atarashii/DEBIAN/md5sums'), 'w')
size = 0
cur = os.path.join(sys.path[0], 'atarashii/usr')
dirs = os.walk(cur)
tempFiles = []
deleted_count = 0
temped_count = 0
hashed_count = 0
for i in dirs:
files = i[2]
path = os.path.join(cur, i[0])
subprocess.call(['chmod', '755', path])
for f in files:
file = os.path.join(path, f)
if f.startswith('.'):
temped_count += 1
to = os.path.join(sys.path[0], 'tmp' + f)
tempFiles.append((file, to))
shutil.move(file, to)
elif f.endswith('~') or f.endswith('.pyc'):
os.remove(file)
deleted_count += 1
else:
if f == 'atarashii' or f == 'atarashiigui':
subprocess.call(['chmod', '644', file])
subprocess.call(['chmod', '+x', file])
else:
subprocess.call(['chmod', '644', file])
hashed_count += 1
size += os.stat(file).st_size
cf = file[len(cur)-3:]
m.write('%s %s\n' % (getFileMD5(file), cf))
m.close()
print ' ' + getStringMD5(str(temped_count))
print ' ' + getStringMD5(str(deleted_count))
print ' ' + getStringMD5(str(hashed_count))
cc = commit_count // 3.4
cd = int(commit_count * 5.7)
ce = cd // cc
tt = int(temped_count * ce)
result = (cc * cd) / (temped_count ** hashed_count ^ deleted_count * tt)
print ' = (%d * %d) / (%d ** %d ^ %d * %d) = %d' % (cc, cd, temped_count, hashed_count, deleted_count, tt, result)
print '\n-- Kittens are building your package ' + '-' * 42
# Write control file -----------------------------------------------------------
try:
os.remove(os.path.join(sys.path[0], 'atarashii/DEBIAN/postinst~'))
except:
pass
try:
os.remove(os.path.join(sys.path[0], 'atarashii/DEBIAN/postrm~'))
except:
pass
control_file = os.path.join(sys.path[0], 'atarashii/DEBIAN/control')
c = open(control_file, 'w')
c.write('''Package: atarashii
Version: ''' + atarashii.__version__ + '''-1
Section: misc
Priority: optional
Architecture: all
Installed-Size: ''' + str(size / 1024) + '''
Depends: python (>= 2.6), python-webkit, python-gtk2, python-gobject, python-dbus, python-gnome2, python-gconf, sox
Maintainer: Ivo Wetzel <ivo.wetzel@googlemail.com>
Homepage: http://github.com/BonsaiDen/Atarashii
Description: Twitter Client for the GNOME Desktop
Atarashii is a simple Twitter Client for your GNOME Desktop.
Its features include a clean minimalistic GUI, Desktop notifications with
configurable sounds, Themes, auto completion of usernames and CloudSync of
read Tweets and Messages. It's build using Python, GTK+ and Webkit.
''')
c.close()
time.sleep(0.1) # make sure dpkg-deb finds the control file!
# Create package
dpkg = False
try:
code = subprocess.call(['fakeroot', 'dpkg-deb', '--build', 'atarashii'],
stdout = open('/dev/null', 'wb'))
if code == 0:
dkpg = True
else:
raise OSError, 'DPKG failed'
debfile = os.path.join(sys.path[0], 'atarashii_%s-1_all.deb' % atarashii.__version__)
shutil.move(os.path.join(sys.path[0], 'atarashii.deb'), debfile)
deb_size = os.stat(debfile).st_size / 1024
except OSError, error:
if not dpkg:
print ''' ERROR: Could not build Atarashii package due to missing 'fakeroot'.\n Please install 'fakeroot' via the package manager and try again.'''
else:
print ''' ERROR: dpkg-deb failed to create the package.'''
print error
# Move all those temp files back
for file, to in tempFiles:
shutil.move(to, file)
update_init_file(0, '0000000')
exit()
print ' ' + getFileMD5(control_file)
print ' ' + getFileMD5(debfile)
print ' = Done!'
# Move all those temp files back
for file, to in tempFiles:
shutil.move(to, file)
update_init_file(0, '0000000')
# Check for errors
try:
subprocess.call(['lintian'], stdout = open('/dev/null', 'wb'))
print '\n-- Kittens are checking for package errors ' + '-' * 36
subprocess.call(['lintian', 'atarashii_%s-1_all.deb' % atarashii.__version__])
print ' = Done!'
except:
pass
# Stats
print '\n-- Kittens are showing you some stats ' + '-' * 41
print ' Version: %s' % atarashii.__version__
print ' Kittens: %d' % commit_count
print ' Lucky: %s' % commit_sha
print ' Size: %d KB' % (size / 1024)
print ' Compres: %d KB\n' % deb_size