summaryrefslogtreecommitdiffstats
path: root/feed/sse_tar.py
blob: 79671f6ec0f92bd60c25415ebdbc8a44e54fc69e (plain)
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
#!/usr/bin/python

import tarfile, zipfile, sys, os
import sse_feed

def archive_uncompress(archive, root, meta = {}):

    f = tarfile.open(archive, "r")

    while True:

        i = f.next()

        if i is None:
            break

        if not i.isreg():
            continue

        if not sse_feed.supported_source(i.name):
            continue

        dst = os.path.join(root, i.name)
        f.extract(i, dst)
        os.utime(dst, (i.mtime, i.mtime))

        sse_feed.process_source(archive, root, i.name, meta)

    del f

def calc_md(fn):
    m = md5.new()
    f = fopen(fn)

    while True:
        data = m.read(1024)

        if len(data) <= 0:
            break

        m.update(data)

    del f

    return m.hexdigest()
        

def process_archive(archive, meta = {}):

    md = calc_md(archive)
    root = os.path.join(HOME, "sources", md)
    
    try:
        os.mkdir(root)
    except:
        pass

    meta["md"] = md
    
    archive_uncompress(archive, root, meta)

if __name__ == "__main__":
    
    archive_uncompress(sys.argv[1])