Хранилища Subversion apt-scan

Редакция

Содержимое файла | Последнее изменение | Открыть журнал | RSS

Редакция Автор № строки Строка
2 ddosia 1
import os
2
import os.path
3
 
4
def start(spath):
5
    """
6
        this function takes one argument "spath", directory
7
        which from we should start to search repos
8
        and returns dict with search result
9
    """
10
    repoinf = dict()
11
    for root, dirs, files in os.walk(spath):
12
#python2.6`s os.walk() has new param "followsymlinks" and this hack will be removed as soon as possible
13
        for dname in dirs:
14
            lrepoinf = dict()      
15
            if os.path.islink(os.path.join(root, dname)):
16
                lrepoinf = start(os.path.join(root, dname))
17
            for cn in lrepoinf:
18
                if cn in repoinf:
19
                    for st in lrepoinf[cn]:
20
                        if st in repoinf[cn]:
21
                            repoinf[cn][st].add(lrepoinf[cn][st])
22
                        else:
23
                            repoinf[cn][st] = lrepoinf[cn][st]
24
                else:
25
                    repoinf[cn] = lrepoinf[cn]
26
        if "Release" in files:
27
                cn = "" #codename
28
                st = "" #suite
29
                rfile = open (os.path.join(root, "Release"))
30
                for l in rfile:
31
                    if l.startswith("Codename"):
32
                        #a little hack, coz of "infra"`s stupid "Codename"s like "interpid-security" instadeof "interpid"
33
                        cn = l[9:].strip().split("-")[0]
34
                    elif l.startswith("Suite"):
35
                        st = l[6:].strip()
36
                    if len(cn) > 0 and len(st) > 0:
37
                        if cn in repoinf:
38
                            if st in repoinf[cn]:
39
                                repoinf[cn][st].add(root)
40
                            else:
41
                                repoinf[cn][st] = set((root, ))
42
                        else:
43
                            repoinf[cn] = dict()
44
                            repoinf[cn][st] = set((root,))
45
                        break
46
                rfile.close();
47
    return repoinf
48