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

Source Code for Module scons.distrib

  1  ############################################################################### 
  2  #                                                                             # 
  3  # Copyright (C) 2006 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, walk 
 26  from re import search 
 27  from tarfile import TarFile 
 28  from zipfile import ZipFile 
 29   
 30  # relax version file. 
 31  from version import version 
 32   
 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 # Loop over the distribution files. 50 for dist_type in type_list: 51 # The file name. 52 if dist_type == 'zip': 53 file = env['DIST_FILE'] + '.zip' 54 elif dist_type == 'tar': 55 file = env['DIST_FILE'] + '.tar.bz2' 56 57 # Print out. 58 print "\n\nSigning the distribution package " + `file` + ".\n" 59 60 # Run the 'gpg' command. 61 system("gpg --detach-sign --default-key relax " + path.pardir + path.sep + file) 62 63 # Final print out. 64 print "\n\n\n"
65 66
67 -def package(target, source, env):
68 """Builder action for packaging the distribution archives.""" 69 70 # Print out. 71 print 72 print "#######################" 73 print "# Packaging the files #" 74 print "#######################" 75 76 # List of distribution files. 77 type_list = [env['DIST_TYPE']] 78 if type_list[0] == 'ALL': 79 type_list = ['zip', 'tar'] 80 81 # Loop over the distribution files. 82 for dist_type in type_list: 83 # The file name. 84 if dist_type == 'zip': 85 file = env['DIST_FILE'] + '.zip' 86 elif dist_type == 'tar': 87 file = env['DIST_FILE'] + '.tar.bz2' 88 89 # Print out. 90 print "\n\nCreating the package distribution " + `file` + ".\n" 91 92 # Open the Zip distribution file. 93 if dist_type == 'zip': 94 archive = ZipFile(path.pardir + path.sep + file, 'w', compression=8) 95 96 # Open the Tar distribution file. 97 elif dist_type == 'tar': 98 if search('.bz2$', file): 99 archive = TarFile.bz2open(path.pardir + path.sep + file, 'w') 100 elif search('.gz$', file): 101 archive = TarFile.gzopen(path.pardir + path.sep + file, 'w') 102 else: 103 archive = TarFile.open(path.pardir + path.sep + file, 'w') 104 105 # Base directory. 106 base = getcwd() + sep 107 108 # Walk through the directories. 109 for root, dirs, files in walk(getcwd()): 110 # Skip the subversion directories. 111 if search("\.svn", root): 112 continue 113 114 # Add the files in the current directory to the archive. 115 for i in xrange(len(files)): 116 # Skip any '.sconsign' files, hidden files, byte-compiled '*.pyc' files, or binary objects '.o', '.os', 'obj', 'lib', and 'exp'. 117 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]): 118 continue 119 120 # Create the file name (without the base directory). 121 name = path.join(root, files[i]) 122 name = name[len(base):] 123 print 'relax-' + version + path.sep + name 124 125 # The archive file name. 126 arcname = 'relax-' + version + path.sep + name 127 128 # Zip archives. 129 if dist_type == 'zip': 130 archive.write(filename=name, arcname=arcname) 131 132 # Tar archives. 133 if dist_type == 'tar': 134 archive.add(name=name, arcname=arcname) 135 136 # Close the archive. 137 archive.close() 138 139 # Final print out. 140 print "\n\n\n"
141