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

Source Code for Module scons.distrib

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006-2008,2011,2019 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 building the relax distribution packages.""" 
 24   
 25  # Python module imports. 
 26  from os import getcwd, path, sep, system, waitpid, walk 
 27  from re import search 
 28  from subprocess import PIPE, Popen 
 29  import sys 
 30  from tarfile import TarFile 
 31  from zipfile import ZipFile 
 32   
 33  # relax module imports. 
 34  from version import version 
 35   
 36   
 37  # Version control directories to skip. 
 38  VERSION_CONTROL_DIRS = [ 
 39      "\.git", 
 40      "\.hg", 
 41      "\.svn", 
 42  ] 
 43   
 44  # Skip any '.sconsign' files, hidden files, byte-compiled '*.pyc' files, or binary objects '.o', '.os', 'obj', 'lib', and 'exp'. 
 45  BLACKLISTED_FILES = [ 
 46      "\.sconsign", 
 47      "^\.", 
 48      "\.pyc$", 
 49      "\.o$", 
 50      "\.os$", 
 51      "\.obj$", 
 52      "\.lib$", 
 53      "\.exp$", 
 54  ] 
 55   
56 -def gpg_sign(target, source, env):
57 """Builder action for creating a GPG signature of the binary distribution file.""" 58 59 # Print out. 60 print('') 61 print("############################################") 62 print("# GPG signing the binary distribution file #") 63 print("############################################\n\n") 64 65 # List of distribution files. 66 type_list = [env['DIST_TYPE']] 67 if type_list[0] == 'ALL': 68 type_list = ['zip', 'tar'] 69 70 # GPG key. 71 key = env['GPG_KEY'] 72 if key == None: 73 sys.stderr.write("The GPG key needs to be supplied on the command line as key=xxxxx, where xxxxx is the name of your key.\n\n") 74 return 75 76 # Loop over the distribution files. 77 for dist_type in type_list: 78 # The file name. 79 if dist_type == 'zip': 80 file = env['DIST_FILE'] + '.zip' 81 elif dist_type == 'tar': 82 file = env['DIST_FILE'] + '.tar.bz2' 83 elif dist_type == 'dmg': 84 file = env['DIST_FILE'] + '.dmg' 85 86 # Print out. 87 print("\n\nSigning the distribution package " + repr(file) + ".\n") 88 89 # Run the 'gpg' command. 90 system("gpg --detach-sign --default-key " + key + " " + path.pardir + path.sep + file) 91 92 # Final printout. 93 print("\n\n\n")
94 95
96 -def package(target, source, env):
97 """Builder action for packaging the distribution archives.""" 98 99 # Print out. 100 print('') 101 print("#######################") 102 print("# Packaging the files #") 103 print("#######################") 104 105 # List of distribution files. 106 type_list = [env['DIST_TYPE']] 107 if type_list[0] == 'ALL': 108 type_list = ['zip', 'tar'] 109 110 # Loop over the distribution files. 111 for dist_type in type_list: 112 # The file name. 113 if dist_type == 'zip': 114 file = env['DIST_FILE'] + '.zip' 115 elif dist_type == 'tar': 116 file = env['DIST_FILE'] + '.tar.bz2' 117 elif dist_type == 'dmg': 118 file = env['DIST_FILE'] + '.dmg' 119 120 # Print out. 121 print("\n\nCreating the package distribution " + repr(file) + ".\n") 122 123 # Create the special Mac OS X DMG file and then stop execution. 124 if dist_type == 'dmg': 125 # Create the Mac OS X universal application. 126 print("\n# Creating the Mac OS X universal application.\n\n") 127 cmd = '%s setup.py py2app' % sys.executable 128 print("%s\n" % cmd) 129 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False) 130 waitpid(pipe.pid, 0) 131 132 # Create the dmg image. 133 print("\n\n# Creating the DMG image.\n\n") 134 cmd = 'hdiutil create -ov -fs HFS+ -volname "relax" -srcfolder dist/relax.app ../%s' % file 135 print("%s\n" % cmd) 136 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False) 137 waitpid(pipe.pid, 0) 138 139 # Stop executing. 140 return 141 142 # Open the Zip distribution file. 143 if dist_type == 'zip': 144 archive = ZipFile(path.pardir + path.sep + file, 'w', compression=8) 145 146 # Open the Tar distribution file. 147 elif dist_type == 'tar': 148 if search('.bz2$', file): 149 archive = TarFile.bz2open(path.pardir + path.sep + file, 'w') 150 elif search('.gz$', file): 151 archive = TarFile.gzopen(path.pardir + path.sep + file, 'w') 152 else: 153 archive = TarFile.open(path.pardir + path.sep + file, 'w') 154 155 # Base directory. 156 base = getcwd() + sep 157 158 # Find all files untracked by the VC and not ignored. 159 untracked = [] 160 if path.isdir(getcwd() + path.sep + ".git"): 161 cmd = "git ls-files --others --exclude-standard" 162 pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False) 163 for file_name in pipe.stdout.readlines(): 164 untracked.append(file_name.strip()) 165 166 # Walk through the directories. 167 for root, dirs, files in walk(getcwd()): 168 # Skip the version control directories. 169 skip = False 170 for vc in VERSION_CONTROL_DIRS: 171 if search(vc, root): 172 skip = True 173 if skip: 174 continue 175 176 # Add the files in the current directory to the archive. 177 for i in range(len(files)): 178 # Skip all blacklisted files. 179 skip = False 180 for file_name in BLACKLISTED_FILES: 181 if search(file_name, files[i]): 182 skip = True 183 184 # Create the file name (without the base directory). 185 name = path.join(root, files[i]) 186 name = name[len(base):] 187 188 # Skip all untracked files. 189 if name in untracked: 190 skip = True 191 192 # Nothing to do. 193 if skip: 194 continue 195 196 # The archive file name. 197 arcname = 'relax-' + version + path.sep + name 198 print(arcname) 199 200 # Zip archives. 201 if dist_type == 'zip': 202 archive.write(filename=name, arcname=arcname) 203 204 # Tar archives. 205 if dist_type == 'tar': 206 archive.add(name=name, arcname=arcname) 207 208 # Close the archive. 209 archive.close() 210 211 # Final printout. 212 print("\n\n\n")
213