tested-by.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/python3
  2. """
  3. Put into Public Domain, by Nicolas Sebrecht.
  4. Manage the feedbacks of the testers for the release notes.
  5. """
  6. from os import system
  7. import argparse
  8. from helpers import CACHEDIR, EDITOR, Testers, User, Git
  9. class App():
  10. def __init__(self):
  11. self.args = None
  12. self.testers = Testers()
  13. self.feedbacks = None
  14. def _getTestersByFeedback(self):
  15. if self.feedbacks is not None:
  16. return self.feedbacks
  17. feedbackOk = []
  18. feedbackNo = []
  19. for tester in self.testers.get():
  20. if tester.getFeedback() is True:
  21. feedbackOk.append(tester)
  22. else:
  23. feedbackNo.append(tester)
  24. for array in [feedbackOk, feedbackNo]:
  25. array.sort(key=lambda t: t.getName())
  26. self.feedbacks = feedbackOk + feedbackNo
  27. def parseArgs(self):
  28. parser = argparse.ArgumentParser(description='Manage the feedbacks.')
  29. parser.add_argument('--add', '-a', dest='add_tester',
  30. help='Add tester')
  31. parser.add_argument('--delete', '-d', dest='delete_tester',
  32. type=int,
  33. help='Delete tester NUMBER')
  34. parser.add_argument('--list', '-l', dest='list_all_testers',
  35. action='store_true',
  36. help='List the testers')
  37. parser.add_argument('--switchFeedback', '-s', dest='switch_feedback',
  38. action='store_true',
  39. help='Switch the feedback of a tester')
  40. self.args = parser.parse_args()
  41. def run(self):
  42. if self.args.list_all_testers is True:
  43. self.listTesters()
  44. if self.args.switch_feedback is True:
  45. self.switchFeedback()
  46. elif self.args.add_tester:
  47. self.addTester(self.args.add_tester)
  48. elif type(self.args.delete_tester) == int:
  49. self.deleteTester(self.args.delete_tester)
  50. def addTester(self, strTester):
  51. try:
  52. splitted = strTester.split('<')
  53. name = splitted[0].strip()
  54. email = "<{}".format(splitted[1]).strip()
  55. except Exception as e:
  56. print(e)
  57. print("expected format is: 'Firstname Lastname <email>'")
  58. exit(2)
  59. self.testers.add(name, email)
  60. self.testers.write()
  61. def deleteTester(self, number):
  62. self.listTesters()
  63. removed = self.feedbacks.pop(number)
  64. self.testers.remove(removed)
  65. print("New list:")
  66. self.feedbacks = None
  67. self.listTesters()
  68. print(("Removed: {}".format(removed)))
  69. ans = User.request("Save on disk? (s/Q)").lower()
  70. if ans in ['s']:
  71. self.testers.write()
  72. def listTesters(self):
  73. self._getTestersByFeedback()
  74. count = 0
  75. for tester in self.feedbacks:
  76. feedback = "ok"
  77. if tester.getFeedback() is not True:
  78. feedback = "no"
  79. print(("{:02d} - {} {}: {}".format(
  80. count, tester.getName(), tester.getEmail(), feedback
  81. )
  82. ))
  83. count += 1
  84. def switchFeedback(self):
  85. self._getTestersByFeedback()
  86. msg = "Switch tester: [<number>/s/q]"
  87. self.listTesters()
  88. number = User.request(msg)
  89. while number.lower() not in ['s', 'save', 'q', 'quit']:
  90. if number == '':
  91. continue
  92. try:
  93. number = int(number)
  94. self.feedbacks[number].switchFeedback()
  95. except (ValueError, IndexError) as e:
  96. print(e)
  97. exit(1)
  98. finally:
  99. self.listTesters()
  100. number = User.request(msg)
  101. if number in ['s', 'save']:
  102. self.testers.write()
  103. self.listTesters()
  104. def reset(self):
  105. self.testers.reset()
  106. self.testers.write()
  107. # def updateMailaliases(self):
  108. if __name__ == '__main__':
  109. Git.chdirToRepositoryTopLevel()
  110. app = App()
  111. app.parseArgs()
  112. app.run()