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-2012 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 " + repr(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 " + repr(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 " + repr(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 " + repr(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 " + repr(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 " + repr(getcwd()) + " to " + repr(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 " + repr(env['RELAX_PATH']) + ".\n\n") 97 98 # All other errors (print normal python error message). 99 else: 100 sys.stderr.write("OSError: [Errno " + repr(message.errno) + "] " + message.strerror + ": " + repr(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 " + repr(env['RELAX_PATH'] + sep + 'relax') + " to " + repr(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("\nCreating the byte-compiled *.pyc files.") 116 python_path = sys.prefix + path.sep + 'bin' + path.sep + 'python' + `sys.version_info[0]` + '.' + `sys.version_info[1]` 117 cmd = "cd %s; %s -m compileall . ; %s -O -m compileall ." % (env['RELAX_PATH'], python_path, python_path) 118 print(cmd) 119 system(cmd) 120 121 # Final printout. 122 print("\n\n\n")
123 124
125 -def uninstall(target, source, env):
126 """relax deinstallation function (a Builder action).""" 127 128 # Print out. 129 ############ 130 131 print('') 132 print("######################") 133 print("# Uninstalling relax #") 134 print("######################\n\n") 135 print(("Uninstalling the program relax from the directory " + repr(env['INSTALL_PATH']) + "\n\n")) 136 137 138 # Tests. 139 ######## 140 141 # Test that the installation path exists. 142 if not access(env['INSTALL_PATH'], F_OK): 143 sys.stderr.write("Cannot uninstall relax, the installation path " + repr(env['INSTALL_PATH']) + " does not exist.\n\n") 144 return 145 146 # Test if the binary directory already exists. 147 if not access(env['BIN_PATH'], F_OK): 148 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['BIN_PATH']) + " does not exist.\n\n") 149 return 150 151 # Test if the relax installation directory exists. 152 if not access(env['RELAX_PATH'], F_OK): 153 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['RELAX_PATH']) + " does not exist.\n\n") 154 return 155 156 # Test if the symlink exists. 157 if env['SYMLINK_FLAG']: 158 try: 159 lstat(env['SYMLINK']) 160 except OSError: 161 sys.stderr.write("Cannot uninstall relax, the file " + repr(env['SYMLINK']) + " does not exist.\n\n") 162 return 163 164 165 # Uninstall. 166 ############ 167 168 # Remove the symbolic link. 169 if env['SYMLINK_FLAG']: 170 print(("\nRemoving the symbolic link " + repr(env['SYMLINK']) + ".")) 171 remove(env['SYMLINK']) 172 173 # Remove the directory. 174 print(("\nRemoving the entire directory " + repr(env['RELAX_PATH']) + ".\n")) 175 for root, dirs, files in walk(env['RELAX_PATH'], topdown=False): 176 for file in files: 177 remove(path.join(root, file)) 178 for file in dirs: 179 rmdir(path.join(root, file)) 180 rmdir(env['RELAX_PATH']) 181 182 # Final printout. 183 print("\n\n\n")
184