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/responsestage.py at master · efeerdur/atc-react Expand file tree/ Copy pathresponsestage.pyMore file actions executable file ·140 lines (106 loc) · 4.94 KB / Copy pathresponsestage.pyFile metadata and controlsexecutable file ·140 lines (106 loc) · 4.94 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 #!/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 ResponseStage: """Class for the Playbook Stage 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_Stages self.parent_title = "Response_Stages" # Init methods self.parse_into_fields(self.yaml_file) def parse_into_fields(self, yaml_file): """Description""" self.rs_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.rs_parsed_file.update( {'description': self.rs_parsed_file .get('description').strip()} ) ras, ra_paths = REACTutils.load_yamls_with_paths( REACTConfig.get('response_actions_dir')) ra_filenames = [ra_path.split('/')[-1].replace('.yml', '') for ra_path in ra_paths] rs_id = self.rs_parsed_file.get('id') # Get proper template if template_type == "markdown": template = env.get_template( 'markdown_responsestage_template.md.j2' ) stage_list = [] for i in range(len(ras)): if rs_mapping[rs_id] == REACTutils.normalize_rs_name(ras[i].get('stage')): ra_id = ras[i].get('id') ra_filename = ra_filenames[i] ra_title = REACTutils.normalize_react_title(ras[i].get('title')) ra_description = ras[i].get('description').strip() stage_list.append( (ra_id, ra_filename, ra_title, ra_description)) elif template_type == "confluence": template = env.get_template( 'confluence_responsestage_template.html.j2' ) self.rs_parsed_file.update( {'confluence_viewpage_url': REACTConfig.get('confluence_viewpage_url')}) stage_list = [] for i in range(len(ras)): if rs_mapping[rs_id] == REACTutils.normalize_rs_name(ras[i].get('stage')): ra_id = ras[i].get('id') ra_filename = ra_filenames[i] ra_title = REACTutils.normalize_react_title(ras[i].get('title')) ra_description = ras[i].get('description').strip() ra_confluence_page_name = ra_id + ": " + ra_title if self.apipath and self.auth and self.space: ra_confluence_page_id = str(REACTutils.confluence_get_page_id( self.apipath, self.auth, self.space, ra_confluence_page_name) ) else: ra_confluence_page_id = "" stage_list.append( (ra_id, ra_filename, ra_title, ra_description, ra_confluence_page_id)) new_title = self.rs_parsed_file.get('id')\ + ": "\ + REACTutils.normalize_react_title(self.rs_parsed_file.get('title')) self.rs_parsed_file.update( {'title': new_title} ) # # POST: Common for both Markdown and Confluence templates # self.rs_parsed_file.update({'stage_list': sorted(stage_list)}) self.content = template.render(self.rs_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. |