Switching favorites tocheckboxes to hopefully make it better on 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 * Switching Condensed View's output to be editable also
23 * Fixed scrolling on Maemo
24 * On the traditional view, fixed an issue setting a value on the unit being converted
25 * Increased the name column size in the traditional view
26 * Switching Favorites to checkboxes from selection
27 """.strip()
28
29
30 __postinstall__ = """#!/bin/sh -e
31
32 gtk-update-icon-cache -f /usr/share/icons/hicolor
33 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
34 """
35
36 __preremove__ = """#!/bin/sh -e
37 """
38
39
40 def find_files(prefix, path):
41         for root, dirs, files in os.walk(path):
42                 for file in files:
43                         if file.startswith(prefix+"-"):
44                                 fileParts = file.split("-")
45                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
46                                 assert unused == prefix
47                                 relPath = os.sep.join(relPathParts)
48                                 yield relPath, file, newName
49
50
51 def unflatten_files(files):
52         d = {}
53         for relPath, oldName, newName in files:
54                 if relPath not in d:
55                         d[relPath] = []
56                 d[relPath].append((oldName, newName))
57         return d
58
59
60 def build_package(distribution):
61         try:
62                 os.chdir(os.path.dirname(sys.argv[0]))
63         except:
64                 pass
65
66         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
67         p = py2deb.Py2deb(__appname__)
68         p.prettyName = constants.__pretty_app_name__
69         p.description = __description__
70         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
71         p.author = __author__
72         p.mail = __email__
73         p.license = "gpl"
74         p.depends = ", ".join([
75                 "python2.6 | python2.5",
76                 "python-simplejson",
77         ])
78         p.depends += {
79                 "debian": ", python-qt4",
80                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
81                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
82         }[distribution]
83         p.recommends = ", ".join([
84         ])
85         p.section = {
86                 "debian": "science",
87                 "diablo": "user/science",
88                 "fremantle": "user/science",
89         }[distribution]
90         p.arch = "all"
91         p.urgency = "low"
92         p.distribution = "diablo fremantle debian"
93         p.repository = "extras"
94         p.changelog = __changelog__
95         p.postinstall = __postinstall__
96         p.preremove = __preremove__
97         p.icon = {
98                 "debian": "data-pixmaps-gonvert.png",
99                 "diablo": "data-pixmaps-gonvert.png",
100                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
101         }[distribution]
102         p["/opt/gonvert/bin"] = [ "gonvert.py" ]
103         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
104                 fullPath = "/opt/gonvert/lib"
105                 if relPath:
106                         fullPath += os.sep+relPath
107                 p[fullPath] = list(
108                         "|".join((oldName, newName))
109                         for (oldName, newName) in files
110                 )
111         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
112                 fullPath = "/opt/gonvert/share"
113                 if relPath:
114                         fullPath += os.sep+relPath
115                 p[fullPath] = list(
116                         "|".join((oldName, newName))
117                         for (oldName, newName) in files
118                 )
119         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
120         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
121         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
122         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
123
124         if distribution == "debian":
125                 print p
126                 print p.generate(
127                         version="%s-%s" % (__version__, __build__),
128                         changelog=__changelog__,
129                         build=True,
130                         tar=False,
131                         changes=False,
132                         dsc=False,
133                 )
134                 print "Building for %s finished" % distribution
135         else:
136                 print p
137                 print p.generate(
138                         version="%s-%s" % (__version__, __build__),
139                         changelog=__changelog__,
140                         build=False,
141                         tar=True,
142                         changes=True,
143                         dsc=True,
144                 )
145                 print "Building for %s finished" % distribution
146
147
148 if __name__ == "__main__":
149         if len(sys.argv) > 1:
150                 try:
151                         import optparse
152                 except ImportError:
153                         optparse = None
154
155                 if optparse is not None:
156                         parser = optparse.OptionParser()
157                         (commandOptions, commandArgs) = parser.parse_args()
158         else:
159                 commandArgs = None
160                 commandArgs = ["diablo"]
161         build_package(commandArgs[0])