예제 #1
0
파일: utils.py 프로젝트: faushine/RDFS
def getInfoDir(dirPath):
    out = subprocess.Popen(['stat', dirPath],
                           stdout=subprocess.PIPE,
                           stderr=subprocess.STDOUT)
    stdout, stderr = out.communicate()
    res = stdout.decode("utf-8")
    attrs = res.split()
    permission = attrs[2]
    dirNode = int(attrs[3])
    dirOwner = attrs[4]
    groupOwner = attrs[5]
    dirSize = int(attrs[7])
    dirName = attrs[-1].split("/")[-1]
    date = formatDate(res)
    dir = Directory(dirPath, dirName, permission, dirOwner, groupOwner,
                    dirSize, dirNode, date)
    subout = subprocess.Popen(['ls', '-lh', dirPath],
                              stdout=subprocess.PIPE,
                              stderr=subprocess.STDOUT)
    substdout, substderr = subout.communicate()
    if len(substdout) == 0: return dir
    subres = substdout.decode("utf-8").splitlines(True)
    for sub in subres:
        subAttrs = sub.split()
        if subAttrs[0].startswith('d'):
            dir.addDirSub(subAttrs[-1])
    return dir