Forcing a max column size on name/unit
[gonvert] / support / builddeb.py
1 #!/usr/bin/python2.5
2
3 import os
4 import sys
5
6 import py2deb
7
8 import constants
9
10
11 __appname__ = constants.__app_name__
12 __description__ = """Unit Conversions
13 A conversion utility that allows conversion between many units like CGS, Ancient, Imperial with many categories like length, mass, numbers, etc. All units converted values shown at once as you type
14 .
15 Homepage: http://www.unihedron.com/projects/gonvert/index.php
16 """
17 __author__ = "Anthony Tekatch"
18 __email__ = "anthony@unihedron.com"
19 __version__ = constants.__version__
20 __build__ = constants.__build__
21 __changelog__ = """
22 * A condensed view of unit conversion for those who so chose
23 * Changed the way windows handle closing
24 """
25
26
27 __postinstall__ = """#!/bin/sh -e
28
29 gtk-update-icon-cache -f /usr/share/icons/hicolor
30 rm -f ~/.gonvert/gonvert.log ~/.gonvert/selections.dat ~/.gonvert/window.dat
31 """
32
33 __preremove__ = """#!/bin/sh -e
34 """
35
36
37 def find_files(prefix, path):
38         for root, dirs, files in os.walk(path):
39                 for file in files:
40                         if file.startswith(prefix+"-"):
41                                 fileParts = file.split("-")
42                                 unused, relPathParts, newName = fileParts[0], fileParts[1:-1], fileParts[-1]
43                                 assert unused == prefix
44                                 relPath = os.sep.join(relPathParts)
45                                 yield relPath, file, newName
46
47
48 def unflatten_files(files):
49         d = {}
50         for relPath, oldName, newName in files:
51                 if relPath not in d:
52                         d[relPath] = []
53                 d[relPath].append((oldName, newName))
54         return d
55
56
57 def build_package(distribution):
58         try:
59                 os.chdir(os.path.dirname(sys.argv[0]))
60         except:
61                 pass
62
63         py2deb.Py2deb.SECTIONS = py2deb.SECTIONS_BY_POLICY[distribution]
64         p = py2deb.Py2deb(__appname__)
65         p.prettyName = constants.__pretty_app_name__
66         p.description = __description__
67         p.bugTracker = "https://bugs.maemo.org/enter_bug.cgi?product=Gonvert"
68         p.author = __author__
69         p.mail = __email__
70         p.license = "gpl"
71         p.depends = ", ".join([
72                 "python2.6 | python2.5",
73                 "python-simplejson",
74         ])
75         p.depends += {
76                 "debian": ", python-qt4",
77                 "diablo": ", python2.5-qt4-core, python2.5-qt4-gui",
78                 "fremantle": ", python2.5-qt4-core, python2.5-qt4-gui, python2.5-qt4-maemo5",
79         }[distribution]
80         p.recommends = ", ".join([
81         ])
82         p.section = {
83                 "debian": "science",
84                 "diablo": "user/science",
85                 "fremantle": "user/science",
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.preremove = __preremove__
94         p.icon = {
95                 "debian": "data-pixmaps-gonvert.png",
96                 "diablo": "data-pixmaps-gonvert.png",
97                 "fremantle": "data-pixmaps-gonvert.png", # Fremantle natively uses 48x48
98         }[distribution]
99         p["/opt/gonvert/bin"] = [ "gonvert.py" ]
100         for relPath, files in unflatten_files(find_files("src", ".")).iteritems():
101                 fullPath = "/opt/gonvert/lib"
102                 if relPath:
103                         fullPath += os.sep+relPath
104                 p[fullPath] = list(
105                         "|".join((oldName, newName))
106                         for (oldName, newName) in files
107                 )
108         for relPath, files in unflatten_files(find_files("data", ".")).iteritems():
109                 fullPath = "/opt/gonvert/share"
110                 if relPath:
111                         fullPath += os.sep+relPath
112                 p[fullPath] = list(
113                         "|".join((oldName, newName))
114                         for (oldName, newName) in files
115                 )
116         p["/usr/share/applications/hildon"] = ["gonvert.desktop"]
117         p["/usr/share/icons/hicolor/26x26/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
118         p["/usr/share/icons/hicolor/64x64/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
119         p["/usr/share/icons/hicolor/scalable/hildon"] = ["data-pixmaps-gonvert.png|gonvert.png"]
120
121         if distribution == "debian":
122                 print p
123                 print p.generate(
124                         version="%s-%s" % (__version__, __build__),
125                         changelog=__changelog__,
126                         build=True,
127                         tar=False,
128                         changes=False,
129                         dsc=False,
130                 )
131                 print "Building for %s finished" % distribution
132         else:
133                 print p
134                 print p.generate(
135                         version="%s-%s" % (__version__, __build__),
136                         changelog=__changelog__,
137                         build=False,
138                         tar=True,
139                         changes=True,
140                         dsc=True,
141                 )
142                 print "Building for %s finished" % distribution
143
144
145 if __name__ == "__main__":
146         if len(sys.argv) > 1:
147                 try:
148                         import optparse
149                 except ImportError:
150                         optparse = None
151
152                 if optparse is not None:
153                         parser = optparse.OptionParser()
154                         (commandOptions, commandArgs) = parser.parse_args()
155         else:
156                 commandArgs = None
157                 commandArgs = ["diablo"]
158         build_package(commandArgs[0])