Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/client.py b/client.py
- index 7985113..623aac5 100644
- --- a/client.py
- +++ b/client.py
- @@ -1,5 +1,16 @@
- -import click
- -import logging
- +"""
- +Main function of the script.
- +Run the script with:
- + a. "-a", "--all" or "no argument" - Runs script for all available repositories
- + b. "-g", "--git" - Runs script only for repos that are on GitHub
- + c. "-h", "--hg" - Runs script only for repos that are on Mercurial
- + d. "-m", "--manual" - Let the user choose for which repositories the script
- + will run
- + e. "-d", "--days" - Let the user choose the amount of days the main markdown
- + file will contain
- +
- +"""
- +import sys
- from datetime import datetime
- from fic_modules.git import create_files_for_git
- from fic_modules.hg import create_files_for_hg
- @@ -15,98 +26,158 @@ from fic_modules.configuration import (
- from fic_modules.markdown_modules import generate_main_md_table
- -@click.group()
- -def cli():
- - """Firefox-Infra-Changelog: tool which build a
- - changelog of commits happening on git or hg that
- - could affect Firefox CI Infra"""
- +def run_all(logger):
- + """
- + Runs the script and updates the HG and Git files.
- + :param logger:
- + :return:
- + """
- + logger.info("========Logging in ALL mode on %s ========",
- + datetime.now())
- + create_files_for_git(REPOSITORIES, onerepo=False)
- + create_files_for_hg(REPOSITORIES, onerepo=False)
- + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- +
- +
- +def run_git_only(logger):
- + """
- + Git mode only - Updates only the Git files.
- + :param logger:
- + :return:
- + """
- + logger.info("========Logging in GIT mode on %s ========",
- + datetime.now())
- + create_files_for_git(REPOSITORIES, onerepo=False)
- + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- + logger.info("Script ran in GIT Only mode")
- +
- +
- +def run_hg_only(logger):
- + """
- + Mercurial mode only - Updates only the HG Files.
- + :param logger:
- + :return:
- + """
- + logger.info("========Logging in HG mode on %s ========",
- + datetime.now())
- + create_files_for_hg(REPOSITORIES, onerepo=False)
- + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- + logger.info("Script ran in HG Only mode")
- +
- +
- +def extract_scriptrepo_keys(repositories):
- + if repositories:
- + for scriptrepo in repositories.get("Github").get("build-puppet") \
- + .get("configuration").get("files-to-check"):
- + REPO_LIST.append(scriptrepo)
- + return scriptrepo
- +
- +
- +def run_specific_repo(logger):
- + """
- + Runs the check for specific repositories. Shows a check menu that let's you
- + choose what repositories would you like to update.
- + :param logger:
- + :return:
- + """
- + test = get_keys("Github")
- + print("Lista key Github:", test)
- + get_keys("Mercurial")
- + # SCRIPT_REPO = extract_scriptrepo_keys()
- + for scriptrepo in REPOSITORIES.get("Github").get("build-puppet") \
- + .get("configuration").get("files-to-check"):
- + REPO_LIST.append(scriptrepo)
- + new_list = []
- + while input != "q":
- + print("You have selected : ", new_list)
- + for keys in REPO_LIST:
- + print(REPO_LIST.index(keys) + 1, keys)
- +
- + user_choice = input("Select a repo by typing it's "
- + "number, "
- + "type q when you are done: ")
- + if str(user_choice) == "q":
- + logger.info("========Logging for %s on %s ========",
- + str(new_list).strip('[]'), datetime.now())
- + for repository in new_list:
- + if repository in REPOSITORIES.get("Github"):
- + create_files_for_git(repository, onerepo=True)
- + generate_main_md_table("git_files",
- + GENERATE_FOR_X_DAYS)
- + elif repository in REPOSITORIES.get("Mercurial"):
- + create_files_for_hg(repository, onerepo=True)
- + clear_file("changelog.md",
- + GENERATE_FOR_X_DAYS)
- + generate_main_md_table("hg_files",
- + GENERATE_FOR_X_DAYS)
- + generate_main_md_table("git_files",
- + GENERATE_FOR_X_DAYS)
- + try:
- + new_entry = int(user_choice) - 1
- + if new_entry < 0 or new_entry >= len(REPO_LIST):
- + print('Not Valid')
- + else:
- + new_list.append(REPO_LIST[int(new_entry)])
- + REPO_LIST.pop(int(new_entry))
- + except ValueError:
- + exit(0)
- +
- +
- +def run_for_days():
- + """
- + Runs the script with a specific amount of days in mind. Updates both HG and
- + Git files for the specified amount of days.
- + :return:
- + """
- pass
- -@cli.command()
- -@click.option("--all", flag_value="a",
- - help="Run for all currently available repositories")
- -@click.option("--git", is_flag=True, flag_value='git',
- - help="Run only for GIT repos")
- -@click.option("--hg", is_flag=True, flag_value='hg',
- - help="Run only for HG repos")
- -@click.option("--l", is_flag=True, flag_value="l",
- - help="Display logger")
- -@click.option("--m", is_flag=True, flag_value="m",
- - help="Let you choose for which repositories the script will run")
- -def cli(all, git, hg, l, m):
- +def main():
- from fic_modules.configuration import LOGGER
- """
- Firefox-Infra-Changelog: tool which build a
- changelog of commits happening on git or hg that
- - could affect Firefox CI Infra"""
- - if l:
- - logging.getLogger().addHandler(logging.StreamHandler())
- - if all:
- - LOGGER.info("========Logging in ALL mode on %s ========",
- - datetime.now())
- - create_files_for_git(REPOSITORIES, onerepo=False)
- - create_files_for_hg(REPOSITORIES, onerepo=False)
- - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- - if git:
- - LOGGER.info("========Logging in GIT mode on %s ========",
- - datetime.now())
- - create_files_for_git(REPOSITORIES, onerepo=False)
- - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- - click.echo("Script ran in GIT Only mode")
- - if hg:
- - LOGGER.info("========Logging in HG mode on %s ========",
- - datetime.now())
- - create_files_for_hg(REPOSITORIES, onerepo=False)
- - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
- - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
- - click.echo("Script ran in HG Only mode")
- - if m:
- - get_keys("Github")
- - get_keys("Mercurial")
- - for scriptrepo in REPOSITORIES.get("Github").get("build-puppet")\
- - .get("configuration").get("files-to-check"):
- - REPO_LIST.append(scriptrepo)
- - new_list = []
- - while input != "q":
- - print("You have selected : ", new_list)
- - for keys in REPO_LIST:
- - print(REPO_LIST.index(keys) + 1, keys)
- -
- - user_choice = input("Select a repo by typing it's "
- - "number, "
- - "type q when you are done: ")
- - if str(user_choice) == "q":
- - LOGGER.info("========Logging for %s on %s ========",
- - str(new_list).strip('[]'), datetime.now())
- - for repository in new_list:
- - if repository in REPOSITORIES.get("Github"):
- - create_files_for_git(repository, onerepo=True)
- - generate_main_md_table("git_files",
- - GENERATE_FOR_X_DAYS)
- - elif repository in REPOSITORIES.get("Mercurial"):
- - create_files_for_hg(repository, onerepo=True)
- - clear_file("changelog.md",
- - GENERATE_FOR_X_DAYS)
- - generate_main_md_table("hg_files",
- - GENERATE_FOR_X_DAYS)
- - generate_main_md_table("git_files",
- - GENERATE_FOR_X_DAYS)
- - try:
- - new_entry = int(user_choice) - 1
- - if new_entry < 0 or new_entry >= len(REPO_LIST):
- - print('Not Valid')
- - else:
- - new_list.append(REPO_LIST[int(new_entry)])
- - REPO_LIST.pop(int(new_entry))
- - except ValueError:
- - exit(0)
- + could affect Firefox CI Infra
- + """
- + if len(sys.argv) is 1:
- + run_all(LOGGER)
- +
- + if "-a" in sys.argv:
- + run_all(LOGGER)
- +
- + if "--all" in sys.argv:
- + run_all(LOGGER)
- +
- + if "-g" in sys.argv:
- + run_git_only(LOGGER)
- +
- + if "--git" in sys.argv:
- + run_git_only(LOGGER)
- +
- + if "-h" in sys.argv:
- + run_hg_only(LOGGER)
- +
- + if "--hg" in sys.argv:
- + run_hg_only(LOGGER)
- +
- + if "-m" in sys.argv:
- + run_specific_repo(LOGGER)
- +
- + if "--manual" in sys.argv:
- + run_specific_repo(LOGGER)
- +
- + if "-d" in sys.argv:
- + run_for_days()
- +
- + if "--days" in sys.argv:
- + run_for_days()
- if __name__ == "__main__":
- - cli()
- + main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement