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