233dfd742be70c9045f4b5b5a22f6cc3533c552c
[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 1.0.0
23 * Switched from GTK to QT in preparation for Meego, all previous features still present
24 * Except removed the current form of search
25 * Added a "Recent" window
26 * Added a "Quick Jump" window (to replace old form of search)
27 * Added favorites to limit the number of categories and units shown
28 * Should be auto-rotatable (might not be working for some reason)
29 * Should auto-enable Fn on Maemo 5
30 """
31
32
33 __postinstall__ = """#!/bin/sh -e
34
35 gtk-update-icon-cache -f /usr/share/icons/hicolor
36 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
37 """
38
39 __preremove__ = """#!/bin/sh -e
40 """
41
42
43 def find_files(prefix, path):
44         for root, dirs, files in os.walk(path):
45                 for file in files:
46                         if file.startswith(prefix+"-"):
47                                 fileParts = file.split("-")
48                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
49                                 assert unused == prefix
50                                 relPath = os.sep.join(relPathParts)
51                                 yield relPath, file, newName
52
53
54 def unflatten_files(files):
55         d = {}
56         for relPath, oldName, newName in files:
57                 if relPath not in d:
58                         d[relPath] = []
59                 d[relPath].append((oldName, newName))
60         return d
61
62
63 def build_package(distribution):
64         try:
65                 os.chdir(os.path.dirname(sys.argv[0]))
66         except:
67                 pass
68
69         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
70         p = py2deb.Py2deb(__appname__)
71         p.prettyName = constants.__pretty_app_name__
72         p.description = __description__
73         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
74         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
75         p.author = __author__
76         p.mail = __email__
77         p.license = "gpl"
78         p.depends = ", ".join([
79                 "python2.6 | python2.5",
80                 "python-gtk2 | python2.5-gtk2",
81                 "python-pyqt4 | python2.5-pyqt4",
82         ])
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["/usr/bin"] = [ "gonvert.py" ]
103         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
104                 fullPath = "/usr/lib/gonvert"
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 = "/usr/share/gonvert"
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])