Redaction de la doc + corrections
[cyril.git] / Scripts / MakeDeb / make_deb.py
1 #!/usr/bin/python
2
3 from glob import glob
4 import shutil, os, sys
5
6 control_template = """Source: %s
7 Section: python
8 Priority: extra
9 Maintainer: %s <%s>
10 Build-Depends: debhelper (>= 7), python-support
11 Standards-Version: 3.8.0
12 Homepage: %s
13
14 Package: %s
15 Architecture: all
16 Depends: python (>= 2.6)%s
17 Description: %s
18 """
19
20 rules_template = """#!/usr/bin/make -f
21 # -*- makefile -*-
22 configure: configure-stamp
23 configure-stamp:
24 dh_testdir
25 touch configure-stamp
26 build: build-stamp
27 build-stamp: configure-stamp
28 dh_testdir
29 $(MAKE)
30 touch $@
31 clean:
32 dh_testdir
33 dh_testroot
34 rm -f build-stamp configure-stamp
35 dh_clean
36 install: build
37 dh_testdir
38 dh_testroot
39 dh_prep
40 dh_installdirs
41 $(MAKE) DESTDIR=$(CURDIR)/debian/%s install
42 binary-arch: build install
43 # rien
44 binary-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
59 binary: binary-indep
60 .PHONY: build clean binary-indep binary install configure
61 """
62
63 dirs_template = """usr/share/pyshared/%s
64 """
65
66 makefile_template = """APPDIR = $(DESTDIR)/usr/share/pyshared/%s
67 clean:
68 rm -f *.py[co] */*.py[co]
69 install:
70 mkdir -p $(APPDIR)
71 %s
72 uninstall:
73 rm -rf $(APPDIR)
74 """
75
76 postinst_template = """#!/bin/sh
77 set -e
78 case "$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 ;;
91 esac
92 exit 0
93 """
94
95 compat_template = "7\n"
96
97
98 def 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
113 def write_file (filename, content):
114 fd = open (filename, "w")
115 fd.write (content)
116 fd.close ()
117
118 def usage ():
119 print "Usage: python %s <dossier>" % sys.argv[0]
120
121 if __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