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

Contents of /trunk/scons/disttar.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 553 - (show annotations) (download) (as text)
Sat Apr 29 10:01:54 2006 UTC (14 years, 6 months ago) by johnpye
File MIME type: text/x-python
File size: 2365 byte(s)
woops forgot to add new file
1 # vim: set et sw=3 tw=0 fo=awqorc ft=python:
2 #
3 # Astxx, the Asterisk C++ API and Utility Library.
4 # Copyright (C) 2005, 2006 Matthew A. Nicholson
5 #
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License version 2.1 as published by the Free Software Foundation.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 def DistTar(target, source, env):
20 """tar archive builder"""
21
22 import tarfile
23 import os
24
25 env_dict = env.Dictionary()
26
27 if env_dict.has_key("DISTTAR_FORMAT") and env_dict["DISTTAR_FORMAT"] in ["gz", "bz2"]:
28 tar_format = env_dict["DISTTAR_FORMAT"]
29 else:
30 tar_format = ""
31
32 # split the target directory, filename, and stuffix
33 base_name = str(target[0]).split('.tar')[0]
34 (target_dir, dir_name) = os.path.split(base_name)
35
36 # create the target directory if it does not exist
37 if target_dir and not os.path.exists(target_dir):
38 os.makedirs(target_dir)
39
40 # open our tar file for writing
41 tar = tarfile.open(str(target[0]), "w:%s" % (tar_format,))
42
43 # write sources to our tar file
44 for item in source:
45 item = str(item)
46 print "Adding '%s/%s'" % (dir_name, item)
47 tar.add(item, '%s/%s' % (dir_name, item))
48
49 # all done
50 tar.close()
51
52 def DistTarSuffix(env, sources):
53 """tar archive suffix generator"""
54
55 env_dict = env.Dictionary()
56 if env_dict.has_key("DISTTAR_FORMAT") and env_dict["DISTTAR_FORMAT"] in ["gz", "bz2"]:
57 return ".tar." + env_dict["DISTTAR_FORMAT"]
58 else:
59 return ".tar"
60
61 def generate(env):
62 """
63 Add builders and construction variables for the DistTar builder.
64 """
65 env.Append(BUILDERS = {
66 'DistTar': env.Builder(
67 action = DistTar,
68 suffix = DistTarSuffix,
69 target_factory = env.fs.Entry,
70 ),
71 })
72
73 env.AppendUnique(
74 DISTTAR_FORMAT = 'gz',
75 )
76
77 def exists(env):
78 """
79 Make sure this tool exists.
80 """
81 try:
82 import os
83 import tarfile
84 except ImportError:
85 return False
86 else:
87 return True

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