2
1

get-developers 3.8 KB

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