/[ascend]/trunk/scons/accumulate.py
ViewVC logotype

Diff of /trunk/scons/accumulate.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1632 by jpye, Tue Sep 11 13:14:22 2007 UTC revision 1633 by jpye, Thu Oct 11 14:14:24 2007 UTC
# Line 1  Line 1 
1  # AccumulateBuilder  # Accumulate
2  #  #
3  # Based on code from http://www.scons.org/wiki/AccumulateBuilder  # Based on code from http://www.scons.org/wiki/AccumulateBuilder
4    
5    # The goal here was to be able to distribute a source code tarball that
6    # contains all the required source code to build our program, plus a LIMITED
7    # subset of our test/sample code, because we have many sample files that are
8    # not yet ready for distribution. We wanted to manage our list of distributable
9    # files using a simple plain text-file system that would be informative to
10    # end users and not tied to a particular build system (SCons).
11    
12    # This tool faciltates creation of tarballs with some files excluded using
13    # a convenient text-file based mechanism. By default, the tool collects copies
14    # of the files you list using the syntax below, and places them in your
15    # 'destination' directory:
16    #
17    #   env.Accumulate('dist/temp/src',"src")
18    #   env.Accumulate('dist/temp',['prog1.exe','prog2.exe'])
19  #  #
20    # There is a special exception however. If, while recursing into directories
21    # listed in the Accumulate source list, a file named 'PACKAGE' is found, then
22    # only files listed therein will be copied to the destination directory.
23    # The 'PACKAGE' file can contain comment lines; they must begin with a '#'.
24    # Once a directory has been found to contain a 'PACKAGE' file, subdirectories
25    # of that directory will not be recursed into unless they also contain a
26    # 'PACKAGE' file.
27    
28  # Converted to SCons 'tool' format by John Pye, 10 Sept 2007.  # Converted to SCons 'tool' format by John Pye, 10 Sept 2007.
29    
30  import os, os.path, shutil  import os, os.path, shutil
31    import SCons.Node.FS
32    
33  def copypackaged(src,dest, symlinks=False):  def copypackaged(src,dest, symlinks=False):
34      """Recursive copy of files listed in a local file named PACKAGE      """Recursive copy of files listed in a local file named PACKAGE
# Line 30  def copypackaged(src,dest, symlinks=Fals Line 54  def copypackaged(src,dest, symlinks=Fals
54          plist = file(plistfile)          plist = file(plistfile)
55          for line in plist:          for line in plist:
56              l = line.strip()              l = line.strip()
57              if l[0]=="#":              if not len(l) or l[0]=="#":
58                  continue                  continue
59              if l in files:              if l in files:
60                  if os.path.isdir(os.path.join(src,l)):                  if os.path.isdir(os.path.join(src,l)):
# Line 65  def copypackaged(src,dest, symlinks=Fals Line 89  def copypackaged(src,dest, symlinks=Fals
89      print "Leaving directory '%s'" % src      print "Leaving directory '%s'" % src
90    
91            
92  def copytree(src, dest, symlinks=False):  def my_copytree(src, dest, env, symlinks=False):
93      """My own copyTree which does not fail if the directory exists.      """My own copyTree which does not fail if the directory exists.
94    
95      Recursively copy a directory tree using copy2().      Recursively copy a directory tree using copy2().
# Line 94  def copytree(src, dest, symlinks=False): Line 118  def copytree(src, dest, symlinks=False):
118          for item in files:          for item in files:
119              srcPath = os.path.join(src, item)              srcPath = os.path.join(src, item)
120              if os.path.isdir(srcPath):              if os.path.isdir(srcPath):
121                    print "DIR = %s" % srcPath
122                  srcBasename = os.path.basename(srcPath)                  srcBasename = os.path.basename(srcPath)
123                  destDirPath = os.path.join(dest, srcBasename)                  destDirPath = os.path.join(dest, srcBasename)
124                  if not os.path.exists(destDirPath):                  if not os.path.exists(destDirPath):
125                        #print "CREATE DIR %s" % destDirPath
126                      os.makedirs(destDirPath)                      os.makedirs(destDirPath)
127                    #print "RECURSE INTO %s" % srcPath
128                  copyItems(srcPath, destDirPath                  copyItems(srcPath, destDirPath
129                      , use_package_list=use_package_list                      , symlinks
130                  )                  )
131              elif os.path.islink(item) and symlinks:              elif os.path.islink(item) and symlinks:
132                    print "LINK = %s" % srcPath
133                  linkto = os.readlink(item)                  linkto = os.readlink(item)
134                  os.symlink(linkto, dest)                  os.symlink(linkto, dest)
135              else:              else:
136                  shutil.copy2(srcPath, dest)                  print "FILE = %s" % srcPath
137                            shutil.copy2(srcPath, dest)    
138    
139      # case 'cp -R src/ dest/' where dest/ already exists      # case 'cp -R src/ dest/' where dest/ already exists
140      if os.path.exists(dest):      if os.path.exists(dest):
# Line 126  def copytree(src, dest, symlinks=False): Line 154  def copytree(src, dest, symlinks=False):
154  ##  ##
155    
156  def accumulatorFunction(target, source, env):  def accumulatorFunction(target, source, env):
157    """Function called when builder is called"""      """Function called when builder is called"""
158    destDir = str(target[0])      destDir = str(target[0])
159    if not os.path.exists(destDir):      #print "DEST DIR = %s" % destDir
160        os.makedirs(destDir)      if not os.path.exists(destDir):
161    for s in source:          #print "CREATE DIR %s" % destDir
162        s = str(s)          os.makedirs(destDir)
163        if os.path.isdir(s):      #print "SOURCES: %s" % source
164            myShutil.copytree(s, destDir, symlinks = False)      for s in source:
165        else:          s = str(s)
166            shutil.copy2(s, destDir)          if os.path.isdir(s):
167                #print "COPYTREE from source %s" % s
168                my_copytree(s, destDir, env, symlinks = False)
169  ##          else:
170  ## Zipper.py              #print "COPY FILE from source %s" % s
171  ##              shutil.copy2(s, destDir)
 import distutils.archive_util  
   
 def zipperFunction(target, source, env):  
         """Function to use as an action which creates a ZIP file from the arguments"""  
         targetName = str(target[0])  
         sourceDir = str(source[0])  
         distutils.archive_util.make_archive(targetName, 'zip', sourceDir)  
   
