forked from Otorhin/Ren2Switch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_private.py
55 lines (34 loc) · 1.13 KB
/
generate_private.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
import tarfile
import os
def make_tar(fn, source_dirs):
# source_dirs = [ plat.path(i) for i in source_dirs ]
"""
Turns a relative path into an absolute path relative to the RAPT
directory.
"""
tf = tarfile.open(fn, "w:gz", format=tarfile.GNU_FORMAT)
added = set()
def add(fn, relfn):
adds = []
while relfn:
adds.append((fn, relfn))
fn = os.path.dirname(fn)
relfn = os.path.dirname(relfn)
adds.reverse()
for fn, relfn in adds:
if relfn not in added:
added.add(relfn)
tf.add(fn, relfn, recursive=False)
for sd in source_dirs:
sd = os.path.abspath(sd)
for dir, dirs, files in os.walk(sd): # @ReservedAssignment
for _fn in dirs:
fn = os.path.join(dir, _fn)
relfn = os.path.relpath(fn, sd)
add(fn, relfn)
for fn in files:
fn = os.path.join(dir, fn)
relfn = os.path.relpath(fn, sd)
add(fn, relfn)
tf.close()
make_tar("private.mp3", ["private"])