def __work(self, read_dir, write_dir): counter = 0 for in_file in read_dir.list_files(): out_file = write_dir.add_file(in_file.get_name(), FileMode.Create) Util.message('Writing', out_file.get_path()) self.bindings.push() self.__set_local_bindings(in_file, read_dir) self.__set_file_bindings(in_file, True) # Load template and replace variables and functions with bindings final = self.__apply_template() out_file.write(final) self.bindings.pop() counter += 1 for read_subdir in read_dir.list_dirs(): write_subdir = write_dir.add_dir(read_subdir.get_name(), FileMode.Create) counter += self.__work(read_subdir, write_subdir) return counter
def run(self): start = time.perf_counter() count = self.__work(self.dirs.pages, self.dirs.out) elapsed = round(time.perf_counter() - start + 0.05, 1) Util.message('Done', '{} {} in {}s' \ .format(count, 'page' if count == 1 else 'pages', elapsed))
def copy_to(self, dst_dir): src = self.path dst = dst_dir.path Util.message('Copy files', 'From {} to {}'.format(src, dst)) shutil.rmtree(dst) shutil.copytree(src, dst)
def process_file(self, in_file, read_dir, template_file, is_stub = False): Util.message('Process', in_file.get_path()) self.bindings.push() # Keep root path relative to the file that invoked the stub if not is_stub: self.__set_local_bindings(in_file, read_dir) self.__set_file_bindings(in_file, True) # Load template and replace variables and functions with bindings final = self.__apply_template(template_file) self.bindings.pop() return final