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

Редакция

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

import os
import os.path

def start(spath):
    """
        this function takes one argument "spath", directory
        which from we should start to search repos
        and returns dict with search result
    """

    repoinf = dict()
    for root, dirs, files in os.walk(spath):
#python2.6`s os.walk() has new param "followsymlinks" and this hack will be removed as soon as possible
        for dname in dirs:
            lrepoinf = dict()      
            if os.path.islink(os.path.join(root, dname)):
                lrepoinf = start(os.path.join(root, dname))
            for cn in lrepoinf:
                if cn in repoinf:
                    for st in lrepoinf[cn]:
                        if st in repoinf[cn]:
                            repoinf[cn][st].add(lrepoinf[cn][st])
                        else:
                            repoinf[cn][st] = lrepoinf[cn][st]
                else:
                    repoinf[cn] = lrepoinf[cn]
        if "Release" in files:
                cn = "" #codename
                st = "" #suite
                rfile = open (os.path.join(root, "Release"))
                for l in rfile:
                    if l.startswith("Codename"):
                        #a little hack, coz of "infra"`s stupid "Codename"s like "interpid-security" instadeof "interpid"
                        cn = l[9:].strip().split("-")[0]
                    elif l.startswith("Suite"):
                        st = l[6:].strip()
                    if len(cn) > 0 and len(st) > 0:
                        if cn in repoinf:
                            if st in repoinf[cn]:
                                repoinf[cn][st].add(root)
                            else:
                                repoinf[cn][st] = set((root, ))
                        else:
                            repoinf[cn] = dict()
                            repoinf[cn][st] = set((root,))
                        break
                rfile.close();
    return repoinf