Merge branch 'master' into qt
[gc-dialer] / 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__ = """Touch screen enhanced interface to the GoogleVoice phone service"
16 Features:
17 .
18 * Dialpad for quick call
19 .
20 * Checking voicemails, texts, call history
21 .
22 * Sending texts
23 .
24 * Notification support for texts, voicemail, and/or missed calls
25 .
26 Homepage: http://gc-dialer.garage.maemo.org/
27 """
28 __author__ = "Ed Page"
29 __email__ = "eopage@byu.net"
30 __version__ = constants.__version__
31 __build__ = constants.__build__
32 __changelog__ = """
33 * Fixed a failed call issue on restart
34 * Trying to improve support for foreign languages
35 * Providing more helpful error on failed call
36 """.strip()
37
38
39 __postinstall__ = """#!/bin/sh -e
40
41 gtk-update-icon-cache -f /usr/share/icons/hicolor
42 rm -f ~/.%(name)s/%(name)s.log
43 rm -f ~/.%(name)s/notifier.log
44 """ % {"name": constants.__app_name__}
45
46 __preremove__ = """#!/bin/sh -e
47
48 python /opt/dialcentral/lib/alarm_handler.py -d || true
49 """
50
51
52 def find_files(prefix, path):
53         for root, dirs, files in os.walk(path):
54                 for file in files:
55                         if file.startswith(prefix+"-"):
56                                 fileParts = file.split("-")
57                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
58                                 assert unused == prefix
59                                 relPath = os.sep.join(relPathParts)
60                                 yield relPath, file, newName
61
62
63 def unflatten_files(files):
64         d = {}
65         for relPath, oldName, newName in files:
66                 if relPath not in d:
67                         d[relPath] = []
68                 d[relPath].append((oldName, newName))
69         return d
70
71
72 def build_package(distribution):
73         try:
74                 os.chdir(os.path.dirname(sys.argv[0]))
75         except:
76                 pass
77
78         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
79         p = py2deb.Py2deb(__appname__)
80         p.prettyName = constants.__pretty_app_name__
81         p.description = __description__
82         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Dialcentral"
83         p.author = __author__
84         p.mail = __email__
85         p.license = "lgpl"
86         p.depends = ", ".join([
87                 "python2.6 | python2.5",
88                 "python-simplejson",
89         ])
90         p.depends += {
91                 "debian": ", python-qt4",
92                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
93                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
94         }[distribution]
95         p.recommends = ", ".join([
96         ])
97         p.section = {
98                 "debian": "comm",
99                 "diablo": "user/network",
100                 "fremantle": "user/network",
101         }[distribution]
102         p.arch = "all"
103         p.urgency = "low"
104         p.distribution = "diablo fremantle debian"
105         p.repository = "extras"
106         p.changelog = __changelog__
107         p.postinstall = __postinstall__
108         p.preremove = __preremove__
109         p.icon = {
110                 "debian": "26x26-dialcentral.png",
111                 "diablo": "26x26-dialcentral.png",
112                 "fremantle": "64x64-dialcentral.png", # Fremantle natively uses 48x48
113         }[distribution]
114         p["/opt/%s/bin" % __appname__] = [ "%s.py" % __appname__ ]
115         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
116                 fullPath = "/opt/%s/lib" % __appname__
117                 if relPath:
118                         fullPath += os.sep+relPath
119                 p[fullPath] = list(
120                         "|".join((oldName, newName))
121                         for (oldName, newName) in files
122                 )
123         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
124                 fullPath = "/opt/%s/share" % __appname__
125                 if relPath:
126                         fullPath += os.sep+relPath
127                 p[fullPath] = list(
128                         "|".join((oldName, newName))
129                         for (oldName, newName) in files
130                 )
131         p["/usr/share/applications/hildon"] = ["dialcentral.desktop"]
132         p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-dialcentral.png|dialcentral.png"]
133         p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-dialcentral.png|dialcentral.png"]
134         p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-dialcentral.png|dialcentral.png"]
135
136         if distribution == "debian":
137                 print p
138                 print p.generate(
139                         version="%s-%s" % (__version__, __build__),
140                         changelog=__changelog__,
141                         build=True,
142                         tar=False,
143                         changes=False,
144                         dsc=False,
145                 )
146                 print "Building for %s finished" % distribution
147         else:
148                 print p
149                 print p.generate(
150                         version="%s-%s" % (__version__, __build__),
151                         changelog=__changelog__,
152                         build=False,
153                         tar=True,
154                         changes=True,
155                         dsc=True,
156                 )
157                 print "Building for %s finished" % distribution
158
159
160 if __name__ == "__main__":
161         if len(sys.argv) > 1:
162                 try:
163                         import optparse
164                 except ImportError:
165                         optparse = None
166
167                 if optparse is not None:
168                         parser = optparse.OptionParser()
169                         (commandOptions, commandArgs) = parser.parse_args()
170         else:
171                 commandArgs = None
172                 commandArgs = ["diablo"]
173         build_package(commandArgs[0])