usr/src/cmd/text-install/osol_install/profile/system_info.py
author Alasdair Lumsden <al@everycity.co.uk>
Sun, 21 Aug 2011 19:33:48 +0000
branchoi_151a
changeset 1422 8e22562763cd
parent 874 bf8addecc01d
permissions -rw-r--r--
Branding: Changing default hostname to openindiana in text-install/osol_install/profile/system_info.py
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
773
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     1
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     2
# CDDL HEADER START
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     3
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     4
# The contents of this file are subject to the terms of the
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     5
# Common Development and Distribution License (the "License").
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     6
# You may not use this file except in compliance with the License.
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     7
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     8
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
     9
# or http://www.opensolaris.org/os/licensing.
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    10
# See the License for the specific language governing permissions
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    11
# and limitations under the License.
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    12
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    13
# When distributing Covered Code, include this CDDL HEADER in each
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    14
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    15
# If applicable, add the following below this CDDL HEADER, with the
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    16
# fields enclosed by brackets "[]" replaced with your own identifying
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    17
# information: Portions Copyright [yyyy] [name of copyright owner]
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    18
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    19
# CDDL HEADER END
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    20
#
872
8b098e92c2a9 6971257 Oracle branding for solaris express
Keith Mitchell <keith.mitchell@oracle.com>
parents: 773
diff changeset
    21
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
773
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    22
#
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    23
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    24
'''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    25
Represent Systemwide attributes such as timezone and locale 
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    26
'''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    27
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    28
import locale
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    29
import logging
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    30
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    31
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    32
class SystemInfo(object):
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    33
    '''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    34
    Represents miscellaneous system information
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    35
    '''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    36
    
1422
8e22562763cd Branding: Changing default hostname to openindiana in text-install/osol_install/profile/system_info.py
Alasdair Lumsden <al@everycity.co.uk>
parents: 874
diff changeset
    37
    DEFAULT_HOSTNAME = "openindiana"
773
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    38
    UTC = "UTC"
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    39
    
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    40
    DEFAULT_LOCALE = "C"
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    41
    DEFAULT_ACTUAL_LOCALE = "C/POSIX"
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    42
874
bf8addecc01d 15166 Text Installer EditFields need to support horizontal scrolling
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 872
diff changeset
    43
    # The maximum length of the hostname should ideally come from
bf8addecc01d 15166 Text Installer EditFields need to support horizontal scrolling
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 872
diff changeset
    44
    # a call to os.sysconf('SC_HOST_NAME_MAX') (see similar calls
bf8addecc01d 15166 Text Installer EditFields need to support horizontal scrolling
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 872
diff changeset
    45
    # in user_info.py) but this currently results in a ValueError.
bf8addecc01d 15166 Text Installer EditFields need to support horizontal scrolling
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 872
diff changeset
    46
    MAX_HOSTNAME_LEN = 256
bf8addecc01d 15166 Text Installer EditFields need to support horizontal scrolling
Sue Sohn <Susan.Sohn@Oracle.COM>
parents: 872
diff changeset
    47
773
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    48
    def __init__(self, hostname=None, tz_region=None,
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    49
                 tz_country=None, tz_timezone=None, time_offset=0,
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    50
                 keyboard=None, locale=None, actual_lang=None):
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    51
        if hostname is None:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    52
            hostname = SystemInfo.DEFAULT_HOSTNAME
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    53
        self.hostname = hostname
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    54
        self.tz_region = tz_region
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    55
        self.tz_country = tz_country
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    56
        self.tz_timezone = tz_timezone
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    57
        self.time_offset = time_offset
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    58
        self.keyboard = keyboard
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    59
        self.locale = locale
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    60
        self.actual_lang = actual_lang 
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    61
    
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    62
    def __str__(self):
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    63
        result = ["System Info:"]
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    64
        result.append("\nHostname: ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    65
        result.append(str(self.hostname))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    66
        result.append("\nTZ: ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    67
        result.append(str(self.tz_region))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    68
        result.append(" - ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    69
        result.append(str(self.tz_country))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    70
        result.append(" - ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    71
        result.append(str(self.tz_timezone))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    72
        result.append("\nTime Offset: ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    73
        result.append(str(self.time_offset))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    74
        result.append("\nKeyboard: ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    75
        result.append(str(self.keyboard))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    76
        result.append("\nLocale: ")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    77
        result.append(str(self.locale))
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    78
        return "".join(result)
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    79
    
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    80
    @staticmethod
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    81
    def get_actual_lang(locale):
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    82
        '''Determine the human readable language from the locale
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    83
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    84
        '''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    85
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    86
        try:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    87
            fp = open("/usr/share/gui-install/langs_localized")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    88
        except:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    89
            raise ValueError(
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    90
                "Unable to open /usr/share/gui-install/langs_localized")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    91
        
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    92
        for line in fp:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    93
            key, splitter, val = line.partition(":")
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    94
            if key == locale:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    95
                return (val.rstrip())
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    96
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    97
        raise ValueError("Unsupported language for locale " + locale)
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    98
 
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
    99
    def determine_locale(self):
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   100
        '''Read in the language set during boot.'''
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   101
        # getdefaultlocale() returns a tuple such as ('en_US', 'UTF8')
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   102
        # The second portion of that tuple is not formatted correctly for
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   103
        # processing, so use getpreferredencoding() to get the encoding.
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   104
        language = locale.getdefaultlocale()[0]
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   105
        encoding = locale.getpreferredencoding()
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   106
        
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   107
        if language is None:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   108
            self.locale = SystemInfo.DEFAULT_LOCALE
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   109
            self.actual_lang = SystemInfo.DEFAULT_ACTUAL_LOCALE
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   110
        else:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   111
            if encoding:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   112
                self.locale = ".".join([language, encoding])
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   113
            else:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   114
                self.locale = language
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   115
            try:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   116
                self.actual_lang = self.get_actual_lang(self.locale)
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   117
            except ValueError, err:
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   118
                logging.warn(err)
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   119
                self.actual_lang = self.locale
cc0753f47d02 6367 Provide a text-installer for opensolaris
Keith Mitchell <keith.mitchell@sun.com>
parents:
diff changeset
   120