1 | import os
|
---|
2 | import glob
|
---|
3 |
|
---|
4 | def 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 |
|
---|
43 | env.CreateDist = CreateDist
|
---|
44 |
|
---|
45 | def exists(env):
|
---|
46 | try:
|
---|
47 | import os
|
---|
48 | import glob
|
---|
49 | import tarfile
|
---|
50 | except ImportError:
|
---|
51 | return False
|
---|
52 | else:
|
---|
53 | return True
|
---|