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 (http://www.nmr-relax.com).          # 
 10  #                                                                             # 
 11  # This program 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 3 of the License, or           # 
 14  # (at your option) any later version.                                         # 
 15  #                                                                             # 
 16  # This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       # 
 23  #                                                                             # 
 24  ############################################################################### 
 25   
 26   
 27  # Import statements. 
 28  from os import F_OK, access, getcwd, path, remove, rmdir, sep, system, walk 
 29  from shutil import copytree 
 30  import sys 
 31   
 32  # UNIX only functions from the os module. 
 33  try: 
 34      from os import lstat, symlink 
 35  except ImportError: 
 36      pass 
 37   
 38   
39 -def install(target, source, env):
40 """relax installation function (a Builder action).""" 41 42 # Print out. 43 ############ 44 45 print('') 46 print("####################") 47 print("# Installing relax #") 48 print("####################\n\n") 49 print("Installing the program relax into the directory " + repr(env['RELAX_PATH']) + "\n\n") 50 51 52 # Tests. 53 ######## 54 55 # Test that the installation path exists. 56 if not access(env['INSTALL_PATH'], F_OK): 57 sys.stderr.write("Cannot install relax, the installation path " + repr(env['INSTALL_PATH']) + " does not exist.\n\n") 58 return 59 60 # Test if the binary directory already exists. 61 if not access(env['BIN_PATH'], F_OK): 62 sys.stderr.write("Cannot install relax, the directory " + repr(env['BIN_PATH']) + " does not exist.\n\n") 63 return 64 65 # Test if the relax installation directory already exists. 66 if access(env['RELAX_PATH'], F_OK): 67 sys.stderr.write("Cannot install relax, the directory " + repr(env['RELAX_PATH']) + " already exists.\n\n") 68 return 69 70 # Test if the symlink exists. 71 if env['SYMLINK_FLAG']: 72 try: 73 lstat(env['SYMLINK']) 74 except OSError: 75 # OK, symlink doesn't exist. 76 pass 77 else: 78 sys.stderr.write("Cannot install relax, the file " + repr(env['SYMLINK']) + " already exists.\n\n") 79 return 80 81 82 # Install. 83 ########## 84 85 # Copy the files (and create the directory). 86 try: 87 print("\nCopying all files in " + repr(getcwd()) + " to " + repr(env['RELAX_PATH']) + ".") 88 copytree(getcwd(), env['RELAX_PATH']) 89 except OSError: 90 message = sys.exc_info()[1] 91 92 # Failure message. 93 sys.stderr.write("Cannot install relax, " + message.__doc__ + "\n") 94 95 # You don't have the privilages to do this. 96 if message.errno == 13: 97 sys.stderr.write("Permission denied, cannot create the directory " + repr(env['RELAX_PATH']) + ".\n\n") 98 99 # All other errors (print normal python error message). 100 else: 101 sys.stderr.write("OSError: [Errno " + repr(message.errno) + "] " + message.strerror + ": " + repr(message.filename) + "\n\n") 102 103 # Quit the function. 104 return 105 106 # Create the symbolic link. 107 if env['SYMLINK_FLAG']: 108 print("\nCreating the symbolic link from " + repr(env['RELAX_PATH'] + sep + 'relax') + " to " + repr(env['SYMLINK']) + ".") 109 symlink(env['RELAX_PATH'] + sep + 'relax', env['SYMLINK']) 110 111 112 # Byte compile. 113 ############### 114 115 # Run relax to create the *.pyc files. 116 print("\nCreating the byte-compiled *.pyc files.") 117 python_path = sys.prefix + path.sep + 'bin' + path.sep + 'python' + `sys.version_info[0]` + '.' + `sys.version_info[1]` 118 cmd = "cd %s; %s -m compileall . ; %s -O -m compileall ." % (env['RELAX_PATH'], python_path, python_path) 119 print(cmd) 120 system(cmd) 121 122 # Final printout. 123 print("\n\n\n")
124 125
126 -def uninstall(target, source, env):
127 """relax deinstallation function (a Builder action).""" 128 129 # Print out. 130 ############ 131 132 print('') 133 print("######################") 134 print("# Uninstalling relax #") 135 print("######################\n\n") 136 print("Uninstalling the program relax from the directory " + repr(env['INSTALL_PATH']) + "\n\n") 137 138 139 # Tests. 140 ######## 141 142 # Test that the installation path exists. 143 if not access(env['INSTALL_PATH'], F_OK): 144 sys.stderr.write("Cannot uninstall relax, the installation path " + repr(env['INSTALL_PATH']) + " does not exist.\n\n") 145 return 146 147 # Test if the binary directory already exists. 148 if not access(env['BIN_PATH'], F_OK): 149 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['BIN_PATH']) + " does not exist.\n\n") 150 return 151 152 # Test if the relax installation directory exists. 153 if not access(env['RELAX_PATH'], F_OK): 154 sys.stderr.write("Cannot uninstall relax, the directory " + repr(env['RELAX_PATH']) + " does not exist.\n\n") 155 return 156 157 # Test if the symlink exists. 158 if env['SYMLINK_FLAG']: 159 try: 160 lstat(env['SYMLINK']) 161 except OSError: 162 sys.stderr.write("Cannot uninstall relax, the file " + repr(env['SYMLINK']) + " does not exist.\n\n") 163 return 164 165 166 # Uninstall. 167 ############ 168 169 # Remove the symbolic link. 170 if env['SYMLINK_FLAG']: 171 print("\nRemoving the symbolic link " + repr(env['SYMLINK']) + ".") 172 remove(env['SYMLINK']) 173 174 # Remove the directory. 175 print("\nRemoving the entire directory " + repr(env['RELAX_PATH']) + ".\n") 176 for root, dirs, files in walk(env['RELAX_PATH'], topdown=False): 177 for file in files: 178 remove(path.join(root, file)) 179 for file in dirs: 180 rmdir(path.join(root, file)) 181 rmdir(env['RELAX_PATH']) 182 183 # Final printout. 184 print("\n\n\n")
185