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