f607ab0b984a5f1dd7e17ee571bfb637694ae3d2
[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         ])
80         p.depends += {
81                 "debian": ", python-qt4",
82                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
83                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
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])