Ejemplo n.º 1
0
    def scan( self, rootpath=None ) :
        """Scan the rootpath and build the tree."""
        if rootpath :
            self._rootpath = rootpath
            self._root = None
        pathinfos = {}

        sizeColorProvider.reinitFileTree()
        for infopath in os.walk(self._rootpath,False) :
            #print "[%s]" % (pathinfos,)
            (path,subpaths,files) = infopath

            if path == self._rootpath :
                name = path
            else :
                name = os.path.split(path)[1]

            dirInfo = DirInfo( name=name, statInfo=os.lstat(path), tree=self )

            pathinfos[path] = dirInfo

            for file in files :
                completepath = os.path.join(path,file)
                try :
                    fileInfo = FileInfo( name=file, statInfo=os.lstat(completepath), tree=self, parent=dirInfo )
                    dirInfo.insertChild(fileInfo)
                except :
                    pass

            for subpath in subpaths :
                completepath = os.path.join(path,subpath)
                if completepath in pathinfos :
                    # print "[%s] : %d v (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                    dirInfo.insertChild(pathinfos[completepath])
                    # print "[%s] : %d ^ (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                    del pathinfos[completepath]

            dirInfo.finalizeLocal()

            if path == self._rootpath :
                self._root = dirInfo
        # print "[%s]" % (pathinfos,)
        return self._root
Ejemplo n.º 2
0
    def scan( self, rootpath=None ) :
        """Scan the rootpath and build the tree."""
        if rootpath :
            self._rootpath = rootpath
            self._root = None
        pathinfos = {}

        sizeColorProvider.reinitFileTree()

        exclude_list_re = []

        for exclude_item in self._exclude_list :
            exclude_list_re.append(re.compile('^'+str(exclude_item).replace('\\','\\\\').replace('.','\\.').replace('[','\\[').replace(']','\\]').replace('(','\\(').replace(')','\\)').replace('+','\\+').replace('*','.*').replace('?','.')+'$'))

        for exclude_item_re in self._exclude_list_re :
            exclude_list_re.append(re.compile(exclude_item_re))

        for infopath in self.file_provider().walk() :
            #print "[%s]" % (pathinfos,)
            (path,subpaths,files) = infopath

            if path == self._rootpath :
                name = path
            else :
                name = self.file_provider().split(path)[1]

            dirInfo = DirInfo( name=self.file_provider().get_clean_name(name), statInfo=self.file_provider().stat(path), tree=self )

            pathinfos[path] = dirInfo

            for file in files :
                exclude = False
                for exclude_item_re in exclude_list_re :
                    if exclude_item_re.match(file) :
                        exclude = True
                if not(exclude) :
                    completepath = self.file_provider().join(path,file)
                    try :
                        fileInfo = FileInfo( name=self.file_provider().get_clean_name(file), statInfo=self.file_provider().stat(completepath), tree=self, parent=dirInfo )
                        dirInfo.insertChild(fileInfo)
                    except :
                        pass

            for subpath in subpaths :
                exclude = False
                for exclude_item_re in exclude_list_re :
                    if exclude_item_re.match(subpath) :
                        exclude = True
                if not(exclude) :
                    completepath = self.file_provider().join(path,subpath)
                    if completepath in pathinfos :
                        # print "[%s] : %d v (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        dirInfo.insertChild(pathinfos[completepath])
                        # print "[%s] : %d ^ (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        del pathinfos[completepath]

            dirInfo.finalizeLocal()

            if path == self._rootpath :
                self._root = dirInfo
        # print "[%s]" % (pathinfos,)
        return self._root
Ejemplo n.º 3
0
    def scan(self, rootpath=None):
        """Scan the rootpath and build the tree."""
        if rootpath:
            self._rootpath = rootpath
            self._root = None
        pathinfos = {}

        sizeColorProvider.reinitFileTree()

        exclude_list_re = []

        for exclude_item in self._exclude_list:
            exclude_list_re.append(
                re.compile(
                    '^' + str(exclude_item).replace('\\', '\\\\').replace(
                        '.', '\\.').replace('[', '\\[').replace(']', '\\]').
                    replace('(', '\\(').replace(')', '\\)').replace(
                        '+', '\\+').replace('*', '.*').replace('?', '.') +
                    '$'))

        for exclude_item_re in self._exclude_list_re:
            exclude_list_re.append(re.compile(exclude_item_re))

        for infopath in self.file_provider().walk():
            #print "[%s]" % (pathinfos,)
            (path, subpaths, files) = infopath

            if path == self._rootpath:
                name = path
            else:
                name = self.file_provider().split(path)[1]

            dirInfo = DirInfo(name=self.file_provider().get_clean_name(name),
                              statInfo=self.file_provider().stat(path),
                              tree=self)

            pathinfos[path] = dirInfo

            for file in files:
                exclude = False
                for exclude_item_re in exclude_list_re:
                    if exclude_item_re.match(file):
                        exclude = True
                if not (exclude):
                    completepath = self.file_provider().join(path, file)
                    try:
                        fileInfo = FileInfo(
                            name=self.file_provider().get_clean_name(file),
                            statInfo=self.file_provider().stat(completepath),
                            tree=self,
                            parent=dirInfo)
                        dirInfo.insertChild(fileInfo)
                    except:
                        pass

            for subpath in subpaths:
                exclude = False
                for exclude_item_re in exclude_list_re:
                    if exclude_item_re.match(subpath):
                        exclude = True
                if not (exclude):
                    completepath = self.file_provider().join(path, subpath)
                    if completepath in pathinfos:
                        # print "[%s] : %d v (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        dirInfo.insertChild(pathinfos[completepath])
                        # print "[%s] : %d ^ (%s)" % (subpath,pathinfos[completepath].totalArea(),completepath)
                        del pathinfos[completepath]

            dirInfo.finalizeLocal()

            if path == self._rootpath:
                self._root = dirInfo
        # print "[%s]" % (pathinfos,)
        return self._root
Ejemplo n.º 4
0
        outputfile = fname
    elif '-e' in relation[fname]:
        prelistfile = fname
    else:
        desfile = fname

# use dialog to open file
if args == ['-x']:
    path, fname = dialog_get()
    onefile = FileInfo(path, fname)
    print(onefile.char_num())
    print(onefile.line_num())
    print(onefile.word_num([]))
# dealing with the directory
elif desfile != '' and '-s' in relation[desfile]:
    directory = DirInfo(cur_file_dir())
    # determine the type needed
    tmplist = desfile.split('.')
    type = '.' + tmplist[-1]
    # get the required list
    localinfo = directory.build_infolist(type)
    for info in localinfo:
        str = ""
        if '-c' in relation[desfile]:
            print(info.char_num())
            str += info.char_num() + '\n'
        if '-w' in relation[desfile]:
            if prelistfile != "":
                # get the preserved word list
                prelist = get_prelist(prelistfile)
                print(info.word_num(prelist))