Redaction de la doc + corrections
[cyril.git] / Scripts / MakeDeb / make_deb.py
CommitLineData
4298640a 1#!/usr/bin/python
2
9bd8db0b 3from glob import glob
4import shutil, os, sys
5
6control_template = """Source: %s
7Section: python
8Priority: extra
9Maintainer: %s <%s>
10Build-Depends: debhelper (>= 7), python-support
11Standards-Version: 3.8.0
12Homepage: %s
13
14Package: %s
15Architecture: all
16Depends: python (>= 2.6)%s
17Description: %s
18"""
19
20rules_template = """#!/usr/bin/make -f
21# -*- makefile -*-
22configure: configure-stamp
23configure-stamp:
24 dh_testdir
25 touch configure-stamp
26build: build-stamp
27build-stamp: configure-stamp
28 dh_testdir
29 $(MAKE)
30 touch $@
31clean:
32 dh_testdir
33 dh_testroot
34 rm -f build-stamp configure-stamp
35 dh_clean
36install: build
37 dh_testdir
38 dh_testroot
39 dh_prep
40 dh_installdirs
41 $(MAKE) DESTDIR=$(CURDIR)/debian/%s install
42binary-arch: build install
43 # rien
44binary-indep: build install
45 dh_testdir
46 dh_testroot
47 dh_installchangelogs
48 dh_installdocs
49 dh_installexamples
50 dh_pysupport
51 dh_link
52 dh_compress -X.js
53 dh_fixperms
54 dh_installdeb
55 dh_shlibdeps
56 dh_gencontrol
57 dh_md5sums
58 dh_builddeb
59binary: binary-indep
60.PHONY: build clean binary-indep binary install configure
61"""
62
63dirs_template = """usr/share/pyshared/%s
64"""
65
66makefile_template = """APPDIR = $(DESTDIR)/usr/share/pyshared/%s
67clean:
68 rm -f *.py[co] */*.py[co]
69install:
70 mkdir -p $(APPDIR)
71%s
72uninstall:
73 rm -rf $(APPDIR)
74"""
75
76postinst_template = """#!/bin/sh
77set -e
78case "$1" in
79 configure)
80 ln -s /usr/share/pyshared/%s /usr/lib/python2.6/dist-packages/%s
81 ;;
82
83 abort-upgrade|abort-remove|abort-deconfigure)
84 rm -f /usr/lib/python2.6/dist-packages/%s
85 ;;
86
87 *)
88 echo "postinst called with unknown argument \`$1'" >&2
89 exit 1
90 ;;
91esac
92exit 0
93"""
94
95compat_template = "7\n"
96
97
98def read_parameters ():
99 data = {}
100 print "Auteur: ",
101 data['author'] = sys.stdin.readline ().strip ()
102 print "Courriel: ",
103 data['email'] = sys.stdin.readline ().strip ()
104 print "URL: ",
105 data['homepage'] = sys.stdin.readline ().strip ()
106 print "Dependances supplementaires: ",
107 data['extradeps'] = sys.stdin.readline ().strip ()
108 print "Description: ",
109 data['description'] = sys.stdin.readline ().strip ()
110 print
111 return data
112
113def write_file (filename, content):
114 fd = open (filename, "w")
115 fd.write (content)
116 fd.close ()
117
118def usage ():
119 print "Usage: python %s <dossier>" % sys.argv[0]
120
121if __name__ == '__main__':
122 if len (sys.argv) < 2:
123 usage ()
124 sys.exit (-1)
125
126 localpath = sys.argv[1]
127 if localpath.endswith("/"):
128 localpath = localpath[0:-1]
129 package = localpath.replace ("-", "_")
130 debpackage = package.replace ("_", "-")
131
132 print "Configuration pour le paquet", debpackage
133 p = read_parameters ()
134
135 path = "/tmp/%s" % package
136 if os.path.exists (path):
137 shutil.rmtree (path)
138 shutil.copytree (localpath, path)
139
140 os.makedirs ("%s/debian/" % path)
141
142 control = control_template % \
143 (debpackage, p['author'], p['email'], p['homepage'], \
144 debpackage, p['extradeps'], p['description'])
145 write_file ("%s/debian/control" % path, control)
146
147 rules = rules_template % (debpackage)
148 write_file ("%s/debian/rules" % path, rules)
149
150 dirs = dirs_template % (package)
151 write_file ("%s/debian/dirs" % path, dirs)
152
153 compat = compat_template
154 write_file ("%s/debian/compat" % path, compat)
155
156 postinst = postinst_template % (package, package, package)
157 write_file ("%s/debian/postinst" % path, postinst)
158
159 blacklist = ("debian", "DEBIAN", "Makefile", "build-stamp", "configure-stamp")
160 copy = ""
161 for i in glob (localpath + "/*.py"):
162 file = os.path.basename (i)
163 if file not in blacklist:
164 copy += "\tcp -r %s $(APPDIR)\n" % file
165 makefile = makefile_template % (package, copy)
166 write_file ("%s/Makefile" % path, makefile)
167
168 os.rename ("%s/changelog.txt" % path, "%s/debian/changelog" % path)
169
170 old = os.getcwd ()
171 os.chdir (path)
172 os.system ("debuild")
173
174 files = glob ("/tmp/%s*.deb" % package.replace("_", "-"))
175 if len (files) == 1:
176 shutil.copy (files[0], old)
177 print "\n\n%s ecrit." % os.path.basename (files[0])
178 else:
179 print "\n\nTrop de .deb dans /tmp : ", files
180