Skip to content

Commit

Permalink
Merge pull request #2 from ecatmur/master
Browse files Browse the repository at this point in the history
[m][install] Interpolate PREFIX at build stage, using prefix from options or install
  • Loading branch information
fontanon committed Aug 28, 2011
2 parents 78adde1 + ddd2de6 commit 097d233
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')):
Expand Down Expand Up @@ -127,5 +128,6 @@ def _find_mo_files (self):
('share/icons/hicolor/24x24/devices', glob.glob('data/icons/24x24/devices/*')),
('share/icons/hicolor/48x48/devices', glob.glob('data/icons/48x48/devices/*')),
('share/icons/hicolor/scalable/devices', glob.glob('data/icons/scalable/devices/*')),
('share/icons/hicolor/scalable/apps', ['data/udev-discover.svg']),
],
)

0 comments on commit 097d233

Please sign in to comment.