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