39
40
os.umask(stat.S_IWGRP | stat.S_IWOTH)
42
options = { 'destdir': '/', 'prefix': '/usr/local/', 'sysconfdir': '/etc/', 'python-interpreter': '/usr/bin/env python' }
43
options = { 'destdir': '/',
44
'prefix': '/usr/local/',
45
'sysconfdir': '/etc/',
46
'examplesdir': '${sysconfdir}',
47
'mandir': '${prefix}/share/man/',
48
'pythonbin': '/usr/bin/env python' }
68
74
directory for installing read-only single-machine data
71
--python-interpreter=PATH
78
directory for example configuration files
82
directory for man pages
72
86
command for python interpreter
76
only install/remove files; skip the post install/removal tasks""" % (app_path, options['destdir'], options['prefix'], options['sysconfdir'], options['python-interpreter'])
90
only install/remove files; skip the post install/removal tasks""" % (app_path, options['destdir'], options['prefix'], options['sysconfdir'], options['examplesdir'], options['mandir'], options['pythonbin'])
79
93
# returns the list of components used in a path
119
for c in components(d):
120
p = os.path.join(p, c)
121
if not os.path.isdir(p):
129
logError('Error removing "%s".' % (f, ))
102
131
# install/remove sets of files
103
def processFiles(install, target, dst, src, template):
132
def processFiles(install, dst, src, template):
104
133
for k, v in template.items():
105
fn, dn = os.path.basename(k), os.path.dirname(k)
106
srcdir, dstdir = os.path.join(src, dn), target
108
for s in components(os.path.join(dst, dn)):
109
dstdir = os.path.join(dstdir, s)
110
# create sub-directories as needed
111
if install and not os.path.isdir(dstdir):
113
for s in glob.glob(os.path.join(srcdir, fn)):
114
d = os.path.join(dstdir, os.path.basename(s))
134
for s in glob.glob(os.path.join(src, k)):
135
d = s.replace(src, dst, 1)
137
createDirs(os.path.dirname(d))
117
139
f = open(s, 'rb')
128
150
os.chmod(d, 0755)
134
logError('Error removing "%s".' % (d, ))
155
# compile .po files and install
156
def processTranslations(install, dst):
157
for s in glob.glob('translations/*.po'):
159
d = os.path.join(dst, 'share/locale/%s/LC_MESSAGES/diffuse.mo' % (lang, ))
160
print 'Installing %s' % (d, )
163
createDirs(os.path.dirname(d))
164
if subprocess.Popen(['msgfmt', '-o', d, s]).wait() != 0:
165
raise OSError('Failed to compile "%s" into "%s".' % (s, d))
136
170
# parse command line arguments
137
171
for arg in sys.argv[1:]:
149
183
logError('Unknown option "%s".' % (arg, ))
187
for s in 'sysconfdir', 'examplesdir', 'mandir':
188
for k in 'prefix', 'sysconfdir':
190
options[s] = options[s].replace('${%s}' % (k, ), options[k])
152
192
# validate inputs
153
for opt in 'prefix', 'sysconfdir':
193
if options['destdir'] == '':
194
options['destdir'] = '/'
195
for opt in 'prefix', 'sysconfdir', 'examplesdir', 'mandir':
155
197
c = components(p)
156
198
if os.pardir in c or os.curdir in c:
177
python-interpreter=%s''' % (stage, destdir, prefix, sysconfdir, python)
223
pythonbin=%s''' % (stage, destdir, prefix, sysconfdir, examplesdir, mandir, pythonbin)
179
225
# install files to prefix
180
processFiles(install, destdir, prefix, 'src/usr', {
181
'bin/diffuse': [ ("'../../etc/diffuserc'", repr(relpath(os.path.join(prefix, 'bin'), os.path.join(sysconfdir, 'diffuserc')))), ('/usr/bin/env python', python) ],
226
processFiles(install, os.path.join(destdir, prefix[1:]), 'src/usr/', {
227
'bin/diffuse': [ ("'../../etc/diffuserc'", repr(relpath(os.path.join(prefix, 'bin'), os.path.join(sysconfdir, 'diffuserc')))), ('/usr/bin/env python', pythonbin) ],
182
228
'share/applications/diffuse.desktop': None,
183
229
'share/diffuse/syntax/*.syntax': None,
184
230
'share/gnome/help/diffuse/C/diffuse.xml': [ ('/usr/', prefix), ('/etc/', sysconfdir) ],
185
'share/man/man1/diffuse.1': [ ('/usr/', prefix), ('/etc/', sysconfdir) ],
186
231
'share/omf/diffuse/diffuse-C.omf': [ ('/usr/', prefix) ],
187
232
'share/pixmaps/diffuse.png': None
236
processFiles(install, os.path.join(destdir, mandir[1:]), 'src/usr/share/man/', {
237
'man1/diffuse.1': [ ('/usr/', prefix), ('/etc/', sysconfdir) ]
190
240
# install files to sysconfdir
191
processFiles(install, destdir, sysconfdir, 'src/etc', { 'diffuserc': [ ('../usr', relpath(sysconfdir, prefix)) ] })
241
processFiles(install, os.path.join(destdir, examplesdir[1:]), 'src/etc/', { 'diffuserc': [ ('/etc/', sysconfdir), ('../usr', relpath(sysconfdir, prefix)) ] })
243
# install translations
244
processTranslations(install, os.path.join(destdir, prefix[1:]))
194
247
# remove directories we own
195
for s in [ 'share/omf/diffuse', 'share/gnome/help/diffuse/C', 'share/gnome/help/diffuse', 'share/diffuse/syntax', 'share/diffuse' ]:
248
for s in 'share/omf/diffuse', 'share/gnome/help/diffuse/C', 'share/gnome/help/diffuse', 'share/diffuse/syntax', 'share/diffuse':
196
249
d = os.path.join(destdir, os.path.join(prefix, s)[1:])