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