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

Diff of /trunk/scons/disttar.py

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

revision 554 by johnpye, Tue May 2 00:51:02 2006 UTC revision 556 by johnpye, Tue May 2 01:57:49 2006 UTC
# Line 16  Line 16 
16  #  #
17  # vim: set et sw=3 tw=0 fo=awqorc ft=python:  # vim: set et sw=3 tw=0 fo=awqorc ft=python:
18    
19    import os
20    
21    def disttar_modify_sources(target,source,env):
22    
23        source,origsource = [], source
24    
25        excludeexts = env.Dictionary().get('DISTTAR_EXCLUDEEXTS',[])
26        excludedirs = env.Dictionary().get('DISTTAR_EXCLUDEDIRS',[])
27    
28        # assume the sources are directories... need to check that
29        for item in origsource:
30            for root, dirs, files in os.walk(str(item)):
31    
32                # don't make directory dependences as that triggers full build
33                # of that directory
34                if root in source:
35                    #print "Removing directory %s" % root
36                    source.remove(root)
37    
38                # loop through files in a directory
39                for name in files:
40                    ext = os.path.splitext(name)
41                    if not ext[1] in excludeexts:
42                        relpath = os.path.join(root,name)
43                        #print "Adding source",relpath
44                        source.append(relpath)
45                for d in excludedirs:
46                    if d in dirs:
47                        dirs.remove(d)  # don't visit CVS directories etc
48    
49        return target, source
50    
51  def DistTar(target, source, env):  def DistTar(target, source, env):
52      """tar archive builder"""      """tar archive builder"""
53    
54      import tarfile      import tarfile
     import os  
55    
56      env_dict = env.Dictionary()      env_dict = env.Dictionary()
57    
# Line 40  def DistTar(target, source, env): Line 71  def DistTar(target, source, env):
71      # open our tar file for writing      # open our tar file for writing
72      tar = tarfile.open(str(target[0]), "w:%s" % (tar_format,))      tar = tarfile.open(str(target[0]), "w:%s" % (tar_format,))
73    
     excludeexts = env_dict.get('DISTTAR_EXCLUDEEXTS',[])  
     excludedirs = env_dict.get('DISTTAR_EXCLUDEDIRS',[])  
   
74      # write sources to our tar file      # write sources to our tar file
75      for item in source:      for item in source:
76          for root, dirs, files in os.walk(str(item)):          item = str(item)
77              for name in files:          print "Adding to TAR file: %s/%s" % (dir_name,item)
78                  ext = os.path.splitext(name)          tar.add(item,'%s/%s' % (dir_name,item))
                 if not ext[1] in excludeexts:  
                     relpath = os.path.join(root,name)  
                     #print "Adding %s/%s" %(dir_name,relpath)  
                     tar.add(os.path.join(root,name),'%s/%s' % (dir_name,relpath))  
             for d in excludedirs:  
                 if d in dirs:  
                     dirs.remove(d)  # don't visit CVS directories etc  
79    
80      # all done      # all done
81      print "Closing TAR file"      print "Closing TAR file"
# Line 78  def generate(env): Line 99  def generate(env):
99              action = DistTar,              action = DistTar,
100              suffix = DistTarSuffix,              suffix = DistTarSuffix,
101              target_factory = env.fs.Entry,              target_factory = env.fs.Entry,
102                emitter = disttar_modify_sources
103          ),          ),
104      })      })
105    
106      env.AppendUnique(      env.AppendUnique(
107          DISTTAR_FORMAT = 'gz'          DISTTAR_FORMAT = 'gz'
108          , DISTTAR_EXCLUDEEXTS = ['.o','.os','.so','.a','.dll','.lib']          , DISTTAR_EXCLUDEEXTS = ['.o','.os','.so','.a','.dll','.lib']
109          , DISTTAR_EXCLUDEDIRS = ['CVS','.svn']          , DISTTAR_EXCLUDEDIRS = ['CVS','.svn','.sconf_temp']
110      )      )
111    
112  def exists(env):  def exists(env):

Legend:
Removed from v.554  
changed lines
  Added in v.556

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