def run(self): try: symlink(os.path.join(SOURCE_DIR, 'pre-commit'), os.path.join(SOURCE_DIR, '.git', 'hooks', 'pre-commit')) except OSError as error: if error.errno != errno.EEXIST: raise
def __build_index(self, app): # pylint: disable=unused-argument html_dir = os.path.join(self.app.output, 'html') search_dir = os.path.join(html_dir, 'assets', 'js', 'search') fragments_dir = os.path.join(search_dir, 'hotdoc_fragments') all_rel_paths = [os.path.relpath(p, html_dir) for p in self.__all_paths] search.create_index(all_rel_paths, multiprocessing.cpu_count() + 1, search_dir, fragments_dir, html_dir, self.app.project.get_private_folder(), os.path.join(HERE, 'stopwords.txt')) subdirs = next(os.walk(html_dir))[1] subdirs.append(html_dir) dumped_trie_path = os.path.join(html_dir, 'dumped.trie') # pylint: disable=unused-variable for root, dirs, files in os.walk(html_dir): for dir_ in dirs: if dir_ == 'assets': continue dest_trie = os.path.join(root, dir_, 'dumped.trie') try: os.remove(dest_trie) except OSError: pass symlink(os.path.relpath( dumped_trie_path, os.path.join(root, dir_)), dest_trie)
def __build_index(self, app): # pylint: disable=unused-argument # pylint: disable=too-many-locals if self.app.incremental: return output = os.path.join(self.app.output, 'html') assets_path = os.path.join(output, 'assets') dest = os.path.join(assets_path, 'js') topdir = os.path.abspath(os.path.join(assets_path, '..')) subdirs = next(os.walk(topdir))[1] subdirs.append(topdir) self.__index.write() dest = os.path.join(topdir, 'dumped.trie') shutil.copyfile( os.path.join(self.project.get_private_folder(), 'search.trie'), dest) # pylint: disable=unused-variable for root, dirs, files in os.walk(topdir): for dir_ in dirs: if dir_ == 'assets': continue dest_trie = os.path.join(root, dir_, 'dumped.trie') try: os.remove(dest_trie) except OSError: pass symlink(os.path.relpath(dest, os.path.join(root, dir_)), dest_trie)
def __build_index(self, app): # pylint: disable=unused-argument # pylint: disable=too-many-locals if self.app.incremental: return output = os.path.join(self.app.output, 'html') assets_path = os.path.join(output, 'assets') dest = os.path.join(assets_path, 'js') topdir = os.path.abspath(os.path.join(assets_path, '..')) subdirs = next(os.walk(topdir))[1] subdirs.append(topdir) exclude_dirs = ['assets'] sources = list_html_files(output, exclude_dirs) stale, unlisted = self.get_stale_files(sources) stale |= unlisted if not stale: return index = SearchIndex(output, dest, self.project.get_private_folder()) index.scan(stale) dest = os.path.join(topdir, 'dumped.trie') shutil.copyfile( os.path.join(self.project.get_private_folder(), 'search.trie'), dest) # pylint: disable=unused-variable for root, dirs, files in os.walk(topdir): for dir_ in dirs: if dir_ == 'assets': continue dest_trie = os.path.join(root, dir_, 'dumped.trie') try: os.remove(dest_trie) except OSError: pass symlink(os.path.relpath(dest, os.path.join(root, dir_)), dest_trie)
def recursive_overwrite(src, dest, ignore=None): """ Banana banana """ if os.path.islink(src): linkto = os.readlink(src) symlink(linkto, dest) elif os.path.isdir(src): if not os.path.isdir(dest): os.makedirs(dest) files = os.listdir(src) if ignore is not None: ignored = ignore(src, files) else: ignored = set() for _ in files: if _ not in ignored: recursive_overwrite(os.path.join(src, _), os.path.join(dest, _), ignore) else: shutil.copyfile(src, dest)
def recursive_overwrite(src, dest, ignore=None): """ Banana banana """ if os.path.islink(src): linkto = os.readlink(src) if os.path.exists(dest): os.remove(dest) symlink(linkto, dest) elif os.path.isdir(src): if not os.path.isdir(dest): os.makedirs(dest) files = os.listdir(src) if ignore is not None: ignored = ignore(src, files) else: ignored = set() for _ in files: if _ not in ignored: recursive_overwrite(os.path.join(src, _), os.path.join(dest, _), ignore) else: shutil.copyfile(src, dest)