def create_rst_file(dir_path): p = Path(dir_path) relpath = p.relative_to(dir_images) rst_dirpath = Path(dir_here, "99-附录 (Appendix)", "01-常用图标外链查询", relpath) if not rst_dirpath.exists(): rst_dirpath.mkdir() rst_path = Path(rst_dirpath, "index.rst") lines = list() lines.append(p.basename) lines.append("=" * 80) lines.append(".. contents:: 索引") lines.append(" :local:") sub_p_list = Path.sort_by_abspath(dir_path.select_dir(recursive=False)) if len(sub_p_list): lines.append("\n**目录**:\n") lines.append("\n.. articles::\n") for p_png in Path.sort_by_abspath(p.select_image(recursive=False)): lines.append("\n" + p_png.fname) lines.append("-" * 80) url = "/" + str(p_png.relative_to(dir_here)) directive = ".. image:: {}".format(url) lines.append(directive) content = "\n".join(lines) rst_path.write_text(content, "utf-8") if len(sub_p_list): for sub_p in sub_p_list: create_rst_file(sub_p)
def generate_terraform_script(tf_dir): """ This function looking for ``main.tf.tpl``, ``variables.tf.tpl`` files in ``tf_dir``. And use jinja2 template engine to generate the real tf files. It pass in the config object to dynamically inject values. :param tf_dir: terraform workspace directory. """ tf_dir = Path(tf_dir) if not tf_dir.is_dir(): raise TypeError tf_files = ["main", "variables", "backend", "output"] for file in tf_files: tpl_file = Path(tf_dir, file + ".tf.tpl") tf_file = Path(tf_dir, file + ".tf") if tpl_file.exists(): tpl = jinja2.Template(tpl_file.read_text(encoding="utf-8")) content = tpl.render(config=config) tf_file.write_text(content, encoding="utf-8")
tag_property_name_mapper[ aws_object_class. resource_type] = tag_property_name except: pass return tag_property_name_mapper tag_property_name_mapper_cache_file = Path(__file__).change( new_basename="tag_property_name_mapper.json") if tag_property_name_mapper_cache_file.exists(): tag_property_name_mapper = json.loads( tag_property_name_mapper_cache_file.read_text()) else: # pragma: no cover tag_property_name_mapper = get_tag_property_name_mapper() tag_property_name_mapper_cache_file.write_text( json.dumps(tag_property_name_mapper)) def get_tags_attr(resource): """ Quickly find the property name for tags using Cache. :type resource: AWSObject :rtype: str """ return tag_property_name_mapper.get(resource.resource_type) def tags_dct_to_list(dct): return [{"Key": k, "Value": v} for k, v in dct.items()]
# -*- coding: utf-8 -*- import pandas as pd from pathlib_mate import PathCls as Path from wotlkdoc.df_to_list_table import df_to_list_table p = Path(__file__).change(new_basename="Stat-Abbreviation.tsv") df = pd.read_csv(p.abspath, sep="\t") lt = df_to_list_table(df) p = p.change(new_ext=".rst") p.write_text(lt.render(), encoding="utf-8")