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):
51
except usage.error, ue:
52
sys.exit("%s: %s" % (sys.argv[0], ue))
54
tap_file = config['tapfile']
55
base_tap_file = os.path.basename(config['tapfile'])
56
protocol = (config['protocol'] or os.path.splitext(base_tap_file)[0])
57
deb_file = config['debfile'] or 'twisted-'+protocol
58
version = config['set-version']
59
maintainer = config['maintainer']
60
description = config['description'] or ('A Twisted-based server for %(protocol)s' %
62
long_description = config['long_description'] or 'Automatically created by tap2deb'
63
twistd_option = type_dict[config['type']]
64
date = string.strip(os.popen('822-date').read())
65
directory = deb_file + '-' + version
66
python_version = '%s.%s' % sys.version_info[:2]
68
if os.path.exists(os.path.join('.build', directory)):
69
os.system('rm -rf %s' % os.path.join('.build', directory))
70
os.makedirs(os.path.join('.build', directory, 'debian'))
72
shutil.copy(tap_file, os.path.join('.build', directory))
74
save_to_file(os.path.join('.build', directory, 'debian', 'README.Debian'),
75
'''This package was auto-generated by tap2deb\n''')
77
save_to_file(os.path.join('.build', directory, 'debian', 'conffiles'),
79
/etc/init.d/%(deb_file)s
80
/etc/default/%(deb_file)s
81
/etc/%(base_tap_file)s
84
save_to_file(os.path.join('.build', directory, 'debian', 'default'),
86
pidfile=/var/run/%(deb_file)s.pid
87
rundir=/var/lib/%(deb_file)s/
88
file=/etc/%(tap_file)s
89
logfile=/var/log/%(deb_file)s.log
92
save_to_file(os.path.join('.build', directory, 'debian', 'init.d'),
96
PATH=/sbin:/bin:/usr/sbin:/usr/bin
98
pidfile=/var/run/%(deb_file)s.pid \
99
rundir=/var/lib/%(deb_file)s/ \
100
file=/etc/%(tap_file)s \
101
logfile=/var/log/%(deb_file)s.log
103
[ -r /etc/default/%(deb_file)s ] && . /etc/default/%(deb_file)s
105
test -x /usr/bin/twistd%(python_version)s || exit 0
106
test -r $file || exit 0
107
test -r /usr/share/%(deb_file)s/package-installed || exit 0
112
echo -n "Starting %(deb_file)s: twistd"
113
start-stop-daemon --start --quiet --exec /usr/bin/twistd%(python_version)s -- \
116
--%(twistd_option)s=$file \
122
echo -n "Stopping %(deb_file)s: twistd"
123
start-stop-daemon --stop --quiet \
138
echo "Usage: /etc/init.d/%(deb_file)s {start|stop|restart|force-reload}" >&2
146
os.chmod(os.path.join('.build', directory, 'debian', 'init.d'), 0755)
148
save_to_file(os.path.join('.build', directory, 'debian', 'postinst'),
151
update-rc.d %(deb_file)s defaults >/dev/null
152
invoke-rc.d %(deb_file)s start
155
save_to_file(os.path.join('.build', directory, 'debian', 'prerm'),
158
invoke-rc.d %(deb_file)s stop
161
save_to_file(os.path.join('.build', directory, 'debian', 'postrm'),
164
if [ "$1" = purge ]; then
165
update-rc.d %(deb_file)s remove >/dev/null
169
save_to_file(os.path.join('.build', directory, 'debian', 'changelog'),
171
%(deb_file)s (%(version)s) unstable; urgency=low
175
-- %(maintainer)s %(date)s
179
save_to_file(os.path.join('.build', directory, 'debian', 'control'),
184
Maintainer: %(maintainer)s
185
Build-Depends-Indep: debhelper
186
Standards-Version: 3.5.6
188
Package: %(deb_file)s
190
Depends: python%(python_version)s-twisted
191
Description: %(description)s
195
save_to_file(os.path.join('.build', directory, 'debian', 'copyright'),
197
This package was auto-debianized by %(maintainer)s on
200
It was auto-generated by tap2deb
203
Moshe Zadka <moshez@twistedmatrix.com> -- tap2deb author
207
Insert copyright here.
210
save_to_file(os.path.join('.build', directory, 'debian', 'dirs'),
215
usr/share/doc/%(deb_file)s
216
usr/share/%(deb_file)s
219
save_to_file(os.path.join('.build', directory, 'debian', 'rules'),
233
rm -f build-stamp install-stamp
236
install: install-stamp
237
install-stamp: build-stamp
243
# Add here commands to install the package into debian/tmp.
244
cp %(base_tap_file)s debian/tmp/etc/
245
cp debian/init.d debian/tmp/etc/init.d/%(deb_file)s
246
cp debian/default debian/tmp/etc/default/%(deb_file)s
247
cp debian/copyright debian/tmp/usr/share/doc/%(deb_file)s/
248
cp debian/README.Debian debian/tmp/usr/share/doc/%(deb_file)s/
249
touch debian/tmp/usr/share/%(deb_file)s/package-installed
252
binary-arch: build install
254
binary-indep: build install
268
@echo >&2 'source and diff are obsolete - use dpkg-source -b'; false
270
binary: binary-indep binary-arch
271
.PHONY: build clean binary-indep binary-arch binary install
274
os.chmod(os.path.join('.build', directory, 'debian', 'rules'), 0755)
276
os.chdir('.build/%(directory)s' % vars())
277
os.system('dpkg-buildpackage -rfakeroot'+ ['', ' -uc -us'][config['unsigned']])
279
if __name__ == '__main__':