Subversion Repositories HelenOS

Rev

Rev 3017 | Rev 3021 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3017 Rev 3019
Line 46... Line 46...
46
    path = os.path.abspath(sys.argv[1]);
46
    path = os.path.abspath(sys.argv[1]);
47
    if (not os.path.isdir(path)):
47
    if (not os.path.isdir(path)):
48
        print "<PATH> must be a directory"
48
        print "<PATH> must be a directory"
49
        return
49
        return
50
   
50
   
-
 
51
    header_size = 18
-
 
52
    payload_size = 0
51
    outf = file(sys.argv[2], "w");
53
    outf = file(sys.argv[2], "w")
-
 
54
    outf.write(struct.pack("<" + ("%d" % header_size) + "x"))
52
   
55
   
53
    for root, dirs, files in os.walk(path):
56
    for root, dirs, files in os.walk(path):
54
        relpath = root[len(path):len(root)]
57
        relpath = root[len(path):len(root)]
55
        for name in files:
58
        for name in files:
56
            canon = os.path.join(relpath, name)
59
            canon = os.path.join(relpath, name)
57
            outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 1, len(canon), canon))
60
            outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 1, len(canon), canon))
-
 
61
            payload_size += 5 + len(canon)
58
           
62
           
59
            fn = os.path.join(root, name)
63
            fn = os.path.join(root, name)
60
            size = os.path.getsize(fn)
64
            size = os.path.getsize(fn)
61
            rd = 0;
65
            rd = 0;
62
            outf.write(struct.pack("<L", size))
66
            outf.write(struct.pack("<L", size))
-
 
67
            payload_size += 4
63
           
68
           
64
            inf = file(fn, "r")
69
            inf = file(fn, "r")
65
            while (rd < size):
70
            while (rd < size):
66
                data = inf.read(4096);
71
                data = inf.read(4096);
67
                outf.write(data)
72
                outf.write(data)
-
 
73
                payload_size += len(data)
68
                rd += len(data)
74
                rd += len(data)
69
            inf.close()
75
            inf.close()
70
       
76
       
71
        for name in dirs:
77
        for name in dirs:
72
            canon = os.path.join(relpath, name)
78
            canon = os.path.join(relpath, name)
73
            outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 2, len(canon), canon))
79
            outf.write(struct.pack("<BL" + ("%d" % len(canon)) + "s", 2, len(canon), canon))
-
 
80
            payload_size += 5 + len(canon)
74
   
81
   
-
 
82
    outf.seek(0)
-
 
83
    outf.write(struct.pack("<4sBBLQ", "HORD", 1, 1, header_size, payload_size))
75
    outf.close()
84
    outf.close()
76
 
85
 
77
if __name__ == '__main__':
86
if __name__ == '__main__':
78
    main()
87
    main()