Minor cleanup
[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 RPN: Stack based math, come on it is fun
17 Pie Menus: Press them or press-drag them
18 History: Its such a drag, so drag them around, delete them, etc
19 .
20 Homepage: http://ejpi.garage.maemo.org/
21 """
22 __author__ = "Ed Page"
23 __email__ = "eopage@byu.net"
24 __version__ = constants.__version__
25 __build__ = constants.__build__
26 __changelog__ = """
27 0.9.6
28 * Fullscreen by Ctrl+Enter
29 * "Enter" in number entry causes a push
30 * Reversed stack order to be more proper
31
32 0.9.4
33  * Added icons
34  * Minor improvements
35  * Swapping the keyboard positions, seem more friendly to my thumb location this way
36
37 0.9.3 - ""
38  * Added +/-, !, sq, and sqrt functions
39  * Improved Documentation
40  * Copy of calculation result and the corresponding equation
41  * Bug fixes
42
43 0.9.2 - ""
44  * Experimenting with faster startup by including pyc files in package
45  * Minor tweaks and bug fixes
46
47 0.9.1 - "Laziness doesn't always pay off"
48  * Profiled the code with an especial focus on the pie menus
49  * Tried to reduce potential bugs with double clicks
50  * Fixed a visual artifact issue on popup
51
52 0.9.0 - "Feed is for horses, so what about feedback?"
53  * Initial public release
54  * Pie menus for keys
55  * Modifiable history
56  * Supports different number types and bases
57  * Basic trig support
58 """
59
60
61 __postinstall__ = """#!/bin/sh -e
62
63 gtk-update-icon-cache -f /usr/share/icons/hicolor
64 """
65
66
67 def find_files(path):
68         for root, dirs, files in os.walk(path):
69                 for file in files:
70                         if file.startswith("src-"):
71                                 fileParts = file.split("-")
72                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
73                                 assert unused == "src"
74                                 relPath = os.sep.join(relPathParts)
75                                 yield relPath, file, newName
76
77
78 def unflatten_files(files):
79         d = {}
80         for relPath, oldName, newName in files:
81                 if relPath not in d:
82                         d[relPath] = []
83                 d[relPath].append((oldName, newName))
84         return d
85
86
87 def build_package(distribution):
88         try:
89                 os.chdir(os.path.dirname(sys.argv[0]))
90         except:
91                 pass
92
93         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
94         p = py2deb.Py2deb(__appname__)
95         p.prettyName = constants.__pretty_app_name__
96         p.description = __description__
97         p.upgradeDescription = __changelog__.split("\n\n", 1)[0]
98         p.author = __author__
99         p.mail = __email__
100         p.license = "lgpl"
101         p.depends = ", ".join([
102                 "python2.6 | python2.5",
103                 "python-gtk2 | python2.5-gtk2",
104                 "python-xml | python2.5-xml",
105         ])
106         maemoSpecificDepends = ", python-osso | python2.5-osso, python-hildon | python2.5-hildon"
107         p.depends += {
108                 "debian": ", python-glade2",
109                 "chinook": maemoSpecificDepends,
110                 "diablo": maemoSpecificDepends,
111                 "fremantle": maemoSpecificDepends + ", python-glade2",
112                 "mer": maemoSpecificDepends + ", python-glade2",
113         }[distribution]
114         p.section = {
115                 "debian": "accessories",
116                 "chinook": "accessories",
117                 "diablo": "user/science",
118                 "fremantle": "user/science",
119                 "mer": "user/science",
120         }[distribution]
121         p.arch = "all"
122         p.urgency = "low"
123         p.distribution = "chinook diablo fremantle mer debian"
124         p.repository = "extras"
125         p.changelog = __changelog__
126         p.postinstall = __postinstall__
127         p.icon = {
128                 "debian": "26x26-ejpi.png",
129                 "chinook": "26x26-ejpi.png",
130                 "diablo": "26x26-ejpi.png",
131                 "fremantle": "64x64-ejpi.png", # Fremantle natively uses 48x48
132                 "mer": "64x64-ejpi.png",
133         }[distribution]
134         p["/usr/bin"] = [ "ejpi.py" ]
135         for relPath, files in unflatten_files(find_files(".")).iteritems():
136                 fullPath = "/usr/lib/ejpi"
137                 if relPath:
138                         fullPath += os.sep+relPath
139                 p[fullPath] = list(
140                         "|".join((oldName, newName))
141                         for (oldName, newName) in files
142                 )
143         p["/usr/share/applications/hildon"] = ["ejpi.desktop"]
144         p["/usr/share/icons/hicolor/26x26/hildon"] = ["26x26-ejpi.png|ejpi.png"]
145         p["/usr/share/icons/hicolor/64x64/hildon"] = ["64x64-ejpi.png|ejpi.png"]
146         p["/usr/share/icons/hicolor/scalable/hildon"] = ["scale-ejpi.png|ejpi.png"]
147
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])