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