Fixing up some packaging issues
[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__ = "Ed Page (Maemo Porter)"
18 __email__ = "eopage@byu.net"
19 __version__ = constants.__version__
20 __build__ = constants.__build__
21 __changelog__ = """
22 0.2.24
23 * Added Radioactivity and Radiation dose categories.
24 * Added shortcuts for fullscreen
25 * Switched to Find being brought up by CTRL+F
26 * Added Find Previous and Find Next shortcuts (CTRL+P, CTRL+N)
27 * Debugging: Added logging support
28 * Internal: Massive cleanup of code
29
30 0.2.23  - Added UK currency category and other UK measurements thanks to Dale Hair
31 0.2.22  - Restore previously used window size
32 0.2.21  - Category column widened. Maximize on start.
33 0.2.20  - correction in micron pressure conversion
34 0.2.19  - viscosity cP conversion correction
35 0.2.18  - addition of magnitudes per square arcsecond to Luminance category
36 0.2.17  - updated baud definitions
37         - fixed homepath location because new debian version changed
38 0.2.16  - fixed icon locating for display in about
39         - added alternate icon gonvert-icon_alernative.png (copy over gonvert.png)
40 0.2.15  - updated mainloop to main as discovered by Alexander Skwar
41 0.2.14  - added Calgary energy and volume suggestions per Kim Lux
42 0.2.13  - new more easily understandable icon
43         - nanotesla definition (nT).
44         - added shortlist feature.
45 0.2.12  - removed inoperable books feature.
46         - fixed up acre accuracy.
47 0.2.11  - miodified descriprion for silver, newton, sadzhens.
48 0.2.10  - \x90 changed to \u00C9 for Emile and similar for Reaumur utf-8 text.
49         - Added translation for "All" book text.
50         - The write units text is translatable.
51         - The pl_messages.po file has been updated
52 0.2.09  - Added utf-8 coding to all text strings in preparation for complete language translation.
53 0.2.08  - Added language translation for menus and labels.
54 0.2.07  - Added language translation changes and messages.pot.
55 0.2.06  - Fixed category list size to show preselected categorys on startup,
56           scroll window H&Vpolicy set to always.
57 0.2.05  - Spelling of Luminance category fixed.
58 0.2.04  - Modified unit clicking to force focus on value entry.
59           Modified Makefile to remove /share/share bug for desktop entry.
60 0.2.03  - Modified Makefile to allow better integration on other platforms.
61 0.2.01  - Added saved selections feature, creates ~/.gonvert/ and file. 
62 0.1.11  - fixed packaging for RPM
63 0.1.10  - added Current Loop category for PLCs and 4-20mA instrumentation.
64 0.1.9   - added kilobit, and more density units.
65 0.1.8   - Added Torque units
66 0.1.7   - Added many more pressure units
67         - Added thermal categories
68         - Added fuel consumption category
69         - Program extension to .pyw so that Windows startup without console
70 0.1.6   - add more frequency units
71         - fixed computer number bases nums was bad near "h" and "v"
72         - fixed error:
73           "GtkTextBuffer.insert_at_cursor() takes exactly 1 argument (2 given)"
74           thanks to Riccardo Galli
75 0.1.5   - put packages into /usr instead of /usr/local
76         - add gnome menu item back in
77 0.1.4   - remove dependency on gnome-config from Makefile, RPM, binary.
78 0.1.3   - touched up computer numbers units for better sorting
79         - limited up resizing of windows to prevent dissapearing areas
80         - fixed find bug that some users might notice (TreeViewColumn/None)
81 0.1.2   - Added description box when writing units
82 0.1.1   - Added help/about box
83         - fixed bug that sets focus on line 2480
84         - fixed temperature difference units labels
85         - all scroll bars only show when needed
86         - Added RPM distribution
87 0.1.0   - Major modifications for GTK2 (RedHat 8.0)
88         - addition of units column in display
89         - sorting for all units columns with sort pointer
90 0.0.15  - added Electromagnetic Radiation category
91 0.0.14  - fixed window close bug, attempt to fix libglade XML startup bug for
92           some machines
93 0.0.13  - changes for python2.2, had to remove gnome dependencies
94 0.0.12  - change contact information address
95 0.0.11  - addition of ppm to "find" utility
96 0.0.10  - addition of petabyte to computer data
97 0.0.9   - addition of cesium atom vibrations to Time category
98 0.0.8   - more accurate calculation of degrees F
99 0.0.7   - added 'Find unit' feature
100         - changed Category list to clist for ease of moveto (focus) after find
101 0.0.6   - added description for Amperes
102         - added DENSITY category
103         - added 4 new categories 101 new units
104         - added shoe size converter
105         - add a function to convert custom formulas (like area from diameter)
106           example: area = pi * (D/2)^2
107           base value = pi* (x/2)^2  #metres in diameter metres, cm, inch, foot.
108 0.0.5   - Tool for listing all categories and units to STDOUT.
109         - re-organization of project files.
110         - addition of suffixes between duodecillion and centillion.
111         - addition of Makefile to install onto Gnome based systems.
112         - sort Units or Value columns (ascending or descending)
113           by clicking on column.
114 0.0.4   - Prefixes and Suffixes addition of;
115           ppm, %, Marx brothers, various descriptions.
116         - addition of microgram to mass category.
117         - replaced base 63 with 62 from computer numbers since
118           only 62 characters can be represented.
119         - fixed error if second line has nothing it wouldn't get
120           updated.
121 0.0.3   - fix bug in labelling of base 36 (was base 37)
122           all numbering systems past 23 were at fault due
123           to improper nums string (fixed).
124 0.0.2   - Completion of second row data entry so that changes
125           to text are not cyclicly causing changes to all
126           values.
127 0.0.1   - Initial release.
128 """
129
130
131 __postinstall__ = """#!/bin/sh -e
132
133 gtk-update-icon-cache -f /usr/share/icons/hicolor
134 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
135 """
136
137 __preremove__ = """#!/bin/sh -e
138 """
139
140
141 def find_files(prefix, path):
142         for root, dirs, files in os.walk(path):
143                 for file in files:
144                         if file.startswith(prefix+"-"):
145                                 fileParts = file.split("-")
146                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
147                                 assert unused == prefix
148                                 relPath = os.sep.join(relPathParts)
149                                 yield relPath, file, newName
150
151
152 def unflatten_files(files):
153         d = {}
154         for relPath, oldName, newName in files:
155                 if relPath not in d:
156                         d[relPath] = []
157                 d[relPath].append((oldName, newName))
158         return d
159
160
161 def build_package(distribution):
162         try:
163                 os.chdir(os.path.dirname(sys.argv[0]))
164         except:
165                 pass
166
167         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
168         p = py2deb.Py2deb(__appname__)
169         p.prettyName = constants.__pretty_app_name__
170         p.description = __description__
171         p.bugTracker = ""
172         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
173         p.author = __author__
174         p.mail = __email__
175         p.license = "lgpl"
176         p.depends = ", ".join([
177                 "python2.6 | python2.5",
178                 "python-gtk2 | python2.5-gtk2",
179                 "python-xml | python2.5-xml",
180                 "python-dbus | python2.5-dbus",
181         ])
182         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
183         p.depends += {
184                 "debian": ", python-glade2",
185                 "chinook": maemoSpecificDepends,
186                 "diablo": maemoSpecificDepends,
187                 "fremantle": maemoSpecificDepends + ", python-glade2",
188                 "mer": maemoSpecificDepends + ", python-glade2",
189         }[distribution]
190         p.recommends = ", ".join([
191         ])
192         p.section = {
193                 "debian": "science",
194                 "chinook": "other",
195                 "diablo": "user/science",
196                 "fremantle": "user/science",
197                 "mer": "user/science",
198         }[distribution]
199         p.arch = "all"
200         p.urgency = "low"
201         p.distribution = "chinook diablo fremantle mer debian"
202         p.repository = "extras"
203         p.changelog = __changelog__
204         p.postinstall = __postinstall__
205         p.preremove = __preremove__
206         p.icon = {
207                 "debian": "data-pixmaps-gonvert.png",
208                 "chinook": "data-pixmaps-gonvert.png",
209                 "diablo": "data-pixmaps-gonvert.png",
210                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
211                 "mer": "data-pixmaps-gonvert.png",
212         }[distribution]
213         p["/usr/bin"] = [ "gonvert.py" ]
214         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
215                 fullPath = "/usr/lib/gonvert"
216                 if relPath:
217                         fullPath += os.sep+relPath
218                 p[fullPath] = list(
219                         "|".join((oldName, newName))
220                         for (oldName, newName) in files
221                 )
222         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
223                 fullPath = "/usr/share/gonvert"
224                 if relPath:
225                         fullPath += os.sep+relPath
226                 p[fullPath] = list(
227                         "|".join((oldName, newName))
228                         for (oldName, newName) in files
229                 )
230         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
231         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
232         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
233         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
234
235         print p
236         print p.generate(
237                 version="%s-%s" % (__version__, __build__),
238                 changelog=__changelog__,
239                 build=False,
240                 tar=True,
241                 changes=True,
242                 dsc=True,
243         )
244         print "Building for %s finished" % distribution
245
246
247 if __name__ == "__main__":
248         if len(sys.argv) > 1:
249                 try:
250                         import optparse
251                 except ImportError:
252                         optparse = None
253
254                 if optparse is not None:
255                         parser = optparse.OptionParser()
256                         (commandOptions, commandArgs) = parser.parse_args()
257         else:
258                 commandArgs = None
259                 commandArgs = ["diablo"]
260         build_package(commandArgs[0])