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