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