get-developers 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #!/usr/bin/env python3
  2. import argparse
  3. import getdeveloperlib
  4. import sys
  5. def __main__():
  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('--cc', action="store_true",
  18. help='list affected developers as CC: lines ready to be pasted in a commit log')
  19. parser.add_argument('-e', dest='email', action='store_const',
  20. const=True, help='only list affected developer email addresses')
  21. parser.add_argument('-v', dest='validate', action='store_const',
  22. const=True, help='validate syntax of DEVELOPERS file')
  23. parser.add_argument('-d', dest='filename', action='store', default=None,
  24. help='override the default DEVELOPERS file (for debug)')
  25. args = parser.parse_args()
  26. # Check that only one action is given
  27. action = 0
  28. if args.architecture is not None:
  29. action += 1
  30. if args.package is not None:
  31. action += 1
  32. if args.files:
  33. action += 1
  34. if args.check:
  35. action += 1
  36. if args.validate:
  37. action += 1
  38. if len(args.patches) != 0:
  39. action += 1
  40. if action > 1:
  41. parser.error("Cannot do more than one action")
  42. if action == 0:
  43. if sys.stdin.isatty():
  44. parser.error("No action specified")
  45. args.patches.append(sys.stdin)
  46. devs = getdeveloperlib.parse_developers(args.filename)
  47. if devs is None:
  48. sys.exit(1)
  49. # Validation is done by parse_developers() above and we error out
  50. # if the validation didn't work, so if we reach here, it means
  51. # validation passed, so we can simply bail out in success.
  52. if args.validate:
  53. return
  54. # Handle the check action
  55. if args.check:
  56. files = getdeveloperlib.check_developers(devs)
  57. for f in files:
  58. print(f)
  59. # Handle the architecture action
  60. if args.architecture is not None:
  61. for dev in devs:
  62. if args.architecture in dev.architectures:
  63. print(dev.name)
  64. return
  65. # Handle the package action
  66. if args.package is not None:
  67. for dev in devs:
  68. if args.package in dev.packages:
  69. print(dev.name)
  70. return
  71. # Handle the files action
  72. if args.files is not None:
  73. for dev in devs:
  74. for f in args.files:
  75. if dev.hasfile(f):
  76. print(dev.name)
  77. break
  78. # Handle the patches action
  79. if len(args.patches) != 0:
  80. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  81. matching_devs = set()
  82. for dev in devs:
  83. # See if we have developers matching by package name
  84. for f in files:
  85. if dev.hasfile(f):
  86. matching_devs.add(dev.name)
  87. # See if we have developers matching by package infra
  88. for i in infras:
  89. if i in dev.infras:
  90. matching_devs.add(dev.name)
  91. matching_devs = sorted(matching_devs)
  92. if args.email or args.cc:
  93. for dev in matching_devs:
  94. print(f"{'Cc: ' if args.cc else ''}{dev}")
  95. else:
  96. result = "--to buildroot@buildroot.org"
  97. for dev in matching_devs:
  98. result += " --cc \"%s\"" % dev
  99. if result != "":
  100. print("git send-email %s" % result)
  101. __main__()