-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_tarball.py
executable file
·47 lines (42 loc) · 1.17 KB
/
create_tarball.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
#!/usr/bin/env python
import sys
import os
import glob
import shutil
import subprocess
def sexe(cmd):
print "[sexe:%s]" % cmd
subprocess.call(cmd,shell=True)
def check_remove(name):
if os.path.exists(name):
r = raw_input("%s already exists: remove ? " % name)
if r.lower()[0] == "y":
if os.path.isdir(name):
shutil.rmtree(name)
else:
os.unlink(name)
else:
print "<exiting>"
sys.exit(-1)
def main():
if len(sys.argv) < 2:
print "usage: python create_tarball.py <output-name>"
print "example: "
print " >python create_tarball.py visit-vtk-5.8.a"
sys.exit(1)
odir = sys.argv[1]
otar = odir + ".tar.gz"
check_remove(odir)
check_remove(otar)
os.mkdir(odir)
excludes = [".git",".gitattributes","README.md","create_tarball.py",odir,otar]
flist = glob.glob("*")
flist = [f for f in flist if not f in excludes]
flist = " ".join(flist)
cmd = "cp -r %s %s" % (flist,odir)
sexe(cmd)
cmd = "tar -czf %s %s" % (otar,odir)
sexe(cmd)
shutil.rmtree(odir)
if __name__ == "__main__":
main()