def read_dir(self, path):
        """
        Reads the given path into the tree
        """
        self.tree = {}
        self.file_count = 0
        self.path = path

        for root, _, filelist in os.walk(path):
            rel = root[len(path):].lstrip('/\\')

            # empty rel, means file is in root dir
            if not rel:
                rel = ' '

            for filename in filelist:
                filename = filename.split('.')
                if len(filename) <= 1:
                    raise RuntimeError("Files without an extension are not supported: {0}".format(
                                       repr(os.path.join(root, '.'.join(filename))),
                                       ))

                ext = filename[-1]
                filename = '.'.join(filename[:-1])

                if ext not in self.tree:
                    self.tree[ext] = {}
                if rel not in self.tree[ext]:
                    self.tree[ext][rel] = []

                self.tree[ext][rel].append(filename)
                self.file_count += 1

        self.tree_length = self.calculate_tree_length()
def read_dir ( self , path ) : self . tree = { } self . file_count = 0 self . path = path for root , _ , filelist in os . walk ( path ) : rel = root [ len ( path ) : ] . lstrip ( '/\\' ) if not rel : rel = ' ' for filename in filelist : filename = filename . split ( '.' ) if len ( filename ) <= 1 : raise RuntimeError ( "Files without an extension are not supported: {0}" . format ( repr ( os . path . join ( root , '.' . join ( filename ) ) ) , ) ) ext = filename [ - 1 ] filename = '.' . join ( filename [ : - 1 ] ) if ext not in self . tree : self . tree [ ext ] = { } if rel not in self . tree [ ext ] : self . tree [ ext ] [ rel ] = [ ] self . tree [ ext ] [ rel ] . append ( filename ) self . file_count += 1 self . tree_length = self . calculate_tree_length ( )
Reads the given path into the tree