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