author | Ginnie Wray<virginia.wray@oracle.com> |
Tue, 19 Jun 2012 12:18:37 -0600 | |
changeset 1717 | 10cb4d15a248 |
parent 1666 | e9d4b6b42777 |
child 1718 | 4cec97c628bb |
permissions | -rw-r--r-- |
947
29603af1b942
6999599 Missing shebang lines in python modules leads to incorrect dependency generation
Keith Mitchell <keith.mitchell@oracle.com>
parents:
902
diff
changeset
|
1 |
#!/usr/bin/python |
902
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
2 |
# CDDL HEADER START |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
3 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
4 |
# The contents of this file are subject to the terms of the |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
5 |
# Common Development and Distribution License (the "License"). |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
6 |
# You may not use this file except in compliance with the License. |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
7 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
8 |
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
9 |
# or http://www.opensolaris.org/os/licensing. |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
10 |
# See the License for the specific language governing permissions |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
11 |
# and limitations under the License. |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
12 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
13 |
# When distributing Covered Code, include this CDDL HEADER in each |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
14 |
# file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
15 |
# If applicable, add the following below this CDDL HEADER, with the |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
16 |
# fields enclosed by brackets "[]" replaced with your own identifying |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
17 |
# information: Portions Copyright [yyyy] [name of copyright owner] |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
18 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
19 |
# CDDL HEADER END |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
20 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
21 |
|
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
22 |
# |
1582
6bdbd27c11a2
7130956 Change default log file location to /var/log/install
Matt Keenan <matt.keenan@oracle.com>
parents:
1403
diff
changeset
|
23 |
# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved. |
902
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
24 |
# |
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
25 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
26 |
'''Module body for solaris_install package |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
27 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
28 |
Classes, functions and variables that are globally useful to install |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
29 |
technologies should go here. |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
30 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
31 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
32 |
|
1623
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
33 |
import ctypes as C |
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
34 |
import errno |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
35 |
import functools |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
36 |
import gettext |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
37 |
import logging |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
38 |
import os |
1623
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
39 |
import platform |
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
40 |
import pwd |
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
41 |
import re |
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
42 |
import shutil |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
43 |
import sys |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
44 |
import subprocess |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
45 |
|
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
46 |
from collections import namedtuple |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
47 |
from select import select |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
48 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
49 |
from data_object import DataObject |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
50 |
|
1623
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
51 |
from bootmgmt.bootinfo import SystemFirmware |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
52 |
from solaris_install.logger import INSTALL_LOGGER_NAME |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
53 |
|
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
54 |
|
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
55 |
_ = gettext.translation('solaris_install_common', '/usr/share/locale', |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
56 |
fallback=True).gettext |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
57 |
|
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
58 |
# Useful common directories and path pieces |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
59 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
60 |
# System Temporary Directory - for secure processes |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
61 |
SYSTEM_TEMP_DIR = '/system/volatile' |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
62 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
63 |
# Post-Install Logs Location |
1582
6bdbd27c11a2
7130956 Change default log file location to /var/log/install
Matt Keenan <matt.keenan@oracle.com>
parents:
1403
diff
changeset
|
64 |
POST_INSTALL_LOGS_DIR = '/var/log/install' |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
65 |
|
1173
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
66 |
# DOC label for entries pertaining to the distribution constructor |
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
67 |
# All 'volatile' entries are stored in DC_LABEL and all 'persistent' |
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
68 |
# entries are stored in DC_PERS_LABEL |
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
69 |
DC_LABEL = "DC specific" |
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
70 |
DC_PERS_LABEL = "DC specific persistent" |
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
71 |
|
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
72 |
# Path to AI_DTD |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
73 |
IMG_AI_MANIFEST_PATH = "auto_install" |
1582
6bdbd27c11a2
7130956 Change default log file location to /var/log/install
Matt Keenan <matt.keenan@oracle.com>
parents:
1403
diff
changeset
|
74 |
IMG_AI_MANIFEST_DTD = os.path.join(IMG_AI_MANIFEST_PATH, |
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
75 |
"ai.dtd.@DTD_VERSION_AI@") |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
76 |
SYS_AI_MANIFEST_DTD = "/usr/share/install/ai.dtd.@DTD_VERSION_AI@" |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
77 |
|
1380
2f3830b79568
7072842 update install gate for pkg5 API version bump to 66
Drew Fisher <drew.fisher@oracle.com>
parents:
1309
diff
changeset
|
78 |
# global version number for all of the consumers of the pkg5 API in the source |
2f3830b79568
7072842 update install gate for pkg5 API version bump to 66
Drew Fisher <drew.fisher@oracle.com>
parents:
1309
diff
changeset
|
79 |
# tree |
2f3830b79568
7072842 update install gate for pkg5 API version bump to 66
Drew Fisher <drew.fisher@oracle.com>
parents:
1309
diff
changeset
|
80 |
PKG5_API_VERSION = 66 |
2f3830b79568
7072842 update install gate for pkg5 API version bump to 66
Drew Fisher <drew.fisher@oracle.com>
parents:
1309
diff
changeset
|
81 |
|
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
82 |
# Reg-exp to match that a given string would be a valid DTD path for Install |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
83 |
DTD_PATH_RE = ".*\.dtd\.\d+$" |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
84 |
__dtd_path_regexp = re.compile(DTD_PATH_RE) |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
85 |
|
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
86 |
# AUTHORIZATIONS |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
87 |
PROFILE_AUTH = "solaris.autoinstall.profile" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
88 |
MANIFEST_AUTH = "solaris.autoinstall.manifest" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
89 |
CLIENT_AUTH = "solaris.autoinstall.client" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
90 |
SERVICE_AUTH = "solaris.autoinstall.service" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
91 |
AUTHS = "/usr/bin/auths" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
92 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
93 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
94 |
class CalledProcessError(subprocess.CalledProcessError): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
95 |
'''Expansion of subprocess.CalledProcessError that may optionally |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
96 |
store a reference to the Popen object that caused the error. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
97 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
98 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
99 |
def __init__(self, returncode, cmd, popen=None): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
100 |
super(CalledProcessError, self).__init__(returncode, cmd) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
101 |
self.popen = popen |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
102 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
103 |
def __str__(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
104 |
return ("Command '%s' returned unexpected exit status %s" % |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
105 |
(self.cmd, self.returncode)) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
106 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
107 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
108 |
class StderrCalledProcessError(CalledProcessError): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
109 |
'''A subprocess generated output to stderr''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
110 |
def __str__(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
111 |
return "Command '%s' generated error output" % self.cmd |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
112 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
113 |
|
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
114 |
class UnauthorizedUserError(Exception): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
115 |
'''Exception raised when the user does not have a specified |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
116 |
authorization. |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
117 |
''' |
1666
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
118 |
def __init__(self, msg): |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
119 |
self.value = msg |
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
120 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
121 |
def __str__(self): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
122 |
return self.value |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
123 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
124 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
125 |
class _LogBuffer(object): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
126 |
'''Class that reads from a filehandle (given by fileno), buffers |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
127 |
the output and dumps to a logger on newlines |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
128 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
129 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
130 |
def __init__(self, fileno, logger, loglevel, bufsize): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
131 |
'''fileno - File number of the file handle to read from |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
132 |
logger - The logger to log to |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
133 |
loglevel - The level at which to log |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
134 |
bufsize - How much to try and read at any given time |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
135 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
136 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
137 |
self.fileno = fileno |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
138 |
self.logger = logger |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
139 |
self.loglevel = loglevel |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
140 |
self.bufsize = bufsize |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
141 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
142 |
self._buffer = [] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
143 |
self._all = [] |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
144 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
145 |
def read_filehandle(self, flush=False): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
146 |
'''Read pending output from the filehandle, and store it in |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
147 |
the internal buffer. If the output contains a newline, or |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
148 |
flush=True, then flush the internal buffer to the logger |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
149 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
150 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
151 |
output = os.read(self.fileno, self.bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
152 |
if "\n" in output or flush: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
153 |
# "Flush" the _LogBuffer's buffer to the logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
154 |
# and add the output to the list of all output |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
155 |
# captured so far. Trailing newline is stripped, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
156 |
# as it is expected that the logger will *add* one |
1104
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
157 |
if flush: |
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
158 |
end_buf, newline, begin_buf = output, '', '' |
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
159 |
else: |
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
160 |
end_buf, newline, begin_buf = output.rpartition("\n") |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
161 |
self._buffer.append(end_buf) |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
162 |
flush_out = "".join(self._buffer) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
163 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
164 |
log_out = flush_out.strip() |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
165 |
if log_out: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
166 |
# Avoid sending blank lines to the logger |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
167 |
self.logger.log(self.loglevel, log_out) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
168 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
169 |
# Keep a record of all output retrieved so far in the |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
170 |
# self._all variable, so that the full output |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
171 |
# may be retrieved later. (Note that blank lines here are |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
172 |
# preserved, in contrast with what is logged) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
173 |
self._all.extend((flush_out, newline)) |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
174 |
self._buffer = [begin_buf] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
175 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
176 |
self._buffer.append(output) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
177 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
178 |
def all_output(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
179 |
'''Return all the output retrieved''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
180 |
self.read_filehandle(flush=True) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
181 |
return "".join(self._all) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
182 |
|
902
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
183 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
184 |
class Popen(subprocess.Popen): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
185 |
'''Enhanced version of subprocess.Popen with functionality commonly |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
186 |
used by install technologies. Functionality that requires blocking until |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
187 |
the subprocess completes is contained within the check_call classmethod, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
188 |
which is similar to subprocess.check_call. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
189 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
190 |
=== Usage examples === |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
191 |
The below examples all assume the command to be run is stored |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
192 |
in a list named 'cmd', e.g., cmd = ['/usr/bin/ls', '-l', '/tmp'] |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
193 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
194 |
* Run a command, raising an exception for non-zero return |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
195 |
>>> Popen.check_call(cmd) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
196 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
197 |
* Run a command, saving all stdout and stderr output |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
198 |
>>> ls = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
199 |
>>> print ls.stdout |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
200 |
srwxrwxrwx 1 root root 0 2011-02-14 09:14 dbus-zObU7eocIA |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
201 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
202 |
* Run a command, logging stderr and ignoring stdout |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
203 |
>>> mylogger = logging.getLogger('MyLogger') |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
204 |
>>> ls = Popen.check_call(cmd, stdout=Popen.DEVNULL, stderr=Popen.STORE, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
205 |
logger=mylogger) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
206 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
207 |
* Run a command, logging stderr at the logging.INFO level |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
208 |
>>> ls = Popen.check_call(cmd, stdout=Popen.STORE, stderr=Popen.STORE, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
209 |
logger="MyLogger", stderr_loglevel=logging.INFO) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
210 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
211 |
* Run a command, triggering an exception if the returncode is |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
212 |
anything EXCEPT '4' or '-1' |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
213 |
>>> Popen.check_call(cmd, check_result=(-1, 4)) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
214 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
215 |
* Run a command, and trigger an exception if it printed anything |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
216 |
to stderr |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
217 |
>>> Popen.check_call(cmd, stderr=Popen.PIPE, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
218 |
check_result=(Popen.STDERR_EMPTY,)) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
219 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
220 |
* Run a command, storing stdout, and ignoring the returncode |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
221 |
>>> ls = Popen.check_call(cmd, stdout=Popen.STORE, check_result=Popen.ANY) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
222 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
223 |
''' |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
224 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
225 |
PIPE = subprocess.PIPE |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
226 |
STDOUT = subprocess.STDOUT |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
227 |
STORE = object() |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
228 |
DEVNULL = object() |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
229 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
230 |
ANY = object() |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
231 |
STDERR_EMPTY = object() |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
232 |
SUCCESS = (0,) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
233 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
234 |
LOG_BUFSIZE = 8192 |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
235 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
236 |
def __init__(self, args, bufsize=0, executable=None, |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
237 |
stdin=None, stdout=None, stderr=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
238 |
preexec_fn=None, close_fds=False, shell=False, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
239 |
cwd=None, env=None, universal_newlines=False, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
240 |
startupinfo=None, creationflags=0): |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
241 |
if stdout is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
242 |
stdout = open(os.devnull, "w+") |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
243 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
244 |
if stderr is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
245 |
stderr = open(os.devnull, "w+") |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
246 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
247 |
if stdin is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
248 |
stdin = open(os.devnull, "r+") |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
249 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
250 |
super(Popen, self).__init__(args, bufsize=bufsize, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
251 |
executable=executable, stdin=stdin, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
252 |
stdout=stdout, stderr=stderr, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
253 |
preexec_fn=preexec_fn, close_fds=close_fds, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
254 |
shell=shell, cwd=cwd, env=env, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
255 |
universal_newlines=universal_newlines, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
256 |
startupinfo=startupinfo, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
257 |
creationflags=creationflags) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
258 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
259 |
@classmethod |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
260 |
def check_call(cls, args, bufsize=0, executable=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
261 |
stdin=None, stdout=None, stderr=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
262 |
preexec_fn=None, close_fds=False, shell=False, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
263 |
cwd=None, env=None, universal_newlines=False, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
264 |
startupinfo=None, creationflags=0, check_result=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
265 |
logger=None, stdout_loglevel=logging.DEBUG, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
266 |
stderr_loglevel=logging.ERROR): |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
267 |
'''solaris_install.Popen.check_call is interface compatible with |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
268 |
subprocess.check_call, accepting all the same positional/keyword |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
269 |
arguments. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
270 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
271 |
solaris_install.Popen.check_call will store the output from stdout and |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
272 |
stderr if they are set to Popen.STORE. Note that |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
273 |
Popen.stdout and Popen.stderr are replaced with a string - |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
274 |
references to filehandles won't be preserved in the manner that a |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
275 |
standard use of the Popen class allows. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
276 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
277 |
logger: If given, the stdout and stderr output from the subprocess |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
278 |
will be logged to this logger. (This parameter also accepts a string, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
279 |
which will be passed to logging.getLogger() to retrieve an appropriate |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
280 |
logger). One or both of stdout/stderr must be set to Popen.PIPE or |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
281 |
Popen.STORE for this functionality to work (a ValueError is raised |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
282 |
if that is not the case). See also stdout_loglevel and stderr_loglevel |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
283 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
284 |
stdout_loglevel and stderr_loglevel: If the stdout/stderr output |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
285 |
from the subprocess are logged as a result of logger being set, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
286 |
the output will be logged at the specified log level. Defaults are: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
287 |
stdout_loglevel: logging.DEBUG |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
288 |
stderr_loglevel: logging.ERROR |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
289 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
290 |
check_result: If specified, should be an iterable of all "acceptable" |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
291 |
values for the return code of the process. If the subprocess' return |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
292 |
code is not one of the given values, then a CalledProcessError |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
293 |
will be raised upon command completion. In addition to integer values, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
294 |
the special value solaris_install.Popen.STDERR_EMPTY may be |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
295 |
included; if it is, then the subprocess will be considered to have |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
296 |
exited unsuccessfully (and a CalledProcessError raised) if there |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
297 |
was any output to stderr. Note that stderr must be set to |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
298 |
Popen.STORE for this to be successful. By default, any non-zero |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
299 |
returncodes are considered errors. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
300 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
301 |
Setting check_result=Popen.ANY causes this function to mimic |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
302 |
subprocess.call (that is, the returncode will be ignored and the |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
303 |
caller is expected to ensure that appropriate behavior occurred) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
304 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
305 |
''' |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
306 |
if check_result is None: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
307 |
check_result = Popen.SUCCESS |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
308 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
309 |
# While Popen.STORE is essentially identical to Popen.PIPE currently, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
310 |
# the separate Popen.STORE parameter is preserved in case the |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
311 |
# functionality diverges in the future. Consumers should use |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
312 |
# Popen.STORE to ensure forwards-compatibility. |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
313 |
if stdout is Popen.STORE: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
314 |
stdout = Popen.PIPE |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
315 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
316 |
if stderr is Popen.STORE: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
317 |
stderr = Popen.PIPE |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
318 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
319 |
if logger is not None: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
320 |
if stderr is not Popen.PIPE and stdout is not Popen.PIPE: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
321 |
raise ValueError("'logger' argument requires one or both " |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
322 |
"of stdout/stderr to be set to PIPE or " |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
323 |
"STORE") |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
324 |
if isinstance(logger, basestring): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
325 |
logger = logging.getLogger(logger) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
326 |
if logger.isEnabledFor(stdout_loglevel): |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
327 |
logger.log(stdout_loglevel, "Executing: %s", args) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
328 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
329 |
popen = cls(args, bufsize=bufsize, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
330 |
executable=executable, stdin=stdin, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
331 |
stdout=stdout, stderr=stderr, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
332 |
preexec_fn=preexec_fn, close_fds=close_fds, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
333 |
shell=shell, cwd=cwd, env=env, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
334 |
universal_newlines=universal_newlines, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
335 |
startupinfo=startupinfo, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
336 |
creationflags=creationflags) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
337 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
338 |
if logger is None: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
339 |
# Simple case - capture all output, and replace the |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
340 |
# Popen.stdout/stderr filehandles with the actual output |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
341 |
output = popen.communicate() |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
342 |
popen.stdout, popen.stderr = output |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
343 |
else: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
344 |
if bufsize > 1: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
345 |
log_bufsize = bufsize |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
346 |
else: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
347 |
log_bufsize = Popen.LOG_BUFSIZE |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
348 |
popen.stdout, popen.stderr = popen._log(logger, log_bufsize, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
349 |
stdout_loglevel, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
350 |
stderr_loglevel) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
351 |
if check_result is Popen.ANY: |
1020
25ef0e7c9bd1
7020660 Change solaris_install.Popen() from a class to a function (Fix check_result=Popen.ANY)
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1017
diff
changeset
|
352 |
return popen |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
353 |
if popen.returncode not in check_result: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
354 |
raise CalledProcessError(popen.returncode, args, popen) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
355 |
if popen.stderr and popen.STDERR_EMPTY in check_result: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
356 |
raise StderrCalledProcessError(popen.returncode, args, popen) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
357 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
358 |
return popen |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
359 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
360 |
def _log(self, logger, bufsize, stdout_loglevel, stderr_loglevel): |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
361 |
'''Poll the stdout/stderr pipes for output, occasionally |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
362 |
dumping that output to the log. |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
363 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
364 |
While the subprocess is running, the filehandles are checked (using |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
365 |
select) for any pending output. The output is stored in memory, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
366 |
until a newline is found, at which point it's passed to the |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
367 |
logger. (see _LogBuffer class, above) |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
368 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
369 |
Additionally, all output is stored. This function returns a tuple |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
370 |
of (stdout, stderr), like Popen.communicate() |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
371 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
372 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
373 |
select_from = [] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
374 |
if self.stdout: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
375 |
stdout_logbuffer = _LogBuffer(self.stdout.fileno(), logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
376 |
stdout_loglevel, bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
377 |
select_from.append(self.stdout.fileno()) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
378 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
379 |
stdout_logbuffer = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
380 |
if self.stderr: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
381 |
stderr_logbuffer = _LogBuffer(self.stderr.fileno(), logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
382 |
stderr_loglevel, bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
383 |
select_from.append(self.stderr.fileno()) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
384 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
385 |
stderr_logbuffer = None |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
386 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
387 |
while self.poll() is None: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
388 |
ready = select(select_from, [], [], 0.25)[0] |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
389 |
if stdout_logbuffer and stdout_logbuffer.fileno in ready: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
390 |
stdout_logbuffer.read_filehandle() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
391 |
if stderr_logbuffer and stderr_logbuffer.fileno in ready: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
392 |
stderr_logbuffer.read_filehandle() |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
393 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
394 |
if stdout_logbuffer: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
395 |
stdout = stdout_logbuffer.all_output() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
396 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
397 |
stdout = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
398 |
if stderr_logbuffer: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
399 |
stderr = stderr_logbuffer.all_output() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
400 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
401 |
stderr = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
402 |
return stdout, stderr |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
403 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
404 |
|
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
405 |
# create a functools.partial object to represent common invocations of Popen. |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
406 |
# |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
407 |
# usage: |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
408 |
# from solaris_install import run, run_slient |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
409 |
# cmd = [my command] |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
410 |
# p = run(cmd) # p.stdout and p.stderr are available as normal |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
411 |
# runsilent(cmd) # p.stdout and p.stderr are set to /dev/null |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
412 |
|
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
413 |
run = functools.partial(Popen.check_call, stdout=Popen.STORE, |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
414 |
stderr=Popen.STORE, stderr_loglevel=logging.DEBUG, |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
415 |
logger=INSTALL_LOGGER_NAME) |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
416 |
run_silent = functools.partial(Popen.check_call, stdout=Popen.DEVNULL, |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
417 |
stderr=Popen.DEVNULL) |
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
418 |
|
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
419 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
420 |
class ApplicationData(DataObject): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
421 |
"""Application Data class |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
422 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
423 |
Provides a location for CUD applications to store application specific data |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
424 |
that checkpoints, etc. may require access to. |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
425 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
426 |
Currently stores: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
427 |
- Application Name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
428 |
- Work Directory, defaulting to /system/volatile |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
429 |
""" |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
430 |
|
1717
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
431 |
def __init__(self, application_name, work_dir="/system/volatile/", |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
432 |
logname=None): |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
433 |
super(ApplicationData, self).__init__(application_name) |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
434 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
435 |
self._application_name = application_name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
436 |
self._work_dir = work_dir |
1160
6f7e708c38ec
16257 Support for zones configuration and installation should be included in AI
Ethan Quach <Ethan.Quach@sun.com>
parents:
1151
diff
changeset
|
437 |
self.data_dict = dict() |
1717
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
438 |
self._logname = logname |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
439 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
440 |
@property |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
441 |
def application_name(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
442 |
"""Read-only Application Name - set at initialisation""" |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
443 |
return self._application_name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
444 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
445 |
@property |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
446 |
def work_dir(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
447 |
"""Read-only Work Directory - set at initialisation""" |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
448 |
return self._work_dir |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
449 |
|
1717
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
450 |
@property |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
451 |
def logname(self): |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
452 |
"""Read-only logname - set at initialization""" |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
453 |
return self._work_dir + "/" + self._logname |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
454 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
455 |
# Implement no-op XML methods |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
456 |
def to_xml(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
457 |
return None |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
458 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
459 |
@classmethod |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
460 |
def can_handle(cls, element): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
461 |
return False |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
462 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
463 |
@classmethod |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
464 |
def from_xml(cls, element): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
465 |
return None |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
466 |
|
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
467 |
|
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
468 |
class SetUIDasEUID(object): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
469 |
""" SetUIDasEUID - context manager for running section of code |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
470 |
with the uid set as the user's euid. |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
471 |
""" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
472 |
def __enter__(self): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
473 |
''' set the uid as euid ''' |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
474 |
self.euid = os.geteuid() |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
475 |
self.ruid = os.getuid() |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
476 |
os.setuid(self.euid) |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
477 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
478 |
def __exit__(self, *exc_info): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
479 |
''' reset the uid and euid ''' |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
480 |
os.setreuid(self.ruid, self.euid) |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
481 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
482 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
483 |
# Utility methods to generate paths given files |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
484 |
def system_temp_path(file=None): |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
485 |
''' Return System Temporary Directory, with file string appended''' |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
486 |
if file is not None: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
487 |
return os.path.sep.join([SYSTEM_TEMP_DIR, file]) |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
488 |
else: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
489 |
return SYSTEM_TEMP_DIR |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
490 |
|
1173
eb652dc71752
7046485 install_boot/boot.py imports a DC python module, causing undesired dependencies in snv_166
Mary Ding <mary.ding@oracle.com>
parents:
1160
diff
changeset
|
491 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
492 |
def post_install_logs_path(file=None): |
1268
25dda32568b2
7046402 provide a functools.partial object for common Popen.check_call invocations
Drew Fisher <drew.fisher@oracle.com>
parents:
1221
diff
changeset
|
493 |
''' Return Post-Install Logs Directory, with file string appended''' |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
494 |
if file is not None: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
495 |
return os.path.sep.join([POST_INSTALL_LOGS_DIR, file]) |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
496 |
else: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
497 |
return POST_INSTALL_LOGS_DIR |
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
498 |
|
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
499 |
|
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
500 |
# Other utility methods |
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
501 |
def force_delete(path): |
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
502 |
'''Delete either a file, a link, or directory and it's sub-tree''' |
1221
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
503 |
try: |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
504 |
if os.path.isdir(path) and not os.path.islink(path): |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
505 |
shutil.rmtree(path) |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
506 |
else: |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
507 |
os.remove(path) |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
508 |
except (IOError, OSError) as err: |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
509 |
if getattr(err, "errno", None) != errno.ENOENT: |
31c6d2de5731
7042146 Implement ISIM project
Susan Sohn <susan.sohn@oracle.com>
parents:
1173
diff
changeset
|
510 |
raise |
1403
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
511 |
|
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
512 |
|
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
513 |
def path_matches_dtd(path): |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
514 |
'''Check if a given path matches the RE for a DTD''' |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
515 |
global __dtd_path_regexp |
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
516 |
|
7d79448a5018
7037014 Install DTDs should be versioned
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1380
diff
changeset
|
517 |
return __dtd_path_regexp.match(path) is not None |
1623
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
518 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
519 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
520 |
def get_system_memory(): |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
521 |
'''Returns the amount of memory available in the system in MB |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
522 |
Basically just as prtconf does. |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
523 |
''' |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
524 |
memory = os.sysconf('SC_PAGESIZE') * os.sysconf('SC_PHYS_PAGES') |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
525 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
526 |
# round it like prtconf did to nearest MB |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
527 |
mb = 2 ** 20 # can't import Size |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
528 |
return (memory + mb - 1) / mb |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
529 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
530 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
531 |
def gpt_firmware_check(): |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
532 |
''' Check to see if the system supports GPT labeled boot disks''' |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
533 |
|
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
534 |
if platform.processor() == "sparc": |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
535 |
gpt_capable = False |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
536 |
if hasattr(SystemFirmware, "PROP_GPT_SUPPORTED"): |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
537 |
firmware = SystemFirmware.get() |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
538 |
gpt_capable = firmware.getprop(SystemFirmware.PROP_GPT_SUPPORTED) |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
539 |
return gpt_capable |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
540 |
else: |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
541 |
# x86 will always be GPT bootable due to GRUB2 |
cb56a2fb4925
PSARC 2012/074 UEFI/GRUB2/Large Disk Boot (UGLDB) (Install phase II):
Niall Power <niall.power@oracle.com>
parents:
1582
diff
changeset
|
542 |
return True |
1652
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
543 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
544 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
545 |
def check_auth_and_euid(auth): |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
546 |
""" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
547 |
Checks whether the user has the specified authorization |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
548 |
and euid as 0. |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
549 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
550 |
Raises UnauthorizedUserError if euid is not 0 or user |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
551 |
doesn't have authorization. |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
552 |
""" |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
553 |
user = pwd.getpwuid(os.getuid())[0] |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
554 |
cmd = [AUTHS, "check", "-u", user, auth] |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
555 |
|
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
556 |
try: |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
557 |
run(cmd) |
15ba29ecb4ed
PSARC 2012/139 installadm Execution Profiles
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1623
diff
changeset
|
558 |
except CalledProcessError as err: |
1666
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
559 |
raise UnauthorizedUserError(_("Insufficient permissions to perform " |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
560 |
"operation.\nAuthorization <%s> " |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
561 |
"required to perform this operation." % \ |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
562 |
auth)) |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
563 |
|
1717
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
564 |
# raise error if euid is not 0 |
1666
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
565 |
if os.geteuid() != 0: |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
566 |
raise UnauthorizedUserError(_("Insufficient permission to perform " |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
567 |
"operation.\neuid required to be " |
e9d4b6b42777
7165160 UnauthorizedUserError doesn't give proper error message in case of
nirmal27<Nirmal.Agarwal@oracle.com>
parents:
1652
diff
changeset
|
568 |
"0 to perform this operation.")) |
1717
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
569 |
|
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
570 |
|
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
571 |
def check_log_level(level): |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
572 |
""" Checks the log level being passed in""" |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
573 |
try: |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
574 |
logging.getLevelName(level) |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
575 |
return True |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
576 |
except NameError: |
10cb4d15a248
7066254 Problem with install/logging
Ginnie Wray<virginia.wray@oracle.com>
parents:
1666
diff
changeset
|
577 |
return False |