Updating changelist
[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 * A condensed view of unit conversion for those who so chose
23 * Changed the way windows handle closing
24 * Improved performance of jumping between some of the windows (including startup)
25 """
26
27
28 __postinstall__ = """#!/bin/sh -e
29
30 gtk-update-icon-cache -f /usr/share/icons/hicolor
31 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
32 """
33
34 __preremove__ = """#!/bin/sh -e
35 """
36
37
38 def find_files(prefix, path):
39         for root, dirs, files in os.walk(path):
40                 for file in files:
41                         if file.startswith(prefix+"-"):
42                                 fileParts = file.split("-")
43                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
44                                 assert unused == prefix
45                                 relPath = os.sep.join(relPathParts)
46                                 yield relPath, file, newName
47
48
49 def unflatten_files(files):
50         d = {}
51         for relPath, oldName, newName in files:
52                 if relPath not in d:
53                         d[relPath] = []
54                 d[relPath].append((oldName, newName))
55         return d
56
57
58 def build_package(distribution):
59         try:
60                 os.chdir(os.path.dirname(sys.argv[0]))
61         except:
62                 pass
63
64         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
65         p = py2deb.Py2deb(__appname__)
66         p.prettyName = constants.__pretty_app_name__
67         p.description = __description__
68         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
69         p.author = __author__
70         p.mail = __email__
71         p.license = "gpl"
72         p.depends = ", ".join([
73                 "python2.6 | python2.5",
74                 "python-simplejson",
75         ])
76         p.depends += {
77                 "debian": ", python-qt4",
78                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
79                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
80         }[distribution]
81         p.recommends = ", ".join([
82         ])
83         p.section = {
84                 "debian": "science",
85                 "diablo": "user/science",
86                 "fremantle": "user/science",
87         }[distribution]
88         p.arch = "all"
89         p.urgency = "low"
90         p.distribution = "diablo fremantle debian"
91         p.repository = "extras"
92         p.changelog = __changelog__
93         p.postinstall = __postinstall__
94         p.preremove = __preremove__
95         p.icon = {
96                 "debian": "data-pixmaps-gonvert.png",
97                 "diablo": "data-pixmaps-gonvert.png",
98                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
99         }[distribution]
100         p["/opt/gonvert/bin"] = [ "gonvert.py" ]
101         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
102                 fullPath = "/opt/gonvert/lib"
103                 if relPath:
104                         fullPath += os.sep+relPath
105                 p[fullPath] = list(
106                         "|".join((oldName, newName))
107                         for (oldName, newName) in files
108                 )
109         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
110                 fullPath = "/opt/gonvert/share"
111                 if relPath:
112                         fullPath += os.sep+relPath
113                 p[fullPath] = list(
114                         "|".join((oldName, newName))
115                         for (oldName, newName) in files
116                 )
117         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
118         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
119         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
120         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
121
122         if distribution == "debian":
123                 print p
124                 print p.generate(
125                         version="%s-%s" % (__version__, __build__),
126                         changelog=__changelog__,
127                         build=True,
128                         tar=False,
129                         changes=False,
130                         dsc=False,
131                 )
132                 print "Building for %s finished" % distribution
133         else:
134                 print p
135                 print p.generate(
136                         version="%s-%s" % (__version__, __build__),
137                         changelog=__changelog__,
138                         build=False,
139                         tar=True,
140                         changes=True,
141                         dsc=True,
142                 )
143                 print "Building for %s finished" % distribution
144
145
146 if __name__ == "__main__":
147         if len(sys.argv) > 1:
148                 try:
149                         import optparse
150                 except ImportError:
151                         optparse = None
152
153                 if optparse is not None:
154                         parser = optparse.OptionParser()
155                         (commandOptions, commandArgs) = parser.parse_args()
156         else:
157                 commandArgs = None
158                 commandArgs = ["diablo"]
159         build_package(commandArgs[0])