get-developers 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env python3
  2. import argparse
  3. import getdeveloperlib
  4. import sys
  5. def parse_args():
  6. parser = argparse.ArgumentParser()
  7. parser.add_argument('patches', metavar='P', type=argparse.FileType('r'), nargs='*',
  8. help='list of patches (use - to read patches from stdin)')
  9. parser.add_argument('-a', dest='architecture', action='store',
  10. help='find developers in charge of this architecture')
  11. parser.add_argument('-p', dest='package', action='store',
  12. help='find developers in charge of this package')
  13. parser.add_argument('-f', dest='files', nargs='*',
  14. help='find developers in charge of these files')
  15. parser.add_argument('-c', dest='check', action='store_const',
  16. const=True, help='list files not handled by any developer')
  17. parser.add_argument('-e', dest='email', action='store_const',
  18. const=True, help='only list affected developer email addresses')
  19. return parser.parse_args()
  20. def __main__():
  21. args = parse_args()
  22. # Check that only one action is given
  23. action = 0
  24. if args.architecture is not None:
  25. action += 1
  26. if args.package is not None:
  27. action += 1
  28. if args.files:
  29. action += 1
  30. if args.check:
  31. action += 1
  32. if len(args.patches) != 0:
  33. action += 1
  34. if action > 1:
  35. print("Cannot do more than one action")
  36. return
  37. if action == 0:
  38. print("No action specified")
  39. return
  40. devs = getdeveloperlib.parse_developers()
  41. if devs is None:
  42. sys.exit(1)
  43. # Handle the check action
  44. if args.check:
  45. files = getdeveloperlib.check_developers(devs)
  46. for f in files:
  47. print(f)
  48. # Handle the architecture action
  49. if args.architecture is not None:
  50. for dev in devs:
  51. if args.architecture in dev.architectures:
  52. print(dev.name)
  53. return
  54. # Handle the package action
  55. if args.package is not None:
  56. for dev in devs:
  57. if args.package in dev.packages:
  58. print(dev.name)
  59. return
  60. # Handle the files action
  61. if args.files is not None:
  62. for dev in devs:
  63. for f in args.files:
  64. if dev.hasfile(f):
  65. print(dev.name)
  66. break
  67. # Handle the patches action
  68. if len(args.patches) != 0:
  69. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  70. matching_devs = set()
  71. for dev in devs:
  72. # See if we have developers matching by package name
  73. for f in files:
  74. if dev.hasfile(f):
  75. matching_devs.add(dev.name)
  76. # See if we have developers matching by package infra
  77. for i in infras:
  78. if i in dev.infras:
  79. matching_devs.add(dev.name)
  80. if args.email:
  81. for dev in matching_devs:
  82. print(dev)
  83. else:
  84. result = "--to buildroot@buildroot.org"
  85. for dev in matching_devs:
  86. result += " --cc \"%s\"" % dev
  87. if result != "":
  88. print("git send-email %s" % result)
  89. __main__()