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