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