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