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