# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):
# 
# Path: quads/tools/create_input.py
# HEADERS = [
#     "U",
#     "ServerHostnamePublic",
#     "Serial",
#     "MAC",
#     "IP",
#     "IPMIADDR",
#     "IPMIURL",
#     "IPMIMAC",
#     "Workload",
#     "Owner",
# ]
# def consolidate_ipmi_data(_host, _path, _value):
# def render_header(_rack):
# def render_row(_host, _properties):
# def rack_has_hosts(rack, hosts):
# def main():
# 
# Path: quads/tools/create_input_assignments.py
# HEADERS = [
#     "ServerHostnamePublic",
#     "OutOfBand",
#     "DateStartAssignment",
#     "DateEndAssignment",
#     "TotalDuration",
#     "TimeRemaining",
# ]
# def print_header():
# def print_summary():
# def print_unmanaged(hosts):
# def print_faulty(broken_hosts):
# def add_row(host):
# def main():
# 
# Path: quads/tools/wiki.py
# class Wiki:
#     def __init__(self, url, username, password):
#         """
#         Wiki object initialization
# 
#         :param url: wordpress url
#         :param username: wordpress username
#         :param password: wordpress password
#         """
#         self.url = url
#         self.username = username
#         self.password = password
#         self.endpoint = os.path.join(self.url, "xmlrpc.php")
# 
#         scheme = urlparse(self.url)[0]
#         if scheme == "https":
#             ssl._create_default_https_context = ssl._create_unverified_context
# 
#     def update(self, _page_title, _page_id, _markdown):
#         """
#         Update an existing wordpress page with generated markdown.
#         Assumes you have a markdown file with content you want published
#         to an existing wordpress page.
#         :param _page_title: post page title
#         :param _page_id: post page id
#         :param _markdown: path to markdown file for upload
#         """
# 
#         wp = Client(self.endpoint, self.username, self.password)
# 
#         # define pages variable
#         page = WordPressPage()
#         page.title = _page_title
# 
#         # page id can be found by viewing via wp-admin dashboard in URL
#         page.id = _page_id
# 
#         # set local content file to read handle info into a string
#         with open(_markdown, "r") as _file:
#             page.content = _file.read()
# 
#         # post new content to the page
#         wp.call(EditPost(page.id, page))
# 
# Path: quads/tools/regenerate_vlans_wiki.py
# def regenerate_vlans_wiki():
#     wp_url = Config["wp_wiki"]
#     wp_username = Config["wp_username"]
#     wp_password = Config["wp_password"]
#     page_title = Config["wp_wiki_vlans_title"]
#     page_id = Config["wp_wiki_vlans_page_id"]
#     with NamedTemporaryFile(mode="w+t") as _markdown:
#         render_header(_markdown)
#         render_vlans(_markdown)
#         _markdown.seek(0)
#         try:
#             wiki = Wiki(
#                 wp_url, wp_username, wp_password
#             )
#             wiki.update(
#                 page_title, page_id, _markdown.name
#             )
#         except ProtocolError as ex:
#             logger.error(ex.errmsg)


import logging
import os
from datetime import datetime
from xmlrpc.client import ProtocolError
from git import Repo, InvalidGitRepositoryError
from quads.config import Config
from quads.tools import create_input, create_input_assignments
from quads.tools.wiki import Wiki
from quads.tools.regenerate_vlans_wiki import regenerate_vlans_wiki
#!/usr/bin/python3


wp_wiki = Config["wp_wiki"]
wp_username = Config["wp_username"]
wp_password = Config["wp_password"]
wp_wiki_main_title = Config["wp_wiki_main_title"]
wp_wiki_main_page_id = Config["wp_wiki_main_page_id"]
wp_wiki_assignments_title = Config["wp_wiki_assignments_title"]
wp_wiki_assignments_page_id = Config["wp_wiki_assignments_page_id"]
wp_wiki_git_manage = Config["wp_wiki_git_manage"]
wp_wiki_git_repo_path = Config["wp_wiki_git_repo_path"]

logger = logging.getLogger(__name__)

if __name__ == "__main__":

    create_input.main()
    main_md = os.path.join(wp_wiki_git_repo_path, "main.md")

# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):
# 
# Path: quads/tools/create_input.py
# HEADERS = [
#     "U",
#     "ServerHostnamePublic",
#     "Serial",
#     "MAC",
#     "IP",
#     "IPMIADDR",
#     "IPMIURL",
#     "IPMIMAC",
#     "Workload",
#     "Owner",
# ]
# def consolidate_ipmi_data(_host, _path, _value):
# def render_header(_rack):
# def render_row(_host, _properties):
# def rack_has_hosts(rack, hosts):
# def main():
# 
# Path: quads/tools/create_input_assignments.py
# HEADERS = [
#     "ServerHostnamePublic",
#     "OutOfBand",
#     "DateStartAssignment",
#     "DateEndAssignment",
#     "TotalDuration",
#     "TimeRemaining",
# ]
# def print_header():
# def print_summary():
# def print_unmanaged(hosts):
# def print_faulty(broken_hosts):
# def add_row(host):
# def main():
# 
# Path: quads/tools/wiki.py
# class Wiki:
#     def __init__(self, url, username, password):
#         """
#         Wiki object initialization
# 
#         :param url: wordpress url
#         :param username: wordpress username
#         :param password: wordpress password
#         """
#         self.url = url
#         self.username = username
#         self.password = password
#         self.endpoint = os.path.join(self.url, "xmlrpc.php")
# 
#         scheme = urlparse(self.url)[0]
#         if scheme == "https":
#             ssl._create_default_https_context = ssl._create_unverified_context
# 
#     def update(self, _page_title, _page_id, _markdown):
#         """
#         Update an existing wordpress page with generated markdown.
#         Assumes you have a markdown file with content you want published
#         to an existing wordpress page.
#         :param _page_title: post page title
#         :param _page_id: post page id
#         :param _markdown: path to markdown file for upload
#         """
# 
#         wp = Client(self.endpoint, self.username, self.password)
# 
#         # define pages variable
#         page = WordPressPage()
#         page.title = _page_title
# 
#         # page id can be found by viewing via wp-admin dashboard in URL
#         page.id = _page_id
# 
#         # set local content file to read handle info into a string
#         with open(_markdown, "r") as _file:
#             page.content = _file.read()
# 
#         # post new content to the page
#         wp.call(EditPost(page.id, page))
# 
# Path: quads/tools/regenerate_vlans_wiki.py
# def regenerate_vlans_wiki():
#     wp_url = Config["wp_wiki"]
#     wp_username = Config["wp_username"]
#     wp_password = Config["wp_password"]
#     page_title = Config["wp_wiki_vlans_title"]
#     page_id = Config["wp_wiki_vlans_page_id"]
#     with NamedTemporaryFile(mode="w+t") as _markdown:
#         render_header(_markdown)
#         render_vlans(_markdown)
#         _markdown.seek(0)
#         try:
#             wiki = Wiki(
#                 wp_url, wp_username, wp_password
#             )
#             wiki.update(
#                 page_title, page_id, _markdown.name
#             )
#         except ProtocolError as ex:
#             logger.error(ex.errmsg)


# Path: quads/tools/regenerate_wiki.py
import logging
import os
from datetime import datetime
from xmlrpc.client import ProtocolError
from git import Repo, InvalidGitRepositoryError
from quads.config import Config
from quads.tools import create_input, create_input_assignments
from quads.tools.wiki import Wiki
from quads.tools.regenerate_vlans_wiki import regenerate_vlans_wiki

#!/usr/bin/python3


wp_wiki = Config["wp_wiki"]
wp_username = Config["wp_username"]
wp_password = Config["wp_password"]
wp_wiki_main_title = Config["wp_wiki_main_title"]
wp_wiki_main_page_id = Config["wp_wiki_main_page_id"]
wp_wiki_assignments_title = Config["wp_wiki_assignments_title"]
wp_wiki_assignments_page_id = Config["wp_wiki_assignments_page_id"]
wp_wiki_git_manage = Config["wp_wiki_git_manage"]
wp_wiki_git_repo_path = Config["wp_wiki_git_repo_path"]

logger = logging.getLogger(__name__)

if __name__ == "__main__":

    create_input.main()
    main_md = os.path.join(wp_wiki_git_repo_path, "main.md")

    if wp_wiki_git_manage: