6830a89d87ede4ef38bf4900212a077a2924c90a
[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 * Cut down on size of media
31 * Attempting to get Maemo 4.1 working
32 * Fixing a couple of issues for launching on Maemo 5
33 """
34
35
36 __postinstall__ = """#!/bin/sh -e
37
38 gtk-update-icon-cache -f /usr/share/icons/hicolor
39 rm -f ~/.%(name)s/%(name)s.log
40 """ % {"name": constants.__app_name__}
41
42 __preremove__ = """#!/bin/sh -e
43 """
44
45
46 def find_files(prefix, path):
47         for root, dirs, files in os.walk(path):
48                 for file in files:
49                         if file.startswith(prefix+"-"):
50                                 fileParts = file.split("-")
51                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
52                                 assert unused == prefix
53                                 relPath = os.sep.join(relPathParts)
54                                 yield relPath, file, newName
55
56
57 def unflatten_files(files):
58         d = {}
59         for relPath, oldName, newName in files:
60                 if relPath not in d:
61                         d[relPath] = []
62                 d[relPath].append((oldName, newName))
63         return d
64
65
66 def build_package(distribution):
67         try:
68                 os.chdir(os.path.dirname(sys.argv[0]))
69         except:
70                 pass
71
72         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
73         p = py2deb.Py2deb(__appname__)
74         p.prettyName = constants.__pretty_app_name__
75         p.description = __description__
76         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Waters%%20of%%20Shiloah"
77         p.author = __author__
78         p.mail = __email__
79         p.license = "lgpl"
80         p.depends = ", ".join([
81                 "python2.6 | python2.5",
82                 "python-gtk2 | python2.5-gtk2",
83                 "python-xml | python2.5-xml",
84                 "python-dbus | python2.5-dbus",
85                 "python-telepathy | python2.5-telepathy",
86         ])
87         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
88         p.depends += {
89                 "debian": ", python-gst0.10",
90                 "diablo": maemoSpecificDepends,
91                 "fremantle": maemoSpecificDepends + ", python-gst0.10",
92         }[distribution]
93         p.recommends = ", ".join([
94         ])
95         p.section = {
96                 "debian": "sound",
97                 "diablo": "user/multimedia",
98                 "fremantle": "user/multimedia",
99         }[distribution]
100         p.arch = "all"
101         p.urgency = "low"
102         p.distribution = "diablo fremantle debian"
103         p.repository = "extras"
104         p.changelog = __changelog__
105         p.postinstall = __postinstall__
106         p.icon = "48x48-WatersOfShiloah.png"
107         p["/opt/WatersOfShiloah/bin"] = ["WatersOfShiloah.py"]
108         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
109                 fullPath = "/opt/WatersOfShiloah/lib"
110                 if relPath:
111                         fullPath += os.sep+relPath
112                 fileLocationTransforms = list(
113                         "|".join((oldName, newName))
114                         for (oldName, newName) in files
115                 )
116                 if not relPath:
117                         fileLocationTransforms.append({
118                                 "debian": "src-stream_gst.py|stream.py",
119                                 "diablo": "src-stream_osso.py|stream.py",
120                                 "fremantle": "src-stream_gst.py|stream.py",
121                         }[distribution])
122                 p[fullPath] = fileLocationTransforms
123         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
124                 fullPath = "/opt/WatersOfShiloah/share"
125                 if relPath:
126                         fullPath += os.sep+relPath
127                 p[fullPath] = list(
128                         "|".join((oldName, newName))
129                         for (oldName, newName) in files
130                 )
131         p["/usr/share/applications/hildon"] = ["WatersOfShiloah.desktop"]
132         p["/usr/share/icons/hicolor/48x48/hildon"] = ["48x48-WatersOfShiloah.png|WatersOfShiloah.png"]
133
134         if distribution == "debian":
135                 print p
136                 print p.generate(
137                         version="%s-%s" % (__version__, __build__),
138                         changelog=__changelog__,
139                         build=True,
140                         tar=False,
141                         changes=False,
142                         dsc=False,
143                 )
144                 print "Building for %s finished" % distribution
145         else:
146                 print p
147                 print p.generate(
148                         version="%s-%s" % (__version__, __build__),
149                         changelog=__changelog__,
150                         build=False,
151                         tar=True,
152                         changes=True,
153                         dsc=True,
154                 )
155                 print "Building for %s finished" % distribution
156
157
158 if __name__ == "__main__":
159         if len(sys.argv) > 1:
160                 try:
161                         import optparse
162                 except ImportError:
163                         optparse = None
164
165                 if optparse is not None:
166                         parser = optparse.OptionParser()
167                         (commandOptions, commandArgs) = parser.parse_args()
168         else:
169                 commandArgs = None
170                 commandArgs = ["diablo"]
171         build_package(commandArgs[0])