Fixing a Maemo 5 issue
[watersofshiloah] / support / builddeb.py
1 #!/usr/bin/python2.5
2
3 import os
4 import sys
5
6 try:
7         import py2deb
8 except ImportError:
9         import fake_py2deb as py2deb
10
11 import constants
12
13
14 __appname__ = constants.__app_name__
15 __description__ = """Media player for inspirational streaming radio and audiobooks including the KJV Bible
16 Supports streaming:
17 * "Mormon Channel" inspirational radio station
18 * Conference precedings and magazines from The Church of Jesus Christ of Latter-day Saints
19 * Scriptures, including King James Version of the Bible and the Book of Mormon
20 .
21 This application is not endorsed by The Church of Jesus Christ of Latter-day Saints
22 .
23 Homepage: http://watersofshiloah.garage.maemo.org
24 """
25 __author__ = "Ed Page"
26 __email__ = "eopage@byu.net"
27 __version__ = constants.__version__
28 __build__ = constants.__build__
29 __changelog__ = """
30 * Fixing a Maemo 5 issue introduced in 1.0.3
31 """
32
33
34 __postinstall__ = """#!/bin/sh -e
35
36 gtk-update-icon-cache -f /usr/share/icons/hicolor
37 rm -f ~/.%(name)s/%(name)s.log
38 """ % {"name": constants.__app_name__}
39
40 __preremove__ = """#!/bin/sh -e
41 """
42
43
44 def find_files(prefix, path):
45         for root, dirs, files in os.walk(path):
46                 for file in files:
47                         if file.startswith(prefix+"-"):
48                                 fileParts = file.split("-")
49                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
50                                 assert unused == prefix
51                                 relPath = os.sep.join(relPathParts)
52                                 yield relPath, file, newName
53
54
55 def unflatten_files(files):
56         d = {}
57         for relPath, oldName, newName in files:
58                 if relPath not in d:
59                         d[relPath] = []
60                 d[relPath].append((oldName, newName))
61         return d
62
63
64 def build_package(distribution):
65         try:
66                 os.chdir(os.path.dirname(sys.argv[0]))
67         except:
68                 pass
69
70         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
71         p = py2deb.Py2deb(__appname__)
72         p.prettyName = constants.__pretty_app_name__
73         p.description = __description__
74         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Waters%%20of%%20Shiloah"
75         p.author = __author__
76         p.mail = __email__
77         p.license = "lgpl"
78         p.depends = ", ".join([
79                 "python2.6 | python2.5",
80                 "python-gtk2 | python2.5-gtk2",
81                 "python-xml | python2.5-xml",
82                 "python-dbus | python2.5-dbus",
83                 "python-telepathy | python2.5-telepathy",
84         ])
85         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
86         p.depends += {
87                 "debian": ", python-gst0.10",
88                 "diablo": maemoSpecificDepends,
89                 "fremantle": maemoSpecificDepends + ", python-gst0.10",
90         }[distribution]
91         p.recommends = ", ".join([
92         ])
93         p.section = {
94                 "debian": "sound",
95                 "diablo": "user/multimedia",
96                 "fremantle": "user/multimedia",
97         }[distribution]
98         p.arch = "all"
99         p.urgency = "low"
100         p.distribution = "diablo fremantle debian"
101         p.repository = "extras"
102         p.changelog = __changelog__
103         p.postinstall = __postinstall__
104         p.icon = "48x48-WatersOfShiloah.png"
105         p["/opt/WatersOfShiloah/bin"] = ["WatersOfShiloah.py"]
106         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
107                 fullPath = "/opt/WatersOfShiloah/lib"
108                 if relPath:
109                         fullPath += os.sep+relPath
110                 fileLocationTransforms = list(
111                         "|".join((oldName, newName))
112                         for (oldName, newName) in files
113                 )
114                 if not relPath:
115                         fileLocationTransforms.append({
116                                 "debian": "src-stream_gst.py|stream.py",
117                                 "diablo": "src-stream_osso.py|stream.py",
118                                 "fremantle": "src-stream_gst.py|stream.py",
119                         }[distribution])
120                 p[fullPath] = fileLocationTransforms
121         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
122                 fullPath = "/opt/WatersOfShiloah/share"
123                 if relPath:
124                         fullPath += os.sep+relPath
125                 p[fullPath] = list(
126                         "|".join((oldName, newName))
127                         for (oldName, newName) in files
128                 )
129         p["/usr/share/applications/hildon"] = ["WatersOfShiloah.desktop"]
130         p["/usr/share/icons/hicolor/48x48/hildon"] = ["48x48-WatersOfShiloah.png|WatersOfShiloah.png"]
131
132         if distribution == "debian":
133                 print p
134                 print p.generate(
135                         version="%s-%s" % (__version__, __build__),
136                         changelog=__changelog__,
137                         build=True,
138                         tar=False,
139                         changes=False,
140                         dsc=False,
141                 )
142                 print "Building for %s finished" % distribution
143         else:
144                 print p
145                 print p.generate(
146                         version="%s-%s" % (__version__, __build__),
147                         changelog=__changelog__,
148                         build=False,
149                         tar=True,
150                         changes=True,
151                         dsc=True,
152                 )
153                 print "Building for %s finished" % distribution
154
155
156 if __name__ == "__main__":
157         if len(sys.argv) > 1:
158                 try:
159                         import optparse
160                 except ImportError:
161                         optparse = None
162
163                 if optparse is not None:
164                         parser = optparse.OptionParser()
165                         (commandOptions, commandArgs) = parser.parse_args()
166         else:
167                 commandArgs = None
168                 commandArgs = ["diablo"]
169         build_package(commandArgs[0])