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