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

Source Code for Module scons.distrib

  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 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 -def gpg_sign(target, source, env):
38 """Builder action for creating a GPG signature of the binary distribution file.""" 39 40 # Print out. 41 print('') 42 print("############################################") 43 print("# GPG signing the binary distribution file #") 44 print("############################################\n\n") 45 46 # List of distribution files. 47 type_list = [env['DIST_TYPE']] 48 if type_list[0] == 'ALL': 49 type_list = ['zip', 'tar'] 50 51 # GPG key. 52 key = env['GPG_KEY'] 53 if key == None: 54 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") 55 return 56 57 # Loop over the distribution files. 58 for dist_type in type_list: 59 # The file name. 60 if dist_type == 'zip': 61 file = env['DIST_FILE'] + '.zip' 62 elif dist_type == 'tar': 63 file = env['DIST_FILE'] + '.tar.bz2' 64 elif dist_type == 'dmg': 65 file = env['DIST_FILE'] + '.dmg' 66 67 # Print out. 68 print("\n\nSigning the distribution package " + repr(file) + ".\n") 69 70 # Run the 'gpg' command. 71 system("gpg --detach-sign --default-key " + key + " " + path.pardir + path.sep + file) 72 73 # Final printout. 74 print("\n\n\n")
75 76
77 -def package(target, source, env):
78 """Builder action for packaging the distribution archives.""" 79 80 # Print out. 81 print('') 82 print("#######################") 83 print("# Packaging the files #") 84 print("#######################") 85 86 # List of distribution files. 87 type_list = [env['DIST_TYPE']] 88 if type_list[0] == 'ALL': 89 type_list = ['zip', 'tar'] 90 91 # Loop over the distribution files. 92 for dist_type in type_list: 93 # The file name. 94 if dist_type == 'zip': 95 file = env['DIST_FILE'] + '.zip' 96 elif dist_type == 'tar': 97 file = env['DIST_FILE'] + '.tar.bz2' 98 elif dist_type == 'dmg': 99 file = env['DIST_FILE'] + '.dmg' 100 101 # Print out. 102 print("\n\nCreating the package distribution " + repr(file) + ".\n") 103 104 # Create the special Mac OS X DMG file and then stop execution. 105 if dist_type == 'dmg': 106 # Create the Mac OS X universal application. 107 print("\n# Creating the Mac OS X universal application.\n\n") 108 cmd = '%s setup.py py2app' % sys.executable 109 print("%s\n" % cmd) 110 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False) 111 waitpid(pipe.pid, 0) 112 113 # Create the dmg image. 114 print("\n\n# Creating the DMG image.\n\n") 115 cmd = 'hdiutil create -ov -fs HFS+ -volname "relax" -srcfolder dist/relax.app ../%s' % file 116 print("%s\n" % cmd) 117 pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False) 118 waitpid(pipe.pid, 0) 119 120 # Stop executing. 121 return 122 123 # Open the Zip distribution file. 124 if dist_type == 'zip': 125 archive = ZipFile(path.pardir + path.sep + file, 'w', compression=8) 126 127 # Open the Tar distribution file. 128 elif dist_type == 'tar': 129 if search('.bz2$', file): 130 archive = TarFile.bz2open(path.pardir + path.sep + file, 'w') 131 elif search('.gz$', file): 132 archive = TarFile.gzopen(path.pardir + path.sep + file, 'w') 133 else: 134 archive = TarFile.open(path.pardir + path.sep + file, 'w') 135 136 # Base directory. 137 base = getcwd() + sep 138 139 # Walk through the directories. 140 for root, dirs, files in walk(getcwd()): 141 # Skip the subversion directories. 142 if search("\.svn", root): 143 continue 144 145 # Add the files in the current directory to the archive. 146 for i in range(len(files)): 147 # Skip any '.sconsign' files, hidden files, byte-compiled '*.pyc' files, or binary objects '.o', '.os', 'obj', 'lib', and 'exp'. 148 if search("\.sconsign", files[i]) or search("^\.", files[i]) or search("\.pyc$", files[i]) or search("\.o$", files[i]) or search("\.os$", files[i]) or search("\.obj$", files[i]) or search("\.lib$", files[i]) or search("\.exp$", files[i]): 149 continue 150 151 # Create the file name (without the base directory). 152 name = path.join(root, files[i]) 153 name = name[len(base):] 154 print('relax-' + version + path.sep + name) 155 156 # The archive file name. 157 arcname = 'relax-' + version + path.sep + name 158 159 # Zip archives. 160 if dist_type == 'zip': 161 archive.write(filename=name, arcname=arcname) 162 163 # Tar archives. 164 if dist_type == 'tar': 165 archive.add(name=name, arcname=arcname) 166 167 # Close the archive. 168 archive.close() 169 170 # Final printout. 171 print("\n\n\n")
172