212d93d4ba64cee021d303a342292427ec3ea279
[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 * Switched from GTK to QT in preparation for Meego, all previous features still present
23 * Except removed the current form of search
24 * Added a "Recent" window
25 * Added a "Quick Jump" window (to replace old form of search)
26 * Added favorites to limit the number of categories and units shown
27 * Should be auto-rotatable (might not be working for some reason)
28 * Should auto-enable Fn on Maemo 5
29 """
30
31
32 __postinstall__ = """#!/bin/sh -e
33
34 gtk-update-icon-cache -f /usr/share/icons/hicolor
35 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
36 """
37
38 __preremove__ = """#!/bin/sh -e
39 """
40
41
42 def find_files(prefix, path):
43         for root, dirs, files in os.walk(path):
44                 for file in files:
45                         if file.startswith(prefix+"-"):
46                                 fileParts = file.split("-")
47                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
48                                 assert unused == prefix
49                                 relPath = os.sep.join(relPathParts)
50                                 yield relPath, file, newName
51
52
53 def unflatten_files(files):
54         d = {}
55         for relPath, oldName, newName in files:
56                 if relPath not in d:
57                         d[relPath] = []
58                 d[relPath].append((oldName, newName))
59         return d
60
61
62 def build_package(distribution):
63         try:
64                 os.chdir(os.path.dirname(sys.argv[0]))
65         except:
66                 pass
67
68         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
69         p = py2deb.Py2deb(__appname__)
70         p.prettyName = constants.__pretty_app_name__
71         p.description = __description__
72         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
73         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
74         p.author = __author__
75         p.mail = __email__
76         p.license = "gpl"
77         p.depends = ", ".join([
78                 "python2.6 | python2.5",
79                 "python-simplejson",
80         ])
81         p.depends += {
82                 "debian": ", python-qt4",
83                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
84                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
85         }[distribution]
86         p.recommends = ", ".join([
87         ])
88         p.section = {
89                 "debian": "science",
90                 "diablo": "user/science",
91                 "fremantle": "user/science",
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.preremove = __preremove__
100         p.icon = {
101                 "debian": "data-pixmaps-gonvert.png",
102                 "diablo": "data-pixmaps-gonvert.png",
103                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
104         }[distribution]
105         p["/usr/bin"] = [ "gonvert.py" ]
106         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
107                 fullPath = "/usr/lib/gonvert"
108                 if relPath:
109                         fullPath += os.sep+relPath
110                 p[fullPath] = list(
111                         "|".join((oldName, newName))
112                         for (oldName, newName) in files
113                 )
114         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
115                 fullPath = "/usr/share/gonvert"
116                 if relPath:
117                         fullPath += os.sep+relPath
118                 p[fullPath] = list(
119                         "|".join((oldName, newName))
120                         for (oldName, newName) in files
121                 )
122         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
123         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
124         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
125         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
126
127         if distribution == "debian":
128                 print p
129                 print p.generate(
130                         version="%s-%s" % (__version__, __build__),
131                         changelog=__changelog__,
132                         build=True,
133                         tar=False,
134                         changes=False,
135                         dsc=False,
136                 )
137                 print "Building for %s finished" % distribution
138         else:
139                 print p
140                 print p.generate(
141                         version="%s-%s" % (__version__, __build__),
142                         changelog=__changelog__,
143                         build=False,
144                         tar=True,
145                         changes=True,
146                         dsc=True,
147                 )
148                 print "Building for %s finished" % distribution
149
150
151 if __name__ == "__main__":
152         if len(sys.argv) > 1:
153                 try:
154                         import optparse
155                 except ImportError:
156                         optparse = None
157
158                 if optparse is not None:
159                         parser = optparse.OptionParser()
160                         (commandOptions, commandArgs) = parser.parse_args()
161         else:
162                 commandArgs = None
163                 commandArgs = ["diablo"]
164         build_package(commandArgs[0])