DoInstall.py :  » Build » A-A-P » aap-1.091 » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Build » A A P 
A A P » aap 1.091 » DoInstall.py
# Part of the A-A-P recipe executive: Install a package

# Copyright (C) 2002-2003 Stichting NLnet Labs
# Permission to copy and use this file is specified in the file COPYING.
# If this file is missing you can find it here: http://www.a-a-p.org/COPYING

import os.path

from Util import *
from RecPython import *
from RecPos import RecPos
from Message import *
from CopyMove import remote_copy_move
from DoRead import doread
from DoAddDef import doadddef
from DoBuild import dobuild

def doinstall(pkgname):
    """
    Install package "pkgname".
    Returns zero for success, non-zero for an error.
    """
    return install_pkg([RecPos("install package")], {}, pkgname)


def assert_pkg(rpstack, recdict, pkgname, optional = 0):
    """
    Assert that package "pkgname" is installed.
    Install it when it isn't present.
    """
    # Check if a command with the package name exists.
    while 1:
        if program_path(pkgname):
            return;

        # Can't find it, ask the user what to do.
        if optional:
            opt = "c. Continue anyway\n"
        else:
            opt = ""
        r = raw_input(('Cannot find package "%s"!\n' % pkgname) +
               ("1. Let Aap attempt installing the package\n"
                "2. Retry (install it yourself first)\n"
                "%s"
                "q. Quit\n"
                "Choice: " % opt))
        if not r:
            continue
        if optional and (r[0] == "c" or r[0] == 'C'):
            return;
        if r[0] == "q" or r[0] == 'Q':
            recipe_error(rpstack, _('Package "%s" was not found') % pkgname)
        if r[0] == "1":
            break

    # Install the package.
    install_pkg(rpstack, recdict, pkgname)


def install_pkg(rpstack, recdict, pkgname):
    """
    Install package "pkgname".
    """

    # Decide what directory the package recipes are located in.
    # E.g., for Unix: ~/.aap/packages/pkgname/
    home = home_dir()
    if not home:
        recipe_error(rpstack, _('No $HOME found'))
        return None
    pkgdir = os.path.join(home, "packages", pkgname)

    # Create the directory when needed.
    try:
        assert_dir(rpstack, recdict, pkgdir)
    except StandardError, e:
        recipe_error(rpstack, (_('Cannot create directory "%s": ') % pkgdir)
                                                                      + str(e))
    try:
        # Change directory to where package recipes are located.
        # Remember the current directory, so that we can go back.
        old_cwd = os.getcwd()
        try:
            goto_dir(recdict, pkgdir)
        except StandardError, e:
            recipe_error(rpstack, (_('Cannot change to directory "%s": ')
                                                            % pkgdir) + str(e))

        # Obtain the bootstrap recipe from the A-A-P web server.
        recipe = "boot.aap"
        url = ("http://www.a-a-p.org/package.php?package=%s&osname=%s"
                                                         % (pkgname, osname()))
        failed = remote_copy_move(rpstack, recdict, 1, 
                                    [ {"name" : url } ], {"name" : recipe},
                                    {"force": 1}, 0, errmsg = 1)
        if failed:
            recipe_error(rpstack, _('Cannot obtain package recipe for "%s"')
                                                                     % pkgname)

        # Create a Work object and fill it with the recipe contents.
        work = doread(0, recipe = recipe)
        recdict = work.recdict

        # Note: we don't add the default dependencies (install, clean) here.

        # Execute the recipe.
        if has_target(recdict, "all"):
            # This normally downloads and builds the package.
            dobuild(work, "all")
        if has_target(recdict, "install"):
            # Found an install target, execute it.
            dobuild(work, "install")
        else:
            # No install target, something must have gone wrong.
            msg_error(recdict,
                        _("Package recipe does not contain an install target"))
    finally:
        # Go back to the directory where we started.
        goto_dir(recdict, old_cwd)

    return work


# vim: set sw=4 et sts=4 tw=79 fo+=l:
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.