Permalink
Browse files

Interpolate PREFIX at build stage, using prefix from options or install

  • Loading branch information...
ecatmur committed Aug 28, 2011
1 parent 78adde1 commit 06a0133318baeb4fd95321865fd22fdc6c20c5ab
Showing with 26 additions and 25 deletions.
  1. +26 −25 setup.py
View
@@ -11,38 +11,39 @@
from distutils.log import warn, info, error, fatal
from distutils.dep_util import newer
# Get current Python version
python_version = platform.python_version_tuple()
PO_DIR = 'po'
MO_DIR = os.path.join('build', 'mo')
# Setup the default install prefix
prefix = sys.prefix
class BuildData(build):
# Check our python is version 2.6 or higher
if python_version[0] >= 2 and python_version[1] >= 6:
## Set file location prefix accordingly
prefix = '/usr/local'
user_options = [
('prefix=', None, "installation prefix"),
]
# Get the install prefix if one is specified from the command line
for arg in sys.argv:
if arg.startswith('--prefix='):
prefix = arg[9:]
prefix = os.path.expandvars(prefix)
def initialize_options(self):
build.initialize_options(self)
self.prefix = None
# Gen .in files with @PREFIX@ replaced
for filename in ['udev-discover']:
infile = open(filename + '.in', 'r')
data = infile.read().replace('@PREFIX@', prefix)
infile.close()
def finalize_options(self):
build.finalize_options(self)
if not self.prefix:
install = self.distribution.get_command_obj('install', False)
if install:
self.prefix = install.prefix
else:
self.prefix = sys.prefix
outfile = open(filename, 'w')
outfile.write(data)
outfile.close()
def run (self):
# Gen .in files with @PREFIX@ replaced
for filename in ['udev-discover']:
infile = open(filename + '.in', 'r')
data = infile.read().replace('@PREFIX@', self.prefix)
infile.close()
PO_DIR = 'po'
MO_DIR = os.path.join('build', 'mo')
outfile = open(filename, 'w')
outfile.write(data)
outfile.close()
class BuildData(build):
def run (self):
build.run (self)
for po in glob.glob (os.path.join (PO_DIR, '*.po')):

0 comments on commit 06a0133

Please sign in to comment.