Fixing package building
[multilist] / support / builddeb.py
1 #!/usr/bin/python2.5
2
3 import os
4 import sys
5
6 try:
7         import py2deb
8 except ImportError:
9         import fake_py2deb as py2deb
10
11 import constants
12
13
14 __appname__ = constants.__app_name__
15 __description__ = """Simple list management application
16 .
17 Homepage: http://multilist.garage.maemo.org/
18 """
19 __author__ = "Christoph Wurstle"
20 __email__ = "n800@axique.net"
21 __version__ = constants.__version__
22 __build__ = constants.__build__
23 __changelog__ = """
24 0.3.1
25   * I18N, extract de.po, add ru.po.
26
27 0.3.0
28   * Initial Release.
29 """
30
31
32 __postinstall__ = """#!/bin/sh -e
33
34 gtk-update-icon-cache -f /usr/share/icons/hicolor
35 rm -f ~/.multilist/multilist.log
36 """
37
38
39 def find_files(path, root):
40         print path, root
41         for unusedRoot, dirs, files in os.walk(path):
42                 for file in files:
43                         if file.startswith(root+"-"):
44                                 print "\t", root, file
45                                 fileParts = file.split("-")
46                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
47                                 assert unused == root
48                                 relPath = os.sep.join(relPathParts)
49                                 yield relPath, file, newName
50
51
52 def unflatten_files(files):
53         d = {}
54         for relPath, oldName, newName in files:
55                 if relPath not in d:
56                         d[relPath] = []
57                 d[relPath].append((oldName, newName))
58         return d
59
60
61 def build_package(distribution):
62         try:
63                 os.chdir(os.path.dirname(sys.argv[0]))
64         except:
65                 pass
66
67         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
68         p = py2deb.Py2deb(__appname__)
69         p.prettyName = constants.__pretty_app_name__
70         p.description = __description__
71         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=quicknote"
72         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
73         p.author = __author__
74         p.mail = __email__
75         p.license = "gpl"
76         p.depends = ", ".join([
77                 "python2.6 | python2.5",
78                 "python-gtk2 | python2.5-gtk2",
79                 "python-xml | python2.5-xml",
80                 "python-dbus | python2.5-dbus",
81         ])
82         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
83         p.depends += {
84                 "debian": ", python-glade2",
85                 "diablo": maemoSpecificDepends,
86                 "fremantle": maemoSpecificDepends + ", python-glade2",
87         }[distribution]
88         p.section = {
89                 "debian": "editors",
90                 "diablo": "user/office",
91                 "fremantle": "user/office",
92         }[distribution]
93         p.arch = "all"
94         p.urgency = "low"
95         p.distribution = "diablo fremantle debian"
96         p.repository = "extras"
97         p.changelog = __changelog__
98         p.postinstall = __postinstall__
99         p.icon = {
100                 "debian": "26x26-multilist.png",
101                 "diablo": "26x26-multilist.png",
102                 "fremantle": "40x40-multilist.png", # Fremantle natively uses 48x48
103         }[distribution]
104         p["/usr/bin"] = [ "multilist.py" ]
105         for relPath, files in unflatten_files(find_files(".", "locale")).iteritems():
106                 fullPath = "/usr/share/locale"
107                 if relPath:
108                         fullPath += os.sep+relPath
109                 p[fullPath] = list(
110                         "|".join((oldName, newName))
111                         for (oldName, newName) in files
112                 )
113         for relPath, files in unflatten_files(find_files(".", "src")).iteritems():
114                 fullPath = "/usr/lib/multilist"
115                 if relPath:
116                         fullPath += os.sep+relPath
117                 p[fullPath] = list(
118                         "|".join((oldName, newName))
119                         for (oldName, newName) in files
120                 )
121         p["/usr/share/applications/hildon"] = ["multilist.desktop"]
122         p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-multilist.png|multilist.png"]
123         p["/usr/share/icons/hicolor/40x40/hildon"] = ["40x40-multilist.png|multilist.png"]
124         p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-multilist.png|multilist.png"]
125
126         if distribution == "debian":
127                 print p
128                 print p.generate(
129                         version="%s-%s" % (__version__, __build__),
130                         changelog=__changelog__,
131                         build=True,
132                         tar=False,
133                         changes=False,
134                         dsc=False,
135                 )
136                 print "Building for %s finished" % distribution
137         else:
138                 print p
139                 print p.generate(
140                         version="%s-%s" % (__version__, __build__),
141                         changelog=__changelog__,
142                         build=False,
143                         tar=True,
144                         changes=True,
145                         dsc=True,
146                 )
147                 print "Building for %s finished" % distribution
148
149
150 if __name__ == "__main__":
151         if len(sys.argv) > 1:
152                 try:
153                         import optparse
154                 except ImportError:
155                         optparse = None
156
157                 if optparse is not None:
158                         parser = optparse.OptionParser()
159                         (commandOptions, commandArgs) = parser.parse_args()
160         else:
161                 commandArgs = None
162                 commandArgs = ["diablo"]
163         build_package(commandArgs[0])