~ubuntu-branches/ubuntu/trusty/diffuse/trusty

« back to all changes in this revision

Viewing changes to install.py

  • Committer: Bazaar Package Importer
  • Author(s): Philipp Huebner
  • Date: 2009-07-07 15:11:56 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090707151156-120zntpv8yjdu90z
Tags: 0.3.4-1
* New upstream release
* Removed typofix.dpatch as it is now fixed upstream
* Removed maintainer scripts (not needed anymore)
* Removed Suggests on scrollkeeper (not needed anymore)
* Added minor bugfix from upstream
* Added gettext to Build-Depends-Indep
* Added compilation of diffuse.po to debian/rules
* Updated maintainer's mail address
* Updated Standards-Version: 3.8.2 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import glob
23
23
import os
24
24
import stat
 
25
import subprocess
25
26
import sys
26
27
 
27
28
app_path = sys.argv[0]
39
40
os.umask(stat.S_IWGRP | stat.S_IWOTH)
40
41
 
41
42
# option defaults
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' }
43
49
install = True
44
50
files_only = False
45
51
 
68
74
     directory for installing read-only single-machine data
69
75
     default: %s
70
76
 
71
 
  --python-interpreter=PATH
 
77
  --examplesdir=PATH
 
78
     directory for example configuration files
 
79
     default: %s
 
80
 
 
81
  --mandir=PATH
 
82
     directory for man pages
 
83
     default: %s
 
84
 
 
85
  --pythonbin=PATH
72
86
     command for python interpreter
73
87
     default: %s
74
88
 
75
89
  --files-only
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'])
77
91
    sys.exit(0)
78
92
 
79
93
# returns the list of components used in a path
99
113
        s = v.join(a)
100
114
    return s
101
115
 
 
116
# create directories
 
117
def createDirs(d):
 
118
    p = os.sep
 
119
    for c in components(d):
 
120
        p = os.path.join(p, c)
 
121
        if not os.path.isdir(p):
 
122
            os.mkdir(p)
 
123
 
 
124
# remove a file
 
125
def removeFile(f):
 
126
    try:
 
127
        os.unlink(f)
 
128
    except OSError:
 
129
        logError('Error removing "%s".' % (f, ))
 
130
 
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
107
 
        dstdir = 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):
112
 
                os.mkdir(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)
115
136
            if install:
 
137
                createDirs(os.path.dirname(d))
116
138
                # install file
117
139
                f = open(s, 'rb')
118
140
                c = f.read()
128
150
                    os.chmod(d, 0755)
129
151
            else:
130
152
                # remove file
131
 
                try:
132
 
                    os.unlink(d)
133
 
                except OSError:
134
 
                    logError('Error removing "%s".' % (d, ))
 
153
                removeFile(d)
 
154
 
 
155
# compile .po files and install
 
156
def processTranslations(install, dst):
 
157
    for s in glob.glob('translations/*.po'):
 
158
        lang = s[13:-3]
 
159
        d = os.path.join(dst, 'share/locale/%s/LC_MESSAGES/diffuse.mo' % (lang, ))
 
160
        print 'Installing %s' % (d, )
 
161
        if install:
 
162
            # install file
 
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))
 
166
        else:
 
167
            # remove file
 
168
            removeFile(d)
135
169
 
136
170
# parse command line arguments
137
171
for arg in sys.argv[1:]:
149
183
            logError('Unknown option "%s".' % (arg, ))
150
184
            sys.exit(1)
151
185
 
 
186
# expand variables
 
187
for s in 'sysconfdir', 'examplesdir', 'mandir':
 
188
    for k in 'prefix', 'sysconfdir':
 
189
        if s != k:
 
190
            options[s] = options[s].replace('${%s}' % (k, ), options[k])
 
191
 
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':
154
196
    p = options[opt]
155
197
    c = components(p)
156
198
    if os.pardir in c or os.curdir in c:
163
205
destdir = options['destdir']
164
206
prefix = options['prefix']
165
207
sysconfdir = options['sysconfdir']
166
 
python = options['python-interpreter']
 
208
examplesdir = options['examplesdir']
 
209
mandir = options['mandir']
 
210
pythonbin = options['pythonbin']
167
211
 
168
212
# tell the user what we are about to do
169
213
if install:
174
218
    destdir=%s
175
219
    prefix=%s
176
220
    sysconfdir=%s
177
 
    python-interpreter=%s''' % (stage, destdir, prefix, sysconfdir, python)
 
221
    examplesdir=%s
 
222
    mandir=%s
 
223
    pythonbin=%s''' % (stage, destdir, prefix, sysconfdir, examplesdir, mandir, pythonbin)
178
224
 
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
188
233
    })
189
234
 
 
235
# install manual
 
236
processFiles(install, os.path.join(destdir, mandir[1:]), 'src/usr/share/man/', {
 
237
        'man1/diffuse.1': [ ('/usr/', prefix), ('/etc/', sysconfdir) ]
 
238
    })
 
239
 
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)) ] })
 
242
 
 
243
# install translations
 
244
processTranslations(install, os.path.join(destdir, prefix[1:]))
192
245
 
193
246
if not install:
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:])
197
250
        try:
198
251
            os.rmdir(d)