172    
173  ##  ##
174  ## register the above builders...  ## register the above builders...
# Line 157  def zipperFunction(target, source, env): Line 177  def zipperFunction(target, source, env):
177  def generate(env):  def generate(env):
178    
179      # add builder to accumulate files      # add builder to accumulate files
180      accuBuilder = env.Builder(action=AccumulatorAction.accumulatorFunction,      accuBuilder = env.Builder(action=accumulatorFunction,
181          source_factory=SCons.Node.FS.default_fs.Entry,          source_factory=SCons.Node.FS.default_fs.Entry,
182          target_factory=SCons.Node.FS.default_fs.Entry,          target_factory=SCons.Node.FS.default_fs.Entry,
183          multi=1)          multi=1)
184      env['BUILDERS']['Accumulate'] = accuBuilder      env['BUILDERS']['Accumulate'] = accuBuilder
185    
     # add builder to zip files  
     zipBuilder = env.Builder(action=Zipper.zipperFunction,  
        source_factory=SCons.Node.FS.default_fs.Entry,  
        target_factory=SCons.Node.FS.default_fs.Entry,  
        multi=0)  
     env['BUILDERS']['Zipper'] = zipBuilder  
   
186  def exists(env):  def exists(env):
187      """      """
188      Make sure this tool exists.      Make sure this tool exists.

Legend:
Removed from v.1632  
changed lines
  Added in v.1633

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22