-
Notifications
You must be signed in to change notification settings - Fork 6
/
make-pkg.py
executable file
·75 lines (59 loc) · 1.75 KB
/
make-pkg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
"""
make-pkg.py
Package dlcpar for release
"""
import os
import re
import shutil
import sys
from subprocess import call, Popen, PIPE
#=============================================================================
FILES = ["bin",
"examples",
"python/dlcpar",
"setup.py",
"README.md",
"MANUAL.md",
"EXAMPLES.md",
"LICENSE",
"CHANGES"]
EXCLUDE = ["python/dlcpar/commands/view_lct.py",
"python/dlcpar/vis/reconsvg.py",
"examples/getexample.sh",
".*.pyc"]
INCLUDE = []
#=============================================================================
def main():
"""main function"""
pkgdir = sys.argv[1]
if os.path.exists(pkgdir):
shutil.rmtree(pkgdir)
exclude_expr = "|".join(EXCLUDE)
p = Popen(["find", "-L"] + FILES, stdout=PIPE)
all_files = [x.rstrip("\n") for x in p.stdout.readlines()]
all_files = [x for x in all_files
if not re.match(exclude_expr, x)] + INCLUDE
for fn in all_files:
dest = os.path.join(pkgdir, fn)
destdir = os.path.dirname(dest)
print fn, "-->", dest
if os.path.isfile(fn):
# copy file
if not os.path.exists(destdir):
os.makedirs(destdir)
shutil.copy(fn, dest)
else:
# make dir
if not os.path.exists(dest):
os.makedirs(dest)
# tar
basename = os.path.basename(pkgdir)
print ' '.join(
["tar", "-C", os.path.dirname(pkgdir), "-zcvf",
pkgdir + ".tar.gz", basename])
call(
["tar", "-C", os.path.dirname(pkgdir), "-zcvf",
pkgdir + ".tar.gz", basename])
if __name__ == "__main__":
sys.exit(main())