author | Ethan Quach <Ethan.Quach@sun.com> |
Tue, 31 May 2011 14:21:09 -0700 | |
changeset 1160 | 6f7e708c38ec |
parent 1151 | 95413393ef67 |
child 1173 | eb652dc71752 |
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 |
# |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
23 |
# Copyright (c) 2010, 2011, 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 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
33 |
from collections import namedtuple |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
34 |
import gettext |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
35 |
import logging |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
36 |
import os |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
37 |
from select import select |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
38 |
import sys |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
39 |
import subprocess |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
40 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
41 |
from data_object import DataObject |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
42 |
|
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
43 |
_ = gettext.translation('AI', '/usr/share/locale', fallback=True).gettext |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
44 |
|
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
45 |
# Shebang lines to tell a (derived manifest) script apart from an XML manifest. |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
46 |
# Note their appearance in scripts may have "/usr" prepended to them. |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
47 |
KSH93_SHEBANG = "/bin/ksh93" |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
48 |
PYTHON_SHEBANG = "/bin/python" |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
49 |
|
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
50 |
# Useful common directories and path pieces |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
51 |
|
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
52 |
# System Temporary Directory - for secure processes |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
53 |
SYSTEM_TEMP_DIR = '/system/volatile' |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
54 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
55 |
# Post-Install Logs Location |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
56 |
POST_INSTALL_LOGS_DIR = '/var/sadm/system/logs' |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
57 |
|
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
58 |
# Directory for per service information |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
59 |
AI_SERVICE_DIR_PATH = '/var/ai/' |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
60 |
|
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
61 |
# Where manifests are stored |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
62 |
AI_DATA = "AI_data" |
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
63 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
64 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
65 |
class CalledProcessError(subprocess.CalledProcessError): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
66 |
'''Expansion of subprocess.CalledProcessError that may optionally |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
67 |
store a reference to the Popen object that caused the error. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
68 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
69 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
70 |
def __init__(self, returncode, cmd, popen=None): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
71 |
super(CalledProcessError, self).__init__(returncode, cmd) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
72 |
self.popen = popen |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
73 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
74 |
def __str__(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
75 |
return ("Command '%s' returned unexpected exit status %s" % |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
76 |
(self.cmd, self.returncode)) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
77 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
78 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
79 |
class StderrCalledProcessError(CalledProcessError): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
80 |
'''A subprocess generated output to stderr''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
81 |
def __str__(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
82 |
return "Command '%s' generated error output" % self.cmd |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
83 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
84 |
|
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
85 |
class _LogBuffer(object): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
86 |
'''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
|
87 |
the output and dumps to a logger on newlines |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
88 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
89 |
''' |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
90 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
91 |
def __init__(self, fileno, logger, loglevel, bufsize): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
92 |
'''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
|
93 |
logger - The logger to log to |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
94 |
loglevel - The level at which to log |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
95 |
bufsize - How much to try and read at any given time |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
96 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
97 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
98 |
self.fileno = fileno |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
99 |
self.logger = logger |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
100 |
self.loglevel = loglevel |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
101 |
self.bufsize = bufsize |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
102 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
103 |
self._buffer = [] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
104 |
self._all = [] |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
105 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
106 |
def read_filehandle(self, flush=False): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
107 |
'''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
|
108 |
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
|
109 |
flush=True, then flush the internal buffer to the logger |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
110 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
111 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
112 |
output = os.read(self.fileno, self.bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
113 |
if "\n" in output or flush: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
114 |
# "Flush" the _LogBuffer's buffer to the logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
115 |
# 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
|
116 |
# captured so far. Trailing newline is stripped, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
117 |
# 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
|
118 |
if flush: |
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
119 |
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
|
120 |
else: |
31b8f597e30a
7041751 solaris_install._LogBuffer misbehaves in read_filehandle() if flush=True
Keith Mitchell <keith.mitchell@oracle.com>
parents:
1087
diff
changeset
|
121 |
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
|
122 |
self._buffer.append(end_buf) |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
123 |
flush_out = "".join(self._buffer) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
124 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
125 |
log_out = flush_out.strip() |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
126 |
if log_out: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
127 |
# 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
|
128 |
self.logger.log(self.loglevel, log_out) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
129 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
130 |
# 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
|
131 |
# 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
|
132 |
# 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
|
133 |
# 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
|
134 |
self._all.extend((flush_out, newline)) |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
135 |
self._buffer = [begin_buf] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
136 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
137 |
self._buffer.append(output) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
138 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
139 |
def all_output(self): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
140 |
'''Return all the output retrieved''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
141 |
self.read_filehandle(flush=True) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
142 |
return "".join(self._all) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
143 |
|
902
5b421d727e75
17161 - Implement Data Cache component for Installer
Darren Kenny <Darren.Kenny@Sun.COM>
parents:
diff
changeset
|
144 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
145 |
class Popen(subprocess.Popen): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
146 |
'''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
|
147 |
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
|
148 |
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
|
149 |
which is similar to subprocess.check_call. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
150 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
151 |
=== Usage examples === |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
152 |
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
|
153 |
in a list named 'cmd', e.g., cmd = ['/usr/bin/ls', '-l', '/tmp'] |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
154 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
155 |
* 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
|
156 |
>>> Popen.check_call(cmd) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
157 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
158 |
* 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
|
159 |
>>> 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
|
160 |
>>> print ls.stdout |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
161 |
srwxrwxrwx 1 root root 0 2011-02-14 09:14 dbus-zObU7eocIA |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
162 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
163 |
* 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
|
164 |
>>> mylogger = logging.getLogger('MyLogger') |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
165 |
>>> 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
|
166 |
logger=mylogger) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
167 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
168 |
* 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
|
169 |
>>> 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
|
170 |
logger="MyLogger", stderr_loglevel=logging.INFO) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
171 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
172 |
* 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
|
173 |
anything EXCEPT '4' or '-1' |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
174 |
>>> Popen.check_call(cmd, check_result=(-1, 4)) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
175 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
176 |
* 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
|
177 |
to stderr |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
178 |
>>> 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
|
179 |
check_result=(Popen.STDERR_EMPTY,)) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
180 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
181 |
* 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
|
182 |
>>> ls = Popen.check_call(cmd, stdout=Popen.STORE, check_result=Popen.ANY) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
183 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
184 |
''' |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
185 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
186 |
PIPE = subprocess.PIPE |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
187 |
STDOUT = subprocess.STDOUT |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
188 |
STORE = object() |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
189 |
DEVNULL = object() |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
190 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
191 |
ANY = object() |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
192 |
STDERR_EMPTY = object() |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
193 |
SUCCESS = (0,) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
194 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
195 |
LOG_BUFSIZE = 8192 |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
196 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
197 |
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
|
198 |
stdin=None, stdout=None, stderr=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
199 |
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
|
200 |
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
|
201 |
startupinfo=None, creationflags=0): |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
202 |
if stdout is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
203 |
stdout = open(os.devnull, "w+") |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
204 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
205 |
if stderr is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
206 |
stderr = open(os.devnull, "w+") |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
207 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
208 |
if stdin is Popen.DEVNULL: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
209 |
stdin = open(os.devnull, "r+") |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
210 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
211 |
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
|
212 |
executable=executable, stdin=stdin, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
213 |
stdout=stdout, stderr=stderr, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
214 |
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
|
215 |
shell=shell, cwd=cwd, env=env, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
216 |
universal_newlines=universal_newlines, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
217 |
startupinfo=startupinfo, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
218 |
creationflags=creationflags) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
219 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
220 |
@classmethod |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
221 |
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
|
222 |
stdin=None, stdout=None, stderr=None, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
223 |
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
|
224 |
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
|
225 |
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
|
226 |
logger=None, stdout_loglevel=logging.DEBUG, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
227 |
stderr_loglevel=logging.ERROR): |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
228 |
'''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
|
229 |
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
|
230 |
arguments. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
231 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
232 |
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
|
233 |
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
|
234 |
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
|
235 |
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
|
236 |
standard use of the Popen class allows. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
237 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
238 |
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
|
239 |
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
|
240 |
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
|
241 |
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
|
242 |
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
|
243 |
if that is not the case). See also stdout_loglevel and stderr_loglevel |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
244 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
245 |
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
|
246 |
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
|
247 |
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
|
248 |
stdout_loglevel: logging.DEBUG |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
249 |
stderr_loglevel: logging.ERROR |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
250 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
251 |
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
|
252 |
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
|
253 |
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
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
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
|
258 |
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
|
259 |
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
|
260 |
returncodes are considered errors. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
261 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
262 |
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
|
263 |
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
|
264 |
caller is expected to ensure that appropriate behavior occurred) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
265 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
266 |
''' |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
267 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
268 |
if check_result is None: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
269 |
check_result = Popen.SUCCESS |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
270 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
271 |
# 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
|
272 |
# 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
|
273 |
# 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
|
274 |
# Popen.STORE to ensure forwards-compatibility. |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
275 |
if stdout is Popen.STORE: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
276 |
stdout = Popen.PIPE |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
277 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
278 |
if stderr is Popen.STORE: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
279 |
stderr = Popen.PIPE |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
280 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
281 |
if logger is not None: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
282 |
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
|
283 |
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
|
284 |
"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
|
285 |
"STORE") |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
286 |
if isinstance(logger, basestring): |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
287 |
logger = logging.getLogger(logger) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
288 |
if logger.isEnabledFor(stdout_loglevel): |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
289 |
logger.log(stdout_loglevel, "Executing: %s", args) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
290 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
291 |
popen = cls(args, bufsize=bufsize, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
292 |
executable=executable, stdin=stdin, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
293 |
stdout=stdout, stderr=stderr, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
294 |
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
|
295 |
shell=shell, cwd=cwd, env=env, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
296 |
universal_newlines=universal_newlines, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
297 |
startupinfo=startupinfo, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
298 |
creationflags=creationflags) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
299 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
300 |
if logger is None: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
301 |
# 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
|
302 |
# 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
|
303 |
output = popen.communicate() |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
304 |
popen.stdout, popen.stderr = output |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
305 |
else: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
306 |
if bufsize > 1: |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
307 |
log_bufsize = bufsize |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
308 |
else: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
309 |
log_bufsize = Popen.LOG_BUFSIZE |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
310 |
# pylint: disable-msg=W0212 |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
311 |
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
|
312 |
stdout_loglevel, |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
313 |
stderr_loglevel) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
314 |
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
|
315 |
return popen |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
316 |
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
|
317 |
raise CalledProcessError(popen.returncode, args, popen) |
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
318 |
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
|
319 |
raise StderrCalledProcessError(popen.returncode, args, popen) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
320 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
321 |
return popen |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
322 |
|
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
323 |
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
|
324 |
'''Poll the stdout/stderr pipes for output, occasionally |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
325 |
dumping that output to the log. |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
326 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
327 |
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
|
328 |
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
|
329 |
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
|
330 |
logger. (see _LogBuffer class, above) |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
331 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
332 |
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
|
333 |
of (stdout, stderr), like Popen.communicate() |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
334 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
335 |
''' |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
336 |
select_from = [] |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
337 |
if self.stdout: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
338 |
stdout_logbuffer = _LogBuffer(self.stdout.fileno(), logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
339 |
stdout_loglevel, bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
340 |
select_from.append(self.stdout.fileno()) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
341 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
342 |
stdout_logbuffer = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
343 |
if self.stderr: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
344 |
stderr_logbuffer = _LogBuffer(self.stderr.fileno(), logger, |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
345 |
stderr_loglevel, bufsize) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
346 |
select_from.append(self.stderr.fileno()) |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
347 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
348 |
stderr_logbuffer = None |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
349 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
350 |
while self.poll() is None: |
1017
70f0b66c2ef7
7019067 solaris_install.Popen logs blank lines
Keith Mitchell <keith.mitchell@oracle.com>
parents:
989
diff
changeset
|
351 |
ready = select(select_from, [], [], 0.25)[0] |
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
352 |
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
|
353 |
stdout_logbuffer.read_filehandle() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
354 |
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
|
355 |
stderr_logbuffer.read_filehandle() |
1087
96b6cc8130c5
6994260 Implement Auto-Installer Derived Manifests
Jack Schwartz <Jack.Schwartz@Oracle.COM>
parents:
1022
diff
changeset
|
356 |
|
989
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
357 |
if stdout_logbuffer: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
358 |
stdout = stdout_logbuffer.all_output() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
359 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
360 |
stdout = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
361 |
if stderr_logbuffer: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
362 |
stderr = stderr_logbuffer.all_output() |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
363 |
else: |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
364 |
stderr = None |
eedee9fd01bb
15957 Implement solaris_install.Popen
Keith Mitchell <keith.mitchell@oracle.com>
parents:
947
diff
changeset
|
365 |
return stdout, stderr |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
366 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
367 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
368 |
class ApplicationData(DataObject): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
369 |
"""Application Data class |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
370 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
371 |
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
|
372 |
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
|
373 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
374 |
Currently stores: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
375 |
- Application Name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
376 |
- Work Directory, defaulting to /system/volatile |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
377 |
""" |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
378 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
379 |
def __init__(self, application_name, work_dir="/system/volatile/"): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
380 |
super(ApplicationData, self).__init__(application_name) |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
381 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
382 |
self._application_name = application_name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
383 |
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
|
384 |
self.data_dict = dict() |
1151
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
385 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
386 |
@property |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
387 |
def application_name(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
388 |
"""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
|
389 |
return self._application_name |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
390 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
391 |
@property |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
392 |
def work_dir(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
393 |
"""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
|
394 |
return self._work_dir |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
395 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
396 |
# Implement no-op XML methods |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
397 |
def to_xml(self): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
398 |
return None |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
399 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
400 |
@classmethod |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
401 |
def can_handle(cls, element): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
402 |
return False |
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 |
@classmethod |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
405 |
def from_xml(cls, element): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
406 |
return None |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
407 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
408 |
# 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
|
409 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
410 |
def system_temp_path(file=None): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
411 |
''' Return System Temporary Directory, with file string appended |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
412 |
''' |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
413 |
if file is not None: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
414 |
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
|
415 |
else: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
416 |
return SYSTEM_TEMP_DIR |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
417 |
|
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
418 |
def post_install_logs_path(file=None): |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
419 |
''' Return Post-Install Logs Directory, with file string appended |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
420 |
''' |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
421 |
if file is not None: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
422 |
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
|
423 |
else: |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
424 |
return POST_INSTALL_LOGS_DIR |
95413393ef67
7038120 Update Auto Installer to use CUD
Darren Kenny <Darren.Kenny@Oracle.COM>
parents:
1104
diff
changeset
|
425 |