Renaming the deb and adding a webpage
[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 Initial release
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-gst0.10 | python2.5-gst0.10",
84         ])
85         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
86         p.depends += {
87                 "debian": "",
88                 "diablo": maemoSpecificDepends,
89                 "fremantle": maemoSpecificDepends,
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                 p[fullPath] = list(
111                         "|".join((oldName, newName))
112                         for (oldName, newName) in files
113                 )
114         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
115                 fullPath = "/opt/WatersOfShiloah/share"
116                 if relPath:
117                         fullPath += os.sep+relPath
118                 p[fullPath] = list(
119                         "|".join((oldName, newName))
120                         for (oldName, newName) in files
121                 )
122         p["/usr/share/applications/hildon"] = ["WatersOfShiloah.desktop"]
123         p["/usr/share/icons/hicolor/48x48/hildon"] = ["48x48-WatersOfShiloah.png|WatersOfShiloah.png"]
124
125         if distribution == "debian":
126                 print p
127                 print p.generate(
128                         version="%s-%s" % (__version__, __build__),
129                         changelog=__changelog__,
130                         build=True,
131                         tar=False,
132                         changes=False,
133                         dsc=False,
134                 )
135                 print "Building for %s finished" % distribution
136         else:
137                 print p
138                 print p.generate(
139                         version="%s-%s" % (__version__, __build__),
140                         changelog=__changelog__,
141                         build=False,
142                         tar=True,
143                         changes=True,
144                         dsc=True,
145                 )
146                 print "Building for %s finished" % distribution
147
148
149 if __name__ == "__main__":
150         if len(sys.argv) > 1:
151                 try:
152                         import optparse
153                 except ImportError:
154                         optparse = None
155
156                 if optparse is not None:
157                         parser = optparse.OptionParser()
158                         (commandOptions, commandArgs) = parser.parse_args()
159         else:
160                 commandArgs = None
161                 commandArgs = ["diablo"]
162         build_package(commandArgs[0])