# Path: pisi/actionsapi/shelltools.py
# def system(command):
#     command = string.join(string.split(command))
#     retValue = run_logged(command)
# 
#     #if return value is different than 0, it means error, raise exception
#     if retValue != 0:
#         error(_("Command \"%s\" failed, return value was %d.") % (command, retValue))
# 
#     return retValue
# 
# Path: pisi/actionsapi/shelltools.py
# def can_access_file(filePath):
#     '''test the existence of file'''
#     return os.access(filePath, os.F_OK)
# 
# Path: pisi/actionsapi/shelltools.py
# def unlink(pattern):
#     '''remove the file path'''
#     filePathGlob = glob.glob(pattern)
#     if len(filePathGlob) == 0:
#         ctx.ui.error(_("No file matched pattern \"%s\". Remove operation failed.") % pattern)
#         return
# 
#     for filePath in filePathGlob:
#         if isFile(filePath) or isLink(filePath):
#             try:
#                 os.unlink(filePath)
#             except OSError:
#                 ctx.ui.error(_('ActionsAPI [unlink]: Permission denied: %s.') % (filePath))
#         elif isDirectory(filePath):
#             ctx.ui.warning(_('ActionsAPI [unlink]: %s is not a file, use \'unlinkDir\' or \'removeDir\' to remove directories.') % filePath)
#         else:
#             ctx.ui.error(_('ActionsAPI [unlink]: File %s doesn\'t exists.') % (filePath))


import os
import gettext
import pisi.context as ctx
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
from pisi.actionsapi.libtools import gnuconfig_update

def install(parameters = '', argument = 'install'):
    '''install source into install directory with given parameters'''
    args = 'make prefix=%(prefix)s/%(defaultprefix)s \
            datadir=%(prefix)s/%(data)s \
            infodir=%(prefix)s/%(info)s \
            localstatedir=%(prefix)s/%(localstate)s \
            mandir=%(prefix)s/%(man)s \
            sysconfdir=%(prefix)s/%(conf)s \
            %(parameters)s \
            %(argument)s' % {
                                'prefix': get.installDIR(),
                                'defaultprefix': get.defaultprefixDIR(),
                                'man': get.manDIR(),
                                'info': get.infoDIR(),
                                'localstate': get.localstateDIR(),
                                'conf': get.confDIR(),
                                'data': get.dataDIR(),
                                'parameters': parameters,
                                'argument':argument,
                            }

    if system(args):
        raise InstallError(_('Install failed.'))
    else:
        fixInfoDir()


def rawInstall(parameters = '', argument = 'install'):
    '''install source into install directory with given parameters = PREFIX=%s % get.installDIR()'''

# Path: pisi/actionsapi/shelltools.py
# def system(command):
#     command = string.join(string.split(command))
#     retValue = run_logged(command)
# 
#     #if return value is different than 0, it means error, raise exception
#     if retValue != 0:
#         error(_("Command \"%s\" failed, return value was %d.") % (command, retValue))
# 
#     return retValue
# 
# Path: pisi/actionsapi/shelltools.py
# def can_access_file(filePath):
#     '''test the existence of file'''
#     return os.access(filePath, os.F_OK)
# 
# Path: pisi/actionsapi/shelltools.py
# def unlink(pattern):
#     '''remove the file path'''
#     filePathGlob = glob.glob(pattern)
#     if len(filePathGlob) == 0:
#         ctx.ui.error(_("No file matched pattern \"%s\". Remove operation failed.") % pattern)
#         return
# 
#     for filePath in filePathGlob:
#         if isFile(filePath) or isLink(filePath):
#             try:
#                 os.unlink(filePath)
#             except OSError:
#                 ctx.ui.error(_('ActionsAPI [unlink]: Permission denied: %s.') % (filePath))
#         elif isDirectory(filePath):
#             ctx.ui.warning(_('ActionsAPI [unlink]: %s is not a file, use \'unlinkDir\' or \'removeDir\' to remove directories.') % filePath)
#         else:
#             ctx.ui.error(_('ActionsAPI [unlink]: File %s doesn\'t exists.') % (filePath))


# Path: pisi/actionsapi/autotools.py
import os
import gettext
import pisi.context as ctx
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
from pisi.actionsapi.libtools import gnuconfig_update


def install(parameters = '', argument = 'install'):
    '''install source into install directory with given parameters'''
    args = 'make prefix=%(prefix)s/%(defaultprefix)s \
            datadir=%(prefix)s/%(data)s \
            infodir=%(prefix)s/%(info)s \
            localstatedir=%(prefix)s/%(localstate)s \
            mandir=%(prefix)s/%(man)s \
            sysconfdir=%(prefix)s/%(conf)s \
            %(parameters)s \
            %(argument)s' % {
                                'prefix': get.installDIR(),
                                'defaultprefix': get.defaultprefixDIR(),
                                'man': get.manDIR(),
                                'info': get.infoDIR(),
                                'localstate': get.localstateDIR(),
                                'conf': get.confDIR(),
                                'data': get.dataDIR(),
                                'parameters': parameters,
                                'argument':argument,
                            }

    if system(args):
        raise InstallError(_('Install failed.'))
    else:
        fixInfoDir()


def rawInstall(parameters = '', argument = 'install'):
    '''install source into install directory with given parameters = PREFIX=%s % get.installDIR()'''

    if system('make %s %s' % (parameters, argument)):