1 # Copyright (c) 2003 Intel Corporation
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
11 # * Redistributions in binary form must reproduce the above
12 # copyright notice, this list of conditions and the following
13 # disclaimer in the documentation and/or other materials provided
14 # with the distribution.
16 # * Neither the name of the Intel Corporation nor the names of its
17 # contributors may be used to endorse or promote products derived
18 # from this software without specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27 # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29 # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 # EXPORT LAWS: THIS LICENSE ADDS NO RESTRICTIONS TO THE EXPORT LAWS OF
33 # YOUR JURISDICTION. It is licensee's responsibility to comply with any
34 # export regulations applicable in licensee's jurisdiction. Under
35 # CURRENT (May 2000) U.S. export regulations this software is eligible
36 # for export from the U.S. and can be downloaded by or otherwise
37 # exported or reexported worldwide EXCEPT to U.S. embargoed destinations
38 # which include Cuba, Iraq, Libya, North Korea, Iran, Syria, Sudan,
39 # Afghanistan and any other country to which the U.S. has embargoed
43 import os, sys, shutil
46 from Exceptions import *
51 from python docs for os.makedirs:
52 Throws an error exception if the leaf directory
53 already exists or cannot be created.
55 That is real useful. Instead, we'll create the directory, then use a
56 separate function to test for its existance.
58 Return 1 if the directory exists and/or has been created, a BootManagerException
59 otherwise. Does not test the writability of said directory.
68 raise BootManagerException, "Unable to create directory tree: %s" % path
74 def removedir( path ):
76 remove a directory tree, return 1 if successful, a BootManagerException
87 raise BootManagerException, "Unable to remove directory tree: %s" % path
93 def sysexec( cmd, log= None ):
95 execute a system command, output the results to the logger
98 return 1 if command completed (return code of non-zero),
99 0 if failed. A BootManagerException is raised if the command
100 was unable to execute or was interrupted by the user with Ctrl+C
102 prog= popen2.Popen4( cmd, 0 )
104 raise BootManagerException, \
105 "Unable to create instance of popen2.Popen3 " \
106 "for command: %s" % cmd
110 for line in prog.fromchild:
112 except KeyboardInterrupt:
113 raise BootManagerException, "Interrupted by user"
115 returncode= prog.wait()
117 raise BootManagerException, "Running %s failed (rc=%d)" % (cmd,returncode)
123 def sysexec_noerr( cmd, log= None ):
125 same as sysexec, but capture boot manager exceptions
129 rc= sysexec( cmd, log )
130 except BootManagerException, e:
139 change to a directory, return 1 if successful, a BootManagerException if failure
144 raise BootManagerException, "Unable to change to directory: %s" % dir
150 def removefile( filepath ):
152 removes a file, return 1 if successful, 0 if failure
155 os.remove( filepath )
157 raise BootManagerException, "Unable to remove file: %s" % filepath