Commit 9021e572 authored by coconux's avatar coconux
Browse files

Improve Config file with a str representation

parent 6aeba6c7
Loading
Loading
Loading
Loading
+72 −67
Original line number Diff line number Diff line
@@ -6,53 +6,59 @@ import sys
import yaml
from os import getenv, listdir

class Config:
class Config():
    def __init__(self):
        """Constructor of the config object
        Returns
        -------
        nothing
        """
        # Job variables
    JOBS_DIR = "jobs"
    TOOLS_DIR = "tools"
    JOB_TEMPLATE_DIR = "job_template"
    JOB_DIR = "job_name"
    JOB_YAML = "job.yml"
    JOB_DESCRIPTION_FILE = "README.md"
    JOB_METADATA_FILE = "job.yml"
    JOBS_EXTENSION = ".yml"
    JOB_CHANGELOG_DIR = "versions"
        self.JOBS_DIR = "jobs"
        self.TOOLS_DIR = "tools"
        self.JOB_TEMPLATE_DIR = "job_template"
        self.JOB_DIR = "job_name"
        self.JOB_YAML = "job.yml"
        self.JOB_DESCRIPTION_FILE = "README.md"
        self.JOB_METADATA_FILE = "job.yml"
        self.JOBS_EXTENSION = ".yml"
        self.JOB_CHANGELOG_DIR = "versions"
        # Directory name to use for the jobs screenshot
    SCREENSHOTS_DIR = "screenshots"
    ISSUES_LIMIT = 5
        self.SCREENSHOTS_DIR = "screenshots"
        self.ISSUES_LIMIT = 5

        # Logging
    LOGFILE_NAME = os.getenv("JOB_LOGFILE")
    EXIT_SUCCESS = 0
    EXIT_FAILURE = 1
        self.LOGFILE_NAME = os.getenv("JOB_LOGFILE")
        self.EXIT_SUCCESS = 0
        self.EXIT_FAILURE = 1

        # Mkdocs
    MKDOCS_DIR = "docs"
    MKDOCS_PLACEHOLDER_FILE = "placeholder.md"
    MARKDOWN_EXTENSION = ".md"
        self.MKDOCS_DIR = "docs"
        self.MKDOCS_PLACEHOLDER_FILE = "placeholder.md"
        self.MARKDOWN_EXTENSION = ".md"
        # Path to images used for the built job documentation
    MKDOCS_DIR_JOBS_IMAGES = "images/jobs"
        self.MKDOCS_DIR_JOBS_IMAGES = "images/jobs"

        # Requests variable & API Variables
    GITLAB_BASE_URL = "https://gitlab.com/"
    GITLAB_API_URL = "https://gitlab.com/api/v4/"
    R2DEVOPS_URL = "https://jobs.r2devops.io/"
    PROJECT_NAME = "r2devops/hub"
    JOBS_SCOPE_LABEL = "Jobs::"
    LABEL_COLOR = "fuchsia"
    JOB_TOKEN = getenv("API_TOKEN")
        self.GITLAB_BASE_URL = "https://gitlab.com/"
        self.GITLAB_API_URL = "https://gitlab.com/api/v4/"
        self.R2DEVOPS_URL = "https://jobs.r2devops.io/"
        self.PROJECT_NAME = "r2devops/hub"
        self.JOBS_SCOPE_LABEL = "Jobs::"
        self.LABEL_COLOR = "fuchsia"
        self.JOB_TOKEN = getenv("API_TOKEN")

        # Templates variables
    BUILDER_DIR = "tools/builder"
    TEMPLATE_DIR = "templates"
    TEMPLATE_INDEX = "index.md.j2"
    TEMPLATE_DOC = "job_documentation.md.j2"
    TEMPLATE_PLACEHOLDER = "placeholder.md.j2"
    TEMPLATE_LICENSE_DIR = "licenses"
    INDEX_FILE = "index.md"
        self.BUILDER_DIR = "tools/builder"
        self.TEMPLATE_DIR = "templates"
        self.TEMPLATE_INDEX = "index.md.j2"
        self.TEMPLATE_DOC = "job_documentation.md.j2"
        self.TEMPLATE_PLACEHOLDER = "placeholder.md.j2"
        self.TEMPLATE_LICENSE_DIR = "licenses"
        self.INDEX_FILE = "index.md"

        # List of stages
    INDEX = {
        self.INDEX = {
            "static_tests": {"name":"Static_tests","icon":"🔎","content":[], "description":"Static testing of repository files"},
            "build": {"name":"Build","icon":"🧱","content":[], "description":"Building and packaging of software"},
            "dynamic_tests": {"name":"Dynamic_tests","icon":"🔥","content":[], "description":"Dynamic testing of a running version of the software"},
@@ -64,25 +70,24 @@ class Config:
        }


    def __str__(self):
        """ Print function, return an string representation of the config object
        Returns
        -------
        str
            All keys and values of the config
        """
        return ''.join("%s: %s \n" % item for item in vars(self).items())


if __name__ == "__main__":
    """Main function, iterating over job structures to compare to the tempale one

if __name__ == "__main__":
    """Main function, print all the config
    Returns
    -------
    0
        In case nothing was mismatched
    Number
        Number of jobs that doesn't match the template
    str
        All keys and values of the config
    """
    # Setup logging
    logging.basicConfig(
        encoding="utf-8",
        level=logging.INFO,
        format="%(asctime)s [%(levelname)s] %(message)s",
        handlers=[
            logging.FileHandler(LOGFILE_NAME),
            logging.StreamHandler()
        ]
    )

    config = Config()
    print(config)