Package scons :: Module install
[hide private]
[frames] | no frames]

Source Code for Module scons.install

  1  #! /usr/bin/python 
  2  # That line was just so programs like gvim or emacs will understand that this is Python code!  Don't 
  3  # make this file executable. 
  4   
  5  ############################################################################### 
  6  #                                                                             # 
  7  # Copyright (C) 2006 Edward d'Auvergne                                        # 
  8  #                                                                             # 
  9  # This file is part of the program relax.                                     # 
 10  #                                                                             # 
 11  # relax is free software; you can redistribute it and/or modify               # 
 12  # it under the terms of the GNU General Public License as published by        # 
 13  # the Free Software Foundation; either version 2 of the License, or           # 
 14  # (at your option) any later version.                                         # 
 15  #                                                                             # 
 16  # relax is distributed in the hope that it will be useful,                    # 
 17  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
 18  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
 19  # GNU General Public License for more details.                                # 
 20  #                                                                             # 
 21  # You should have received a copy of the GNU General Public License           # 
 22  # along with relax; if not, write to the Free Software                        # 
 23  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA   # 
 24  #                                                                             # 
 25  ############################################################################### 
 26   
 27   
 28  # Import statements. 
 29  from os import F_OK, access, getcwd, path, remove, rmdir, sep, system, walk 
 30  from shutil import copytree 
 31  import sys 
 32   
 33  # UNIX only functions from the os module. 
 34  try: 
 35      from os import lstat, symlink 
 36  except ImportError: 
 37      pass 
 38   
 39   
40 -def install(target, source, env):
41 """relax installation function (a Builder action).""" 42 43 # Print out. 44 ############ 45 46 print 47 print "####################" 48 print "# Installing relax #" 49 print "####################\n\n" 50 print "Installing the program relax into the directory " + `env['RELAX_PATH']` + "\n\n" 51 52 53 # Tests. 54 ######## 55 56 # Test that the installation path exists. 57 if not access(env['INSTALL_PATH'], F_OK): 58 sys.stderr.write("Cannot install relax, the installation path " + `env['INSTALL_PATH']` + " does not exist.\n\n") 59 return 60 61 # Test if the binary directory already exists. 62 if not access(env['BIN_PATH'], F_OK): 63 sys.stderr.write("Cannot install relax, the directory " + `env['BIN_PATH']` + " does not exist.\n\n") 64 return 65 66 # Test if the relax installation directory already exists. 67 if access(env['RELAX_PATH'], F_OK): 68 sys.stderr.write("Cannot install relax, the directory " + `env['RELAX_PATH']` + " already exists.\n\n") 69 return 70 71 # Test if the symlink exists. 72 if env['SYMLINK_FLAG']: 73 try: 74 lstat(env['SYMLINK']) 75 except OSError: 76 # OK, symlink doesn't exist. 77 pass 78 else: 79 sys.stderr.write("Cannot install relax, the file " + `env['SYMLINK']` + " already exists.\n\n") 80 return 81 82 83 # Install. 84 ########## 85 86 # Copy the files (and create the directory). 87 try: 88 print "\nCopying all files in " + `getcwd()` + " to " + `env['RELAX_PATH']` + "." 89 copytree(getcwd(), env['RELAX_PATH']) 90 except OSError, message: 91 # Failure message. 92 sys.stderr.write("Cannot install relax, " + message.__doc__ + "\n") 93 94 # You don't have the privilages to do this. 95 if message.errno == 13: 96 sys.stderr.write("Permission denied, cannot create the directory " + `env['RELAX_PATH']` + ".\n\n") 97 98 # All other errors (print normal python error message). 99 else: 100 sys.stderr.write("OSError: [Errno " + `message.errno` + "] " + message.strerror + ": " + `message.filename` + "\n\n") 101 102 # Quit the function. 103 return 104 105 # Create the symbolic link. 106 if env['SYMLINK_FLAG']: 107 print "\nCreating the symbolic link from " + `env['RELAX_PATH'] + sep + 'relax'` + " to " + `env['SYMLINK']` + "." 108 symlink(env['RELAX_PATH'] + sep + 'relax', env['SYMLINK']) 109 110 111 # Byte compile. 112 ############### 113 114 # Run relax to create the *.pyc files. 115 print "\nRunning relax to create the byte-compiled *.pyc files." 116 system(env['SYMLINK'] + " --test") 117 118 # Final print out. 119 print "\n\n\n"
120 121
122 -def uninstall(target, source, env):
123 """relax deinstallation function (a Builder action).""" 124 125 # Print out. 126 ############ 127 128 print 129 print "######################" 130 print "# Uninstalling relax #" 131 print "######################\n\n" 132 print "Uninstalling the program relax from the directory " + `env['INSTALL_PATH']` + "\n\n" 133 134 135 # Tests. 136 ######## 137 138 # Test that the installation path exists. 139 if not access(env['INSTALL_PATH'], F_OK): 140 sys.stderr.write("Cannot uninstall relax, the installation path " + `env['INSTALL_PATH']` + " does not exist.\n\n") 141 return 142 143 # Test if the binary directory already exists. 144 if not access(env['BIN_PATH'], F_OK): 145 sys.stderr.write("Cannot uninstall relax, the directory " + `env['BIN_PATH']` + " does not exist.\n\n") 146 return 147 148 # Test if the relax installation directory exists. 149 if not access(env['RELAX_PATH'], F_OK): 150 sys.stderr.write("Cannot uninstall relax, the directory " + `env['RELAX_PATH']` + " does not exist.\n\n") 151 return 152 153 # Test if the symlink exists. 154 if env['SYMLINK_FLAG']: 155 try: 156 lstat(env['SYMLINK']) 157 except OSError: 158 sys.stderr.write("Cannot uninstall relax, the file " + `env['SYMLINK']` + " does not exist.\n\n") 159 return 160 161 162 # Uninstall. 163 ############ 164 165 # Remove the symbolic link. 166 if env['SYMLINK_FLAG']: 167 print "\nRemoving the symbolic link " + `env['SYMLINK']` + "." 168 remove(env['SYMLINK']) 169 170 # Remove the directory. 171 print "\nRemoving the entire directory " + `env['RELAX_PATH']` + ".\n" 172 for root, dirs, files in walk(env['RELAX_PATH'], topdown=False): 173 for file in files: 174 remove(path.join(root, file)) 175 for file in dirs: 176 rmdir(path.join(root, file)) 177 rmdir(env['RELAX_PATH']) 178 179 # Final print out. 180 print "\n\n\n"
181