Attempting some optimizations
[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 * Attempting some optimizations
28 """.strip()
29
30
31 __postinstall__ = """#!/bin/sh -e
32
33 gtk-update-icon-cache -f /usr/share/icons/hicolor
34 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
35 """
36
37 __preremove__ = """#!/bin/sh -e
38 """
39
40
41 def find_files(prefix, path):
42         for root, dirs, files in os.walk(path):
43                 for file in files:
44                         if file.startswith(prefix+"-"):
45                                 fileParts = file.split("-")
46                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
47                                 assert unused == prefix
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=Gonvert"
72         p.author = __author__
73         p.mail = __email__
74         p.license = "gpl"
75         p.depends = ", ".join([
76                 "python2.6 | python2.5",
77                 "python-simplejson",
78         ])
79         p.depends += {
80                 "debian": ", python-qt4",
81                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
82                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
83         }[distribution]
84         p.recommends = ", ".join([
85         ])
86         p.section = {
87                 "debian": "science",
88                 "diablo": "user/science",
89                 "fremantle": "user/science",
90         }[distribution]
91         p.arch = "all"
92         p.urgency = "low"
93         p.distribution = "diablo fremantle debian"
94         p.repository = "extras"
95         p.changelog = __changelog__
96         p.postinstall = __postinstall__
97         p.preremove = __preremove__
98         p.icon = {
99                 "debian": "data-pixmaps-gonvert.png",
100                 "diablo": "data-pixmaps-gonvert.png",
101                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
102         }[distribution]
103         p["/opt/gonvert/bin"] = [ "gonvert.py" ]
104         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
105                 fullPath = "/opt/gonvert/lib"
106                 if relPath:
107                         fullPath += os.sep+relPath
108                 p[fullPath] = list(
109                         "|".join((oldName, newName))
110                         for (oldName, newName) in files
111                 )
112         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
113                 fullPath = "/opt/gonvert/share"
114                 if relPath:
115                         fullPath += os.sep+relPath
116                 p[fullPath] = list(
117                         "|".join((oldName, newName))
118                         for (oldName, newName) in files
119                 )
120         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
121         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
122         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
123         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
124
125         if distribution == "debian":
126                 print p
127                 print p.generate(
128                         version="%s-%s" % (__version__, __build__),
129                         changelog=__changelog__,
130                         build=True,
131                         tar=False,
132                         changes=False,
133                         dsc=False,
134                 )
135                 print "Building for %s finished" % distribution
136         else:
137                 print p
138                 print p.generate(
139                         version="%s-%s" % (__version__, __build__),
140                         changelog=__changelog__,
141                         build=False,
142                         tar=True,
143                         changes=True,
144                         dsc=True,
145                 )
146                 print "Building for %s finished" % distribution
147
148
149 if __name__ == "__main__":
150         if len(sys.argv) > 1:
151                 try:
152                         import optparse
153                 except ImportError:
154                         optparse = None
155
156                 if optparse is not None:
157                         parser = optparse.OptionParser()
158                         (commandOptions, commandArgs) = parser.parse_args()
159         else:
160                 commandArgs = None
161                 commandArgs = ["diablo"]
162         build_package(commandArgs[0])