-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.py
More file actions
64 lines (54 loc) · 1.87 KB
/
parse.py
File metadata and controls
64 lines (54 loc) · 1.87 KB
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
import os
import sys
#from myshutil import copytree
def cp_layer(src, destbase):
tmp = src[:src.rfind("/")]
if src[src.rfind("/"):] != "/diff" and src[src.rfind("/"):] != "/diff\n":
print("%r"%src[src.rfind("/"):])
assert False
tmp = tmp[tmp.rfind("/"):]
dest = destbase + tmp
#copytree(src, dest, ignore_dangling_symlinks = True)
if src.rfind("\n") != -1:
src = src[:src.rfind("\n")]
order = "cp -r " + src + " " + dest
os.system("mkdir -p " + dest)
os.system(order)
def parse_layers(input_, destbase):
count = 0
index = input_.find(":")
while index != -1:
src = input_[:index]
input_ = input_[index + 1:]
index = input_.find(":")
cp_layer(src, destbase)
src = input_
cp_layer(src, destbase)
def make_image_dir(imagename):
os.system("mkdir -p " + imagename)
def parse_images(filename):
with open(filename, 'r') as f:
for line in f:
words = line.split()
id_ = words[0]
image = words[1]
tag = words[2]
currdir = image + "/" + tag
make_image_dir(currdir)
order = "docker inspect -f '{{.GraphDriver.Data.LowerDir}}:{{.GraphDriver.Data.UpperDir}}' " + id_
result = os.popen(order).read()
parse_layers(result, currdir)
os.system("tar -cvf" + currdir + ".tar " + currdir)
def pull_images(imagename, wd):
os.system("cd " + wd)
os.system("docker pull " + imagename + " --all-tags")
os.system("mkdir -p tmp")
imagefile = "tmp/images.txt"
os.system("docker images --format \"{{.ID}} {{.Repository}} {{.Tag}}\" > " + imagefile)
def main():
assert len(sys.argv) == 3
# pull_images(sys.argv[1], sys.argv[2])
imagefile = "tmp/images.txt"
parse_images(imagefile)
if __name__ == "__main__":
main()