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

Annotation of /trunk/scons/disttar.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 556 - (hide annotations) (download) (as text)
Tue May 2 01:57:49 2006 UTC (14 years, 5 months ago) by johnpye
File MIME type: text/x-python
File size: 3389 byte(s)
Some fixes to the 'disttar' thing for 'scons dist'
1 johnpye 554 # DistTarBuilder: tool to generate tar files using SCons
2 johnpye 553 # Copyright (C) 2005, 2006 Matthew A. Nicholson
3     #
4 johnpye 554 # This file is free software; you can redistribute it and/or
5 johnpye 553 # modify it under the terms of the GNU Lesser General Public
6     # License version 2.1 as published by the Free Software Foundation.
7     #
8 johnpye 554 # This file is distributed in the hope that it will be useful,
9 johnpye 553 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10     # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11     # Lesser General Public License for more details.
12     #
13     # You should have received a copy of the GNU Lesser General Public
14     # License along with this library; if not, write to the Free Software
15     # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 johnpye 554 #
17     # vim: set et sw=3 tw=0 fo=awqorc ft=python:
18 johnpye 553
19 johnpye 556 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 johnpye 553 def DistTar(target, source, env):
52     """tar archive builder"""
53    
54     import tarfile
55    
56     env_dict = env.Dictionary()
57    
58 johnpye 554 if env_dict.get("DISTTAR_FORMAT") in ["gz", "bz2"]:
59 johnpye 553 tar_format = env_dict["DISTTAR_FORMAT"]
60     else:
61     tar_format = ""
62    
63     # split the target directory, filename, and stuffix
64     base_name = str(target[0]).split('.tar')[0]
65     (target_dir, dir_name) = os.path.split(base_name)
66    
67     # create the target directory if it does not exist
68     if target_dir and not os.path.exists(target_dir):
69     os.makedirs(target_dir)
70    
71     # open our tar file for writing
72     tar = tarfile.open(str(target[0]), "w:%s" % (tar_format,))
73    
74     # write sources to our tar file
75     for item in source:
76 johnpye 556 item = str(item)
77     print "Adding to TAR file: %s/%s" % (dir_name,item)
78     tar.add(item,'%s/%s' % (dir_name,item))
79 johnpye 553
80     # all done
81 johnpye 554 print "Closing TAR file"
82 johnpye 553 tar.close()
83    
84     def DistTarSuffix(env, sources):
85     """tar archive suffix generator"""
86    
87     env_dict = env.Dictionary()
88     if env_dict.has_key("DISTTAR_FORMAT") and env_dict["DISTTAR_FORMAT"] in ["gz", "bz2"]:
89     return ".tar." + env_dict["DISTTAR_FORMAT"]
90     else:
91     return ".tar"
92    
93     def generate(env):
94     """
95     Add builders and construction variables for the DistTar builder.
96     """
97     env.Append(BUILDERS = {
98     'DistTar': env.Builder(
99     action = DistTar,
100     suffix = DistTarSuffix,
101     target_factory = env.fs.Entry,
102 johnpye 556 emitter = disttar_modify_sources
103 johnpye 553 ),
104     })
105    
106     env.AppendUnique(
107 johnpye 554 DISTTAR_FORMAT = 'gz'
108     , DISTTAR_EXCLUDEEXTS = ['.o','.os','.so','.a','.dll','.lib']
109 johnpye 556 , DISTTAR_EXCLUDEDIRS = ['CVS','.svn','.sconf_temp']
110 johnpye 553 )
111    
112     def exists(env):
113     """
114     Make sure this tool exists.
115     """
116     try:
117     import os
118     import tarfile
119     except ImportError:
120     return False
121     else:
122     return True

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