Advertisement
Guest User

Untitled

a guest
Mar 1st, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.81 KB | None | 0 0
  1. diff --git a/client.py b/client.py
  2. index 7985113..623aac5 100644
  3. --- a/client.py
  4. +++ b/client.py
  5. @@ -1,5 +1,16 @@
  6. -import click
  7. -import logging
  8. +"""
  9. +Main function of the script.
  10. +Run the script with:
  11. + a. "-a", "--all" or "no argument" - Runs script for all available repositories
  12. + b. "-g", "--git" - Runs script only for repos that are on GitHub
  13. + c. "-h", "--hg" - Runs script only for repos that are on Mercurial
  14. + d. "-m", "--manual" - Let the user choose for which repositories the script
  15. + will run
  16. + e. "-d", "--days" - Let the user choose the amount of days the main markdown
  17. + file will contain
  18. +
  19. +"""
  20. +import sys
  21. from datetime import datetime
  22. from fic_modules.git import create_files_for_git
  23. from fic_modules.hg import create_files_for_hg
  24. @@ -15,98 +26,158 @@ from fic_modules.configuration import (
  25. from fic_modules.markdown_modules import generate_main_md_table
  26.  
  27.  
  28. -@click.group()
  29. -def cli():
  30. - """Firefox-Infra-Changelog: tool which build a
  31. - changelog of commits happening on git or hg that
  32. - could affect Firefox CI Infra"""
  33. +def run_all(logger):
  34. + """
  35. + Runs the script and updates the HG and Git files.
  36. + :param logger:
  37. + :return:
  38. + """
  39. + logger.info("========Logging in ALL mode on %s ========",
  40. + datetime.now())
  41. + create_files_for_git(REPOSITORIES, onerepo=False)
  42. + create_files_for_hg(REPOSITORIES, onerepo=False)
  43. + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  44. + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  45. + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  46. +
  47. +
  48. +def run_git_only(logger):
  49. + """
  50. + Git mode only - Updates only the Git files.
  51. + :param logger:
  52. + :return:
  53. + """
  54. + logger.info("========Logging in GIT mode on %s ========",
  55. + datetime.now())
  56. + create_files_for_git(REPOSITORIES, onerepo=False)
  57. + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  58. + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  59. + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  60. + logger.info("Script ran in GIT Only mode")
  61. +
  62. +
  63. +def run_hg_only(logger):
  64. + """
  65. + Mercurial mode only - Updates only the HG Files.
  66. + :param logger:
  67. + :return:
  68. + """
  69. + logger.info("========Logging in HG mode on %s ========",
  70. + datetime.now())
  71. + create_files_for_hg(REPOSITORIES, onerepo=False)
  72. + clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  73. + generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  74. + generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  75. + logger.info("Script ran in HG Only mode")
  76. +
  77. +
  78. +def extract_scriptrepo_keys(repositories):
  79. + if repositories:
  80. + for scriptrepo in repositories.get("Github").get("build-puppet") \
  81. + .get("configuration").get("files-to-check"):
  82. + REPO_LIST.append(scriptrepo)
  83. + return scriptrepo
  84. +
  85. +
  86. +def run_specific_repo(logger):
  87. + """
  88. + Runs the check for specific repositories. Shows a check menu that let's you
  89. + choose what repositories would you like to update.
  90. + :param logger:
  91. + :return:
  92. + """
  93. + test = get_keys("Github")
  94. + print("Lista key Github:", test)
  95. + get_keys("Mercurial")
  96. + # SCRIPT_REPO = extract_scriptrepo_keys()
  97. + for scriptrepo in REPOSITORIES.get("Github").get("build-puppet") \
  98. + .get("configuration").get("files-to-check"):
  99. + REPO_LIST.append(scriptrepo)
  100. + new_list = []
  101. + while input != "q":
  102. + print("You have selected : ", new_list)
  103. + for keys in REPO_LIST:
  104. + print(REPO_LIST.index(keys) + 1, keys)
  105. +
  106. + user_choice = input("Select a repo by typing it's "
  107. + "number, "
  108. + "type q when you are done: ")
  109. + if str(user_choice) == "q":
  110. + logger.info("========Logging for %s on %s ========",
  111. + str(new_list).strip('[]'), datetime.now())
  112. + for repository in new_list:
  113. + if repository in REPOSITORIES.get("Github"):
  114. + create_files_for_git(repository, onerepo=True)
  115. + generate_main_md_table("git_files",
  116. + GENERATE_FOR_X_DAYS)
  117. + elif repository in REPOSITORIES.get("Mercurial"):
  118. + create_files_for_hg(repository, onerepo=True)
  119. + clear_file("changelog.md",
  120. + GENERATE_FOR_X_DAYS)
  121. + generate_main_md_table("hg_files",
  122. + GENERATE_FOR_X_DAYS)
  123. + generate_main_md_table("git_files",
  124. + GENERATE_FOR_X_DAYS)
  125. + try:
  126. + new_entry = int(user_choice) - 1
  127. + if new_entry < 0 or new_entry >= len(REPO_LIST):
  128. + print('Not Valid')
  129. + else:
  130. + new_list.append(REPO_LIST[int(new_entry)])
  131. + REPO_LIST.pop(int(new_entry))
  132. + except ValueError:
  133. + exit(0)
  134. +
  135. +
  136. +def run_for_days():
  137. + """
  138. + Runs the script with a specific amount of days in mind. Updates both HG and
  139. + Git files for the specified amount of days.
  140. + :return:
  141. + """
  142. pass
  143.  
  144.  
  145. -@cli.command()
  146. -@click.option("--all", flag_value="a",
  147. - help="Run for all currently available repositories")
  148. -@click.option("--git", is_flag=True, flag_value='git',
  149. - help="Run only for GIT repos")
  150. -@click.option("--hg", is_flag=True, flag_value='hg',
  151. - help="Run only for HG repos")
  152. -@click.option("--l", is_flag=True, flag_value="l",
  153. - help="Display logger")
  154. -@click.option("--m", is_flag=True, flag_value="m",
  155. - help="Let you choose for which repositories the script will run")
  156. -def cli(all, git, hg, l, m):
  157. +def main():
  158. from fic_modules.configuration import LOGGER
  159. """
  160. Firefox-Infra-Changelog: tool which build a
  161. changelog of commits happening on git or hg that
  162. - could affect Firefox CI Infra"""
  163. - if l:
  164. - logging.getLogger().addHandler(logging.StreamHandler())
  165. - if all:
  166. - LOGGER.info("========Logging in ALL mode on %s ========",
  167. - datetime.now())
  168. - create_files_for_git(REPOSITORIES, onerepo=False)
  169. - create_files_for_hg(REPOSITORIES, onerepo=False)
  170. - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  171. - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  172. - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  173. - if git:
  174. - LOGGER.info("========Logging in GIT mode on %s ========",
  175. - datetime.now())
  176. - create_files_for_git(REPOSITORIES, onerepo=False)
  177. - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  178. - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  179. - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  180. - click.echo("Script ran in GIT Only mode")
  181. - if hg:
  182. - LOGGER.info("========Logging in HG mode on %s ========",
  183. - datetime.now())
  184. - create_files_for_hg(REPOSITORIES, onerepo=False)
  185. - clear_file("changelog.md", GENERATE_FOR_X_DAYS)
  186. - generate_main_md_table("hg_files", GENERATE_FOR_X_DAYS)
  187. - generate_main_md_table("git_files", GENERATE_FOR_X_DAYS)
  188. - click.echo("Script ran in HG Only mode")
  189. - if m:
  190. - get_keys("Github")
  191. - get_keys("Mercurial")
  192. - for scriptrepo in REPOSITORIES.get("Github").get("build-puppet")\
  193. - .get("configuration").get("files-to-check"):
  194. - REPO_LIST.append(scriptrepo)
  195. - new_list = []
  196. - while input != "q":
  197. - print("You have selected : ", new_list)
  198. - for keys in REPO_LIST:
  199. - print(REPO_LIST.index(keys) + 1, keys)
  200. -
  201. - user_choice = input("Select a repo by typing it's "
  202. - "number, "
  203. - "type q when you are done: ")
  204. - if str(user_choice) == "q":
  205. - LOGGER.info("========Logging for %s on %s ========",
  206. - str(new_list).strip('[]'), datetime.now())
  207. - for repository in new_list:
  208. - if repository in REPOSITORIES.get("Github"):
  209. - create_files_for_git(repository, onerepo=True)
  210. - generate_main_md_table("git_files",
  211. - GENERATE_FOR_X_DAYS)
  212. - elif repository in REPOSITORIES.get("Mercurial"):
  213. - create_files_for_hg(repository, onerepo=True)
  214. - clear_file("changelog.md",
  215. - GENERATE_FOR_X_DAYS)
  216. - generate_main_md_table("hg_files",
  217. - GENERATE_FOR_X_DAYS)
  218. - generate_main_md_table("git_files",
  219. - GENERATE_FOR_X_DAYS)
  220. - try:
  221. - new_entry = int(user_choice) - 1
  222. - if new_entry < 0 or new_entry >= len(REPO_LIST):
  223. - print('Not Valid')
  224. - else:
  225. - new_list.append(REPO_LIST[int(new_entry)])
  226. - REPO_LIST.pop(int(new_entry))
  227. - except ValueError:
  228. - exit(0)
  229. + could affect Firefox CI Infra
  230. + """
  231. + if len(sys.argv) is 1:
  232. + run_all(LOGGER)
  233. +
  234. + if "-a" in sys.argv:
  235. + run_all(LOGGER)
  236. +
  237. + if "--all" in sys.argv:
  238. + run_all(LOGGER)
  239. +
  240. + if "-g" in sys.argv:
  241. + run_git_only(LOGGER)
  242. +
  243. + if "--git" in sys.argv:
  244. + run_git_only(LOGGER)
  245. +
  246. + if "-h" in sys.argv:
  247. + run_hg_only(LOGGER)
  248. +
  249. + if "--hg" in sys.argv:
  250. + run_hg_only(LOGGER)
  251. +
  252. + if "-m" in sys.argv:
  253. + run_specific_repo(LOGGER)
  254. +
  255. + if "--manual" in sys.argv:
  256. + run_specific_repo(LOGGER)
  257. +
  258. + if "-d" in sys.argv:
  259. + run_for_days()
  260. +
  261. + if "--days" in sys.argv:
  262. + run_for_days()
  263.  
  264.  
  265. if __name__ == "__main__":
  266. - cli()
  267. + main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement