1
# Copyright (c) 2001-2004 Twisted Matrix Laboratories.
2
# See LICENSE for details.
6
import sys, os, string, shutil
8
from twisted.python import usage
10
class MyOptions(usage.Options):
11
optFlags = [["unsigned", "u"]]
12
optParameters = [["tapfile", "t", "twistd.tap"],
13
["maintainer", "m", "", "The maintainer's name and email in a specific format: "
14
"'John Doe <johndoe@example.com>'"],
15
["protocol", "p", ""],
16
["description", "e", ""],
17
["long_description", "l", ""],
18
["set-version", "V", "1.0"],
19
["debfile", "d", None],
20
["type", "y", "tap", "type of configuration: 'tap', 'xml, 'source' or 'python' for .tac files"]]
22
#zsh_altArgDescr = {"foo":"use this description for foo instead"}
23
#zsh_multiUse = ["foo", "bar"]
24
#zsh_mutuallyExclusive = [("foo", "bar"), ("bar", "baz")]
25
zsh_actions = {"type":"(tap xml source python)"}
26
#zsh_actionDescr = {"logfile":"log file name", "random":"random seed"}
28
def postOptions(self):
29
if not self["maintainer"]:
30
raise usage.UsageError, "maintainer must be specified."
40
def save_to_file(file, text):
41
open(file, 'w').write(text)
49
except usage.error, ue:
50
sys.exit("%s: %s" % (sys.argv[0], ue))
52
tap_file = config['tapfile']
53
base_tap_file = os.path.basename(config['tapfile'])
54
protocol = (config['protocol'] or os.path.splitext(base_tap_file)[0])
55
deb_file = config['debfile'] or 'twisted-'+protocol
56
version = config['set-version']
57
maintainer = config['maintainer']
58
description = config['description'] or ('A Twisted-based server for %(protocol)s' %
60
long_description = config['long_description'] or 'Automatically created by tap2deb'
61
twistd_option = type_dict[config['type']]
62
date = string.strip(os.popen('822-date').read())
63
directory = deb_file + '-' + version
64
python_version = '%s.%s' % sys.version_info[:2]
66
if os.path.exists(os.path.join('.build', directory)):
67
os.system('rm -rf %s' % os.path.join('.build', directory))
68
os.makedirs(os.path.join('.build', directory, 'debian'))
70
shutil.copy(tap_file, os.path.join('.build', directory))
72
save_to_file(os.path.join('.build', directory, 'debian', 'README.Debian'),
73
'''This package was auto-generated by tap2deb\n''')
75
save_to_file(os.path.join('.build', directory, 'debian', 'conffiles'),
77
/etc/init.d/%(deb_file)s
78
/etc/default/%(deb_file)s
79
/etc/%(base_tap_file)s
82
save_to_file(os.path.join('.build', directory, 'debian', 'default'),
84
pidfile=/var/run/%(deb_file)s.pid
85
rundir=/var/lib/%(deb_file)s/
86
file=/etc/%(tap_file)s
87
logfile=/var/log/%(deb_file)s.log
90
save_to_file(os.path.join('.build', directory, 'debian', 'init.d'),
94
PATH=/sbin:/bin:/usr/sbin:/usr/bin
96
pidfile=/var/run/%(deb_file)s.pid \
97
rundir=/var/lib/%(deb_file)s/ \
98
file=/etc/%(tap_file)s \
99
logfile=/var/log/%(deb_file)s.log
101
[ -r /etc/default/%(deb_file)s ] && . /etc/default/%(deb_file)s
103
test -x /usr/bin/twistd%(python_version)s || exit 0
104
test -r $file || exit 0
105
test -r /usr/share/%(deb_file)s/package-installed || exit 0
110
echo -n "Starting %(deb_file)s: twistd"
111
start-stop-daemon --start --quiet --exec /usr/bin/twistd%(python_version)s -- \
114
--%(twistd_option)s=$file \
120
echo -n "Stopping %(deb_file)s: twistd"
121
start-stop-daemon --stop --quiet \
136
echo "Usage: /etc/init.d/%(deb_file)s {start|stop|restart|force-reload}" >&2
144
os.chmod(os.path.join('.build', directory, 'debian', 'init.d'), 0755)
146
save_to_file(os.path.join('.build', directory, 'debian', 'postinst'),
149
update-rc.d %(deb_file)s defaults >/dev/null
150
invoke-rc.d %(deb_file)s start
153
save_to_file(os.path.join('.build', directory, 'debian', 'prerm'),
156
invoke-rc.d %(deb_file)s stop
159
save_to_file(os.path.join('.build', directory, 'debian', 'postrm'),
162
if [ "$1" = purge ]; then
163
update-rc.d %(deb_file)s remove >/dev/null
167
save_to_file(os.path.join('.build', directory, 'debian', 'changelog'),
169
%(deb_file)s (%(version)s) unstable; urgency=low
173
-- %(maintainer)s %(date)s
177
save_to_file(os.path.join('.build', directory, 'debian', 'control'),
182
Maintainer: %(maintainer)s
183
Build-Depends-Indep: debhelper
184
Standards-Version: 3.5.6
186
Package: %(deb_file)s
188
Depends: python%(python_version)s-twisted
189
Description: %(description)s
193
save_to_file(os.path.join('.build', directory, 'debian', 'copyright'),
195
This package was auto-debianized by %(maintainer)s on
198
It was auto-generated by tap2deb
201
Moshe Zadka <moshez@twistedmatrix.com> -- tap2deb author
205
Insert copyright here.
208
save_to_file(os.path.join('.build', directory, 'debian', 'dirs'),
213
usr/share/doc/%(deb_file)s
214
usr/share/%(deb_file)s
217
save_to_file(os.path.join('.build', directory, 'debian', 'rules'),
231
rm -f build-stamp install-stamp
234
install: install-stamp
235
install-stamp: build-stamp
241
# Add here commands to install the package into debian/tmp.
242
cp %(base_tap_file)s debian/tmp/etc/
243
cp debian/init.d debian/tmp/etc/init.d/%(deb_file)s
244
cp debian/default debian/tmp/etc/default/%(deb_file)s
245
cp debian/copyright debian/tmp/usr/share/doc/%(deb_file)s/
246
cp debian/README.Debian debian/tmp/usr/share/doc/%(deb_file)s/
247
touch debian/tmp/usr/share/%(deb_file)s/package-installed
250
binary-arch: build install
252
binary-indep: build install
266
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
268
binary: binary-indep binary-arch
269
.PHONY: build clean binary-indep binary-arch binary install
272
os.chmod(os.path.join('.build', directory, 'debian', 'rules'), 0755)
274
os.chdir('.build/%(directory)s' % vars())
275
os.system('dpkg-buildpackage -rfakeroot'+ ['', ' -uc -us'][config['unsigned']])
277
if __name__ == '__main__':