def load_tree(cls, path, config, nav_path='', parent=None): """ Load chapters tree recursivelly. """ index_name = config.get('index', cls.INDEX_FILE) files, dirs = [], [] # print ("Load tree: %s, %s" % (path, config)) # scan sub-dirs and files for name in os.listdir(path): full_path = fs.join(path, name) # dirs if fs.isdir(full_path): if not cls.is_name_masked(name): dirs.append(full_path) # files elif fs.isfile(full_path): if cls.is_file_to_render(name): files.append(name) # no index = no data here, but don't give up, try scan deeper! if not index_name in files: cls.load_subdirs(dirs, config, nav_path=nav_path, parent=parent) return # index found = create chapter! initial_title = fs.basename(path).capitalize() chapter = cls(config, title=initial_title, nav_path=nav_path, is_index=True) chapter.load_meta(file_path=fs.join(path, index_name)) files.remove(index_name) # add to parent if parent: parent.add_child(chapter) # load files cls.load_files(path, files, config, nav_path=nav_path, parent=chapter) # load dirs cls.load_subdirs(dirs, config, nav_path=nav_path, parent=chapter) # print ("chapter: %s, files: %s, dirs: %s" % (str(chapter), files, dirs)) return chapter
def cleanup(): """ Cleanup error log. """ if fs.isfile(ERROR_LOGFILE): os.unlink(ERROR_LOGFILE)