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