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