Last active
February 7, 2020 21:32
-
-
Save vict0rsch/4592fb499b33abf57706263677f1d621 to your computer and use it in GitHub Desktop.
Revisions
-
vict0rsch renamed this gist
Feb 7, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
vict0rsch created this gist
Feb 7, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,127 @@ from pathlib import Path import re from rstcloth.rstcloth import RstCloth if __name__ == "__main__": conf = Path() / "conf.txt" clusterdest = Path() / "clusterconf.rst" clouddest = Path() / "cloudconf.rst" with conf.open("r") as f: lines = [l.strip() for l in f.readlines()] d = RstCloth() new_lines = [] prev = None should_parse = False do_list = True do_cluster = True do_partitions = True do_cloud = False for i, l in enumerate(lines): if i == 0: continue prev = lines[i - 1] if "# ===" in prev: if "# COMPUTE NODES" in l: should_parse = True # d.h1("Compute Nodes") # d.newline() if not should_parse: prev = l continue if "# Full list" in prev: w = l.replace("# ", "") d.h1("Full List") d.newline() nodes = re.sub("\[.*?\]", "", w).split(",") for node in reversed(nodes): w = w.split(node) ids = w[-1] w = w[0] item = node + ids if item[-1] == ",": item = item[:-1] d.li(item) d.newline() d.h1("Cluster Nodes") # ------------------------- # ----- d.newline() ----- # -------------------------ke do_list = False continue if not do_list and do_cluster: if "# =====" in prev: do_cluster = False d.write(str(clusterdest)) d = RstCloth() d.h1("Cloud Nodes") d.newline() continue if re.match("# [A-Z]+", prev) and do_cluster: title = prev.replace("# ", "").capitalize() d.h2(title) d.newline() k = i while lines[k + 1] and "#" not in lines[k + 1]: k += 1 nodes = lines[i : k + 1] for n in nodes: name = n.split()[0].replace("NodeName=", "") n = n.replace(f"NodeName={name} ", "") items = n.split() d.li(name) d.newline() for item in items: d.li(item.replace("=", ": "), indent=2) d.newline() d.newline() if not do_list and not do_cluster: if "# Cloud Nodes" in l: do_cloud = True print("doing cloud") continue if do_cloud and "# ===" in l and "# Cloud Nodes" not in prev: do_cloud = False continue if ( re.match("# [A-Z]+", prev) and do_cloud and "NodeName" not in prev and "===" not in l ): title = prev.replace("# ", "").capitalize() d.h2(title) d.newline() k = i while lines[k + 1] and "#" not in lines[k + 1]: k += 1 nodes = lines[i : k + 1] for p in nodes: name = p.split()[0].replace("NodeName=", "") p = p.replace(f"NodeName={name} ", "") items = p.split() d.li(name) d.newline() for item in items: d.li(item.replace("=", ": "), indent=2) d.newline() d.newline() d.write(str(clouddest)) with clouddest.open("r") as f: lines = f.read() with clouddest.open("w") as f: f.write(lines.replace("=", "^")) with clusterdest.open("r") as f: lines = f.read() with clusterdest.open("w") as f: f.write(lines.replace("=", "^"))