Bump to 1.0.5
[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 * Fixing error display in landscape
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         ])
81         p.depends += {
82                 "debian": ", python-qt4",
83                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
84                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
85         }[distribution]
86         p.section = {
87                 "debian": "math",
88                 "diablo": "user/science",
89                 "fremantle": "user/science",
90         }[distribution]
91         p.arch = "all"
92         p.urgency = "low"
93         p.distribution = "diablo fremantle debian"
94         p.repository = "extras"
95         p.changelog = __changelog__
96         p.postinstall = __postinstall__
97         p.icon = {
98                 "debian": "26x26-ejpi.png",
99                 "diablo": "26x26-ejpi.png",
100                 "fremantle": "64x64-ejpi.png", # Fremantle natively uses 48x48
101         }[distribution]
102         p["/opt/%s/bin" % __appname__] = [ "%s.py" % __appname__ ]
103         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
104                 fullPath = "/opt/%s/lib" % __appname__
105                 if relPath:
106                         fullPath += os.sep+relPath
107                 p[fullPath] = list(
108                         "|".join((oldName, newName))
109                         for (oldName, newName) in files
110                 )
111         p["/usr/share/applications/hildon"] = ["%s.desktop" % __appname__]
112         p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-ejpi.png|ejpi.png"]
113         p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-ejpi.png|ejpi.png"]
114         p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-ejpi.png|ejpi.png"]
115
116         if distribution == "debian":
117                 print p
118                 print p.generate(
119                         version="%s-%s" % (__version__, __build__),
120                         changelog=__changelog__,
121                         build=True,
122                         tar=False,
123                         changes=False,
124                         dsc=False,
125                 )
126                 print "Building for %s finished" % distribution
127         else:
128                 print p
129                 print p.generate(
130                         version="%s-%s" % (__version__, __build__),
131                         changelog=__changelog__,
132                         build=False,
133                         tar=True,
134                         changes=True,
135                         dsc=True,
136                 )
137                 print "Building for %s finished" % distribution
138
139
140 if __name__ == "__main__":
141         if len(sys.argv) > 1:
142                 try:
143                         import optparse
144                 except ImportError:
145                         optparse = None
146
147                 if optparse is not None:
148                         parser = optparse.OptionParser()
149                         (commandOptions, commandArgs) = parser.parse_args()
150         else:
151                 commandArgs = None
152                 commandArgs = ["diablo"]
153         build_package(commandArgs[0])