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