示例#1
0
def tree(path, dirs_only=False, max_depth=0, _depth=0):
    path = Path(path)
    lst = path.lstat()
    is_symlink = stat.S_ISLNK(lst.st_mode)
    st = lst if is_symlink else path.stat()
    is_dir = stat.S_ISDIR(st.st_mode)
    if is_symlink:
        size = 0
    elif is_dir:
        size = functools.reduce(operator.add, [
            tree(p, dirs_only=dirs_only,
                 max_depth=max_depth,
                 _depth=_depth+1)
            for p in sorted(path.iterdir())
        ], 0)
    else:
        size = lst.st_size
    if (is_dir or not dirs_only) and \
       (not max_depth or _depth <= max_depth):
        p = str(path)
        if is_dir:
            p += os.path.sep
        if is_symlink:
            p += ' -> ' + os.readlink(str(path))
        print('%10s  %s' % (format_size(size), p))
    return size
示例#2
0
    def GetCHMod(self):
        filename = self.SOURCELIST.getFilename()
        LL = 0
        LLp = 0
        LLk = 0
        
        try:
            if os.path.isdir(self.SOURCELIST.getFilename()) == True:
                pattern = self.SOURCELIST.getFilename()
            else:
                pattern = self.SOURCELIST.getCurrentDirectory() + self.SOURCELIST.getFilename()
            findResults = []
            findResults.append(pattern)
            self['infoD'].setText('Attributes: ')
            self.fileright = 0
            for file in findResults:
                mode = stat.S_IMODE(os.lstat(file)[stat.ST_MODE])
                for level in ('USR', 'GRP', 'OTH'):
                    for perm in ('R', 'W', 'X'):
                        if mode & getattr(stat, 'S_I' + perm + level):
                            if perm == 'R':
                                LLp = 4
                            
                            if perm == 'W':
                                LLp = 2
                            
                            if perm == 'X':
                                LLp = 1
                            
                        else:
                            LLp = 0
                        if level == 'USR':
                            LLk = 100
                        
                        if level == 'GRP':
                            LLk = 10
                        
                        if level == 'OTH':
                            LLk = 1
                        
                        if perm == 'R':
                            LL = LL + LLp * LLk
                        
                        if perm == 'W':
                            LL = LL + LLp * LLk
                        
                        if perm == 'X':
                            LL = LL + LLp * LLk
                            continue
        except:
            pass

        self['infoD'].setText('Attributes: ' + str(LL))
        self.fileright = LL
示例#3
0
文件: test_search.py 项目: emgee/hype
def setup_module(mod):
    mod.db = he.Database(str(py.test.ensuretemp('test_search.db')))
    mod.db.add_attr_index('@title', he.ESTIDXATTRSTR)
    for path in TESTDATA.listdir():
        if path.basename.startswith('rfc'):
            doc = he.Document(unicode(path.basename))
            stat = path.lstat()
            doc['@cdate'] = unicode(formattime(stat.ctime))
            doc['@mdate'] = unicode(formattime(stat.mtime))
            doc['@size'] = unicode(stat.size)
            doc['@title'] = unicode(path.basename)
            doc.add_text(unicode(path.read(), 'utf-8'))
            mod.db.put_doc(doc)
    db.flush()
    db.sync()
    db.optimize()