GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — atc-react/scripts/responseaction.py at master · efeerdur/atc-react Expand file tree/ Copy pathresponseaction.pyMore file actions executable file ·144 lines (109 loc) · 4.73 KB / Copy pathresponseaction.pyFile metadata and controlsexecutable file ·144 lines (109 loc) · 4.73 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 #!/usr/bin/env python3 from jinja2 import Environment, FileSystemLoader import os try: from scripts.reactutils import REACTutils from scripts.react_mapping import rs_mapping env = Environment(loader=FileSystemLoader('scripts/templates')) except: from response.atc_react.scripts.reactutils import REACTutils from response.atc_react.scripts.react_mapping import rs_mapping env = Environment(loader=FileSystemLoader( 'response/atc_react/scripts/templates')) REACTConfig = REACTutils.load_config("config.yml") class ResponseAction: """Class for the Playbook Actions entity""" def __init__(self, yaml_file, apipath=None, auth=None, space=None): """Init method""" # Init vars self.yaml_file = yaml_file self.apipath = apipath self.auth = auth self.space = space # The name of the directory containing future markdown Response_Actions self.parent_title = "Response_Actions" # Init methods self.parse_into_fields(self.yaml_file) def parse_into_fields(self, yaml_file): """Description""" self.ra_parsed_file = REACTutils.read_yaml_file(yaml_file) def render_template(self, template_type): """Description template_type: - "markdown" - "confluence" """ if template_type not in ["markdown", "confluence"]: raise Exception( "Bad template_type. Available values:" + " [\"markdown\", \"confluence\"]") # # PRE: Common for both Markdown and Confluence templates # self.ra_parsed_file.update( {'category': REACTutils.get_ra_category(self.ra_parsed_file .get('id'))} ) self.ra_parsed_file.update( {'description': self.ra_parsed_file.get('description').strip()} ) # Get proper template if template_type == "markdown": template = env.get_template( 'markdown_responseaction_template.md.j2' ) self.ra_parsed_file.update( {'title': REACTutils.normalize_react_title(self.ra_parsed_file .get('title'))} ) stage_list = [] stage = self.ra_parsed_file.get('stage') for rs_id, rs_name in rs_mapping.items(): if REACTutils.normalize_rs_name(stage) == rs_name: stage_list.append((rs_id, rs_name)) self.ra_parsed_file.update( {'stage': stage_list} ) elif template_type == "confluence": template = env.get_template( 'confluence_responseaction_template.html.j2') new_title = self.ra_parsed_file.get('id')\ + ": "\ + REACTutils.normalize_react_title(self.ra_parsed_file.get('title')) self.ra_parsed_file.update( {'title': new_title} ) self.ra_parsed_file.update( {'confluence_viewpage_url': REACTConfig.get('confluence_viewpage_url')}) ## ## Add link to a stage ## stage = self.ra_parsed_file.get('stage') rs_list = [] for rs_id, rs_name in rs_mapping.items(): if REACTutils.normalize_rs_name(stage) == rs_name: if self.apipath and self.auth and self.space: rs_confluence_page_name = rs_id + ": " + rs_name rs_confluence_page_id = str(REACTutils.confluence_get_page_id( self.apipath, self.auth, self.space, rs_confluence_page_name) ) rs_list.append((rs_id, rs_name, rs_confluence_page_id)) else: rs_confluence_page_id = "" rs_list.append((rs_id, rs_name, rs_confluence_page_id)) break self.ra_parsed_file.update( {'stage': rs_list} ) # # POST: Common for both Markdown and Confluence templates # self.content = template.render(self.ra_parsed_file) def save_markdown_file(self, atc_dir=REACTConfig.get('md_name_of_root_directory')): """Write content (md template filled with data) to a file""" base = os.path.basename(self.yaml_file) title = os.path.splitext(base)[0] file_path = atc_dir + self.parent_title + "/" + \ title + ".md" return REACTutils.write_file(file_path, self.content) |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |