2 # -*- coding: utf-8 -*-
4 import sys, os, fileinput, compileall, re, shutil
7 BINDIR = os.getcwd()+'/usr/bin'
8 DATADIR = os.getcwd()+'/usr/share'
9 DOCDIR = os.getcwd()+'/usr/doc'
11 ###################################################################################
14 return os.path.abspath(sys.path[0])
17 return sourcedir().split('-')[-1]
20 return os.path.join(DATADIR, 'findemall-%s' % version())
23 return os.path.join(DOCDIR, 'findemall-%s' % version())
26 if DATADIR.startswith('/usr'):
27 return os.path.join(DATADIR, 'locale', lang, 'LC_MESSAGES')
29 # if we don't install into /usr or/usr/local, install locales into the
30 # findemall-1.x directory, as in the source tree
31 return os.path.join(datadir(), 'locale', lang, 'LC_MESSAGES')
33 ###################################################################################
35 def compile_modules():
36 compileall.compile_dir(sourcedir(), maxlevels=0, rx=re.compile('findemall.py'))
39 # replace the default shebang line (#!/usr/bin/env python) with
40 # one matching the current python interpreter
41 filename = os.path.join(datadir(), 'findemall.py')
42 for line in fileinput.input(filename, inplace=1):
43 if fileinput.isfirstline():
44 line = '#!%s\n' % sys.executable
45 sys.stdout.write(line)
48 os.system('mkdir -pv %s' % dirname)
50 def install(src, dst):
54 except (OSError, IOError):
55 print ' WARNING: unable to install "%s"' % dst
57 def installdir(src, dst, ext=None):
58 '''Install all files from src into dst; if extension ext is given, only these
59 files are installed.'''
60 files = os.listdir(src)
62 files = [f for f in files if os.path.splitext(f)[1] == ext]
64 install(os.path.join(src, f), os.path.join(dst, f))
66 def install_executable():
68 linkname = os.path.join(BINDIR, 'findemall')
69 filename = os.path.join(datadir(), 'findemall.py')
70 os.chmod(filename, 0755)
71 # remove existing link first
72 os.system('rm -f %s' % linkname)
73 os.system('ln -sv %s %s' % (filename, linkname))
75 def install_modules():
77 installdir(sourcedir(), datadir(), '.py')
78 installdir(sourcedir(), datadir(), '.pyc')
82 installdir(os.path.join(sourcedir(), 'doc'), docdir())
85 for lang in os.listdir(os.path.join(sourcedir(), 'locale')):
86 # file is e.g. "../findemall-1.x/locale/de/LC_MESSAGES/findemall.mo"
87 fname = os.path.join(sourcedir(), 'locale', lang, 'LC_MESSAGES', 'findemall.mo')
88 if os.path.isfile(fname):
89 mofile = os.path.join(localedir(lang), 'findemall.mo')
90 mkdir(localedir(lang))
91 install(fname, mofile)
93 ###################################################################################