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