aboutsummaryrefslogtreecommitdiff
path: root/ipsutils/env.py
blob: 0551b3cf7e198fc19decb0b924a308fa81054ea4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# This file is part of ipsutils.

# ipsutils 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 3 of the License, or
# (at your option) any later version.
#
# ipsutils is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with ipsutils.  If not, see <http://www.gnu.org/licenses/>.

import os
import sys
from . import config


class Environment(config.Config):
    def __init__(self, ipsfile):
        """Implements an extended environment from the Config class.
        
        ipsfile = A valid SPEC file
        """
        super(Environment, self).__init__(ipsfile)
        
        # Platform specific ipsbuild directory assignment
        if sys.platform == 'linux2' \
            or sys.platform == 'linux' \
            or sys.platform == 'sunos5':
            self.__basepath = os.path.join(os.environ['HOME'], 'ipsbuild')
            self.home = os.environ['HOME']
        else:
            self.__basepath = os.path.join(os.environ['USERPROFILE'], 'ipsbuild')
            self.home = os.environ['USERPROFILE']

        # Dictionary of top-level directories
        self.env = {
                'IPSBUILD': self.pathgen(''),
                'BUILDROOT': self.pathgen('BUILDROOT'),
                'BUILD': self.pathgen('BUILD'),
                'SPECS': self.pathgen('SPECS'),
                'SOURCES': self.pathgen('SOURCES'),
                'PKGS': self.pathgen('PKGS'),
                'SPKGS': self.pathgen('SPKGS')
                }
        
        # complete_name is required to build proper path names.  
        self.complete_name = self.key_dict['name'] + '-' + self.key_dict['version']
        if self.key_dict['badpath']:
            self.complete_name = self.key_dict['badpath']
        
        # Dictionary of package-level directories
        self.env_pkg = {
                'BUILDROOT': os.path.join(self.env['BUILDROOT'], self.complete_name),
                'BUILDPROTO': os.path.join(self.env['BUILDROOT'], self.complete_name, 'root'),
                'BUILD': os.path.join(self.env['BUILD'], self.complete_name),
                'SOURCES': os.path.join(self.env['SOURCES'], os.path.basename(self.key_dict['source_url'])),
                'PKGS': os.path.join(self.env['PKGS'], self.complete_name),
                'SPKGS': os.path.join(self.env['SPKGS'], self.complete_name)
                }

        self.env_meta = {
                'STAGE1': os.path.join(self.env_pkg['BUILDROOT'], self.complete_name + '.1'),
                'STAGE1_PASS2': os.path.join(self.env_pkg['BUILDROOT'], self.complete_name + '.1p2'),
                'STAGE2': os.path.join(self.env_pkg['BUILDROOT'], self.complete_name + '.2'),
                'STAGE3': os.path.join(self.env_pkg['BUILDROOT'], self.complete_name),
                'STAGE4': os.path.join(self.env_pkg['BUILDROOT'], self.complete_name + '.res')
                }
        # Generic utility mapping for platform specific configuration.
        # Note: This is mainly to test script functionality on different platforms
        #       even though this library is VERY VERY Solaris 11 specific
        self.tool = {
                    'tar': 'tar',
                    'unzip': 'unzip',
                    'gunzip': 'gunzip',
                    'bunzip': 'bunzip',
                    'pkgsend': 'pkgsend',
                    'pkgmogrify': 'pkgmogrify',
                    'pkgdepend': 'pkgdepend',
                    'pkglint': 'pkglint',
                    'pkgfmt': 'pkgfmt'
                    }

        # Oracle Solaris tar is ancient.  GNU tar is preferred.
        if sys.platform == 'sunos5':
            self.tool['tar'] = 'gtar'

    def pathgen(self, path):
        """Simplify path generation based on "ipsbuild" base path
        
        path: directory leaf of 'ipsbuild' directory (in $HOME)
        """
        return os.path.join(self.__basepath, path)