rendered paste body# -*- coding: utf-8 -*-
#
# Copyright (C) 2009, TUBITAK/UEKAE
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# Please read the COPYING file.
# Standard Python Modules
import os
import gettext
__trans = gettext.translation('pisi', fallback=True)
_ = __trans.ugettext
# Pisi Modules
import pisi.context as ctx
# ActionsAPI Modules
import pisi.actionsapi
import pisi.actionsapi.get as get
from pisi.actionsapi.shelltools import system
from pisi.actionsapi.shelltools import can_access_file
from pisi.actionsapi.shelltools import unlink
class ConfigureError(pisi.actionsapi.Error):
def __init__(self, value=''):
pisi.actionsapi.Error.__init__(self, value)
self.value = value
ctx.ui.error(value)
class MakeError(pisi.actionsapi.Error):
def __init__(self, value=''):
pisi.actionsapi.Error.__init__(self, value)
self.value = value
ctx.ui.error(value)
class InstallError(pisi.actionsapi.Error):
def __init__(self, value=''):
pisi.actionsapi.Error.__init__(self, value)
self.value = value
ctx.ui.error(value)
class RunTimeError(pisi.actionsapi.Error):
def __init__(self, value=''):
pisi.actionsapi.Error.__init__(self, value)
self.value = value
ctx.ui.error(value)
def getWafCmd():
if can_access_file('waf'):
return 'python waf'
else
return 'waf'
def configure(parameters = ''):
'''configure source with given parameters = "--enable-something-useful etc."'''
if can_access_file('wscript'):
args = '%s \
--prefix=/%s \
--blddir=%s \
--datadir=/%s \
--sysconfdir=/%s \
--localstatedir=/%s \
--libexecdir=/%s \
%s configure' % (getWafCmd(), get.defaultprefixDIR(), get.HOST(), \
get.dataDIR(), get.confDIR(), get.localstateDIR(), get.libexecDIR(), \
parameters)
if system(args):
raise ConfigureError(_('Configure failed.'))
else:
raise ConfigureError(_('No wscript found.'))
def rawConfigure(parameters = ''):
'''configure source with given parameters = "--prefix=... --enable-foobar etc."'''
if can_access_file('wscript'):
if system('%s %s configure' % (getWafCmd(), parameters)):
raise ConfigureError(_('Configure failed.'))
else:
raise ConfigureError(_('No wscript found.'))
def build(parameters = 'all'):
'''build source with given parameters = "all" || "doc,bin" || etc.'''
if can_access_file('wscript'):
if system('%s --targets=%s build' % (getWafCmd(), parameters)):
raise MakeError(_('Build failed.'))
else:
raise ConfigureError(_('No wscript found.'))
def fixInfoDir():
infoDir = '%s/usr/share/info/dir' % get.installDIR()
if can_access_file(infoDir):
unlink(infoDir)
def install(parameters = ''):
'''install files into install directory with given parameters'''
if can_access_file('wscript'):
args = '%(wafcmd)s --prefix=%(prefix)s/%(defaultprefix)s \
--datadir=%(prefix)s/%(data)s \
--localstatedir=%(prefix)s/%(localstate)s \
--sysconfdir=%(prefix)s/%(conf)s \
%(parameters)s install' % { \
'wafcmd':getWafCmd(),
'prefix': get.installDIR(),
'defaultprefix': get.defaultprefixDIR(),
'data': get.dataDIR(),
'localstate': get.localstateDIR(),
'conf': get.confDIR(),
'parameters': parameters}
if system(args):
raise InstallError(_('Install failed.'))
else:
fixInfoDir()
else:
raise InstallError(_('No wscript found.'))
def rawInstall(parameters = ''):
'''install files into install directory with given parameters'''
if can_access_file('wscript'):
if system('%s %s install' % (getWafCmd(), parameters)):
raise InstallError(_('Install failed.'))
else:
fixInfoDir()
else:
raise InstallError(_('No wscript found.'))
def clean(parameters = ''):
'''remove the build files'''
if can_access_file('wscript'):
if system('%s %s clean' % (getWafCmd(), parameters)):
raise RunTimeError(_('Clean failed.'))
else:
raise InstallError(_('No wscript found.'))