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

Source Code for Module scons.install

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