Bump to 1.0.0
[ejpi] / 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__ = """A Touch Screen Optimized RPN Calculator using Pie Menus
16 .
17 RPN: Stack based math, come on it is fun
18 .
19 Pie Menus: Press them or press-drag them
20 .
21 History: Its such a drag, so drag them around, delete them, etc
22 .
23 Homepage: http://ejpi.garage.maemo.org/
24 """
25 __author__ = "Ed Page"
26 __email__ = "eopage@byu.net"
27 __version__ = constants.__version__
28 __build__ = constants.__build__
29 __changelog__ = """
30 * Port to Qt wtih misc fixes
31 """.strip()
32
33
34 __postinstall__ = """#!/bin/sh -e
35
36 gtk-update-icon-cache -f /usr/share/icons/hicolor
37 rm -f ~/.%(name)s/%(name)s.log
38 """ % {"name": constants.__app_name__}
39
40 __preremove__ = """#!/bin/sh -e
41 """
42
43
44 def find_files(prefix, path):
45         for root, dirs, files in os.walk(path):
46                 for file in files:
47                         if file.startswith(prefix+"-"):
48                                 fileParts = file.split("-")
49                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
50                                 assert unused == prefix
51                                 relPath = os.sep.join(relPathParts)
52                                 yield relPath, file, newName
53
54
55 def unflatten_files(files):
56         d = {}
57         for relPath, oldName, newName in files:
58                 if relPath not in d:
59                         d[relPath] = []
60                 d[relPath].append((oldName, newName))
61         return d
62
63
64 def build_package(distribution):
65         try:
66                 os.chdir(os.path.dirname(sys.argv[0]))
67         except:
68                 pass
69
70         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
71         p = py2deb.Py2deb(__appname__)
72         p.prettyName = constants.__pretty_app_name__
73         p.description = __description__
74         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=ejpi"
75         p.author = __author__
76         p.mail = __email__
77         p.license = "lgpl"
78         p.depends = ", ".join([
79                 "python2.6 | python2.5",
80                 "python-gtk2 | python2.5-gtk2",
81                 "python-xml | python2.5-xml",
82                 "python-dbus | python2.5-dbus",
83         ])
84         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
85         p.depends += {
86                 "debian": ", python-glade2",
87                 "diablo": maemoSpecificDepends,
88                 "fremantle": maemoSpecificDepends + ", python-glade2",
89         }[distribution]
90         p.section = {
91                 "debian": "math",
92                 "diablo": "user/science",
93                 "fremantle": "user/science",
94         }[distribution]
95         p.arch = "all"
96         p.urgency = "low"
97         p.distribution = "diablo fremantle debian"
98         p.repository = "extras"
99         p.changelog = __changelog__
100         p.postinstall = __postinstall__
101         p.icon = {
102                 "debian": "26x26-ejpi.png",
103                 "diablo": "26x26-ejpi.png",
104                 "fremantle": "64x64-ejpi.png", # Fremantle natively uses 48x48
105         }[distribution]
106         p["/opt/%s/bin" % __appname__] = [ "%s.py" % __appname__ ]
107         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
108                 fullPath = "/opt/%s/lib" % __appname__
109                 if relPath:
110                         fullPath += os.sep+relPath
111                 p[fullPath] = list(
112                         "|".join((oldName, newName))
113                         for (oldName, newName) in files
114                 )
115         p["/usr/share/applications/hildon"] = ["%s.desktop" % __appname__]
116         p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-ejpi.png|ejpi.png"]
117         p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-ejpi.png|ejpi.png"]
118         p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-ejpi.png|ejpi.png"]
119
120         if distribution == "debian":
121                 print p
122                 print p.generate(
123                         version="%s-%s" % (__version__, __build__),
124                         changelog=__changelog__,
125                         build=True,
126                         tar=False,
127                         changes=False,
128                         dsc=False,
129                 )
130                 print "Building for %s finished" % distribution
131         else:
132                 print p
133                 print p.generate(
134                         version="%s-%s" % (__version__, __build__),
135                         changelog=__changelog__,
136                         build=False,
137                         tar=True,
138                         changes=True,
139                         dsc=True,
140                 )
141                 print "Building for %s finished" % distribution
142
143
144 if __name__ == "__main__":
145         if len(sys.argv) > 1:
146                 try:
147                         import optparse
148                 except ImportError:
149                         optparse = None
150
151                 if optparse is not None:
152                         parser = optparse.OptionParser()
153                         (commandOptions, commandArgs) = parser.parse_args()
154         else:
155                 commandArgs = None
156                 commandArgs = ["diablo"]
157         build_package(commandArgs[0])