1
|
|
|
from SCons.Script import * |
2
|
|
|
from contextlib import contextmanager |
3
|
|
|
import os, tarfile |
4
|
|
|
|
5
|
|
|
def package_builder(target, source, env): |
6
|
|
|
''' |
7
|
|
|
Performs packaging. |
8
|
|
|
''' |
9
|
|
|
# Remove first directory part of target name, |
10
|
|
|
# so "dist/foo_v1.0" becomes "foo_v1.0" |
11
|
|
|
target_name = str(target[0]).split('/',1)[1] |
12
|
|
|
inclusions = [[str(s), str(s)] for s in source] |
13
|
|
|
exclusion_suffix=[".pyc", ".sqlite", ".orig"] |
14
|
|
|
exclusion_files = [] |
15
|
|
|
exclusion_dirs = [".git"] |
16
|
|
|
|
17
|
|
|
def tarfilter(tarinfo): |
18
|
|
|
fname = tarinfo.name |
19
|
|
|
if tarinfo.isdir(): |
20
|
|
|
for dirname in exclusion_dirs: |
21
|
|
|
# if the filter is "/static", we still want to add "/static-release" |
22
|
|
|
if fname.endswith(dirname) or dirname+os.sep in fname: |
23
|
|
|
print "Skipping directory "+fname |
24
|
|
|
return None |
25
|
|
|
print "Adding directory "+fname |
26
|
|
|
return tarinfo |
27
|
|
|
elif tarinfo.isfile(): |
28
|
|
|
if fname in exclusion_files: |
29
|
|
|
print "Skipping file "+fname |
30
|
|
|
return None |
31
|
|
|
for suffix in exclusion_suffix: |
32
|
|
|
if fname.endswith(suffix): |
33
|
|
|
print "Skipping file "+fname |
34
|
|
|
return None |
35
|
|
|
print "Adding file "+fname |
36
|
|
|
return tarinfo |
37
|
|
|
|
38
|
|
|
tar = tarfile.open(str(target[0])+".tar.gz","w:gz") |
39
|
|
|
for src, dest in inclusions: |
40
|
|
|
tar.add(src, dest, filter=tarfilter) |
41
|
|
|
tar.close() |
42
|
|
|
|
43
|
|
|
packagebuilder = Builder(action=package_builder) |
44
|
|
|
|