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