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

Source Code for Module scons.distrib

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