source: trunk/scons/utils.py @ 1176

Last change on this file since 1176 was 1176, checked in by mar637, 18 years ago

added CreateDist? to replace disttar. Maybe turn this into an Action

File size: 1.8 KB
Line 
1import os
2import glob
3
4def generate(env):
5    def SGlob(pattern):
6        path = env.GetBuildPath('SConscript').replace('SConscript', '')
7        return [ i.replace(path, '') for i in glob.glob(path + pattern) ]
8    env.SGlob = SGlob
9
10    def AddCustomPath(path=""):
11        if not len(path) or not os.path.exists(path):
12            return
13        env.PrependUnique(CPPPATH = [os.path.join(path, "include")])
14        env.PrependUnique(LIBPATH = [os.path.join(path, "lib")])
15    env.AddCustomPath = AddCustomPath
16
17    def CreateDist(target, sources, descend="stage"):
18        import tarfile
19        base_name = str(target).split('.tar')[0]
20        (target_dir, dir_name) = os.path.split(base_name)
21        # create the target directory if it does not exist
22        if target_dir and not os.path.exists(target_dir):
23            os.makedirs(target_dir)
24        tar_format = "bz2"
25        tar = tarfile.open(str(target)+".tar.bz2", "w:%s" % (tar_format,))
26        if os.path.exists(descend): os.chdir(descend)
27        taritems = []
28        excludedirs = [".svn"]
29        for item in sources:
30            if os.path.isdir(item):
31                for root, dirs, files in os.walk(str(item)):
32                    if not root in excludedirs:
33                        for name in files:
34                            if not name.startswith("."):
35                                taritems.append(os.path.join(root, name))
36            else:
37                taritems.append(item)
38        for item in taritems:
39            print "Adding to archive: %s/%s" % (dir_name, item)
40            tar.add(item,'%s/%s' % (dir_name, item))
41        tar.close()
42        return env.Entry(traget_dir)
43
44    env.CreateDist = CreateDist
45
46def exists(env):
47    try:
48        import os
49        import glob
50        import tarfile
51    except ImportError:
52        return False
53    else:
54        return True
Note: See TracBrowser for help on using the repository browser.