Optimizing for Maemo
[gonvert] / support / builddeb.py
1 #!/usr/bin/python2.5
2
3 import os
4 import sys
5
6 import py2deb
7
8 import constants
9
10
11 __appname__ = constants.__app_name__
12 __description__ = """Unit Conversions
13 A conversion utility that allows conversion between many units like CGS, Ancient, Imperial with many categories like length, mass, numbers, etc. All units converted values shown at once as you type
14 .
15 Homepage: http://www.unihedron.com/projects/gonvert/index.php
16 """
17 __author__ = "Anthony Tekatch"
18 __email__ = "anthony@unihedron.com"
19 __version__ = constants.__version__
20 __build__ = constants.__build__
21 __changelog__ = """
22 0.9.3
23 * Rotation support through Ctrl+o
24 * Switching from scrollbar to panning
25 """
26
27
28 __postinstall__ = """#!/bin/sh -e
29
30 gtk-update-icon-cache -f /usr/share/icons/hicolor
31 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
32 """
33
34 __preremove__ = """#!/bin/sh -e
35 """
36
37
38 def find_files(prefix, path):
39         for root, dirs, files in os.walk(path):
40                 for file in files:
41                         if file.startswith(prefix+"-"):
42                                 fileParts = file.split("-")
43                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
44                                 assert unused == prefix
45                                 relPath = os.sep.join(relPathParts)
46                                 yield relPath, file, newName
47
48
49 def unflatten_files(files):
50         d = {}
51         for relPath, oldName, newName in files:
52                 if relPath not in d:
53                         d[relPath] = []
54                 d[relPath].append((oldName, newName))
55         return d
56
57
58 def build_package(distribution):
59         try:
60                 os.chdir(os.path.dirname(sys.argv[0]))
61         except:
62                 pass
63
64         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
65         p = py2deb.Py2deb(__appname__)
66         p.prettyName = constants.__pretty_app_name__
67         p.description = __description__
68         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
69         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
70         p.author = __author__
71         p.mail = __email__
72         p.license = "gpl"
73         p.depends = ", ".join([
74                 "python2.6 | python2.5",
75                 "python-gtk2 | python2.5-gtk2",
76                 "python-xml | python2.5-xml",
77                 "python-dbus | python2.5-dbus",
78         ])
79         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
80         p.depends += {
81                 "debian": ", python-glade2",
82                 "diablo": maemoSpecificDepends,
83                 "fremantle": maemoSpecificDepends + ", python-glade2",
84         }[distribution]
85         p.recommends = ", ".join([
86         ])
87         p.section = {
88                 "debian": "science",
89                 "diablo": "user/science",
90                 "fremantle": "user/science",
91         }[distribution]
92         p.arch = "all"
93         p.urgency = "low"
94         p.distribution = "diablo fremantle debian"
95         p.repository = "extras"
96         p.changelog = __changelog__
97         p.postinstall = __postinstall__
98         p.preremove = __preremove__
99         p.icon = {
100                 "debian": "data-pixmaps-gonvert.png",
101                 "diablo": "data-pixmaps-gonvert.png",
102                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
103         }[distribution]
104         p["/usr/bin"] = [ "gonvert.py" ]
105         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
106                 fullPath = "/usr/lib/gonvert"
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("data", ".")).iteritems():
114                 fullPath = "/usr/share/gonvert"
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"] = ["gonvert.desktop"]
122         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
123         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
124         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.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])