get-developers 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #!/usr/bin/env python
  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('-c', dest='check', action='store_const',
  14. const=True, help='list files not handled by any developer')
  15. return parser.parse_args()
  16. def __main__():
  17. devs = getdeveloperlib.parse_developers()
  18. if devs is None:
  19. sys.exit(1)
  20. args = parse_args()
  21. # Check that only one action is given
  22. action = 0
  23. if args.architecture is not None:
  24. action += 1
  25. if args.package is not None:
  26. action += 1
  27. if args.check:
  28. action += 1
  29. if len(args.patches) != 0:
  30. action += 1
  31. if action > 1:
  32. print("Cannot do more than one action")
  33. return
  34. if action == 0:
  35. print("No action specified")
  36. return
  37. # Handle the check action
  38. if args.check:
  39. files = getdeveloperlib.check_developers(devs)
  40. for f in files:
  41. print(f)
  42. # Handle the architecture action
  43. if args.architecture is not None:
  44. for dev in devs:
  45. if args.architecture in dev.architectures:
  46. print(dev.name)
  47. return
  48. # Handle the package action
  49. if args.package is not None:
  50. for dev in devs:
  51. if args.package in dev.packages:
  52. print(dev.name)
  53. return
  54. # Handle the patches action
  55. if len(args.patches) != 0:
  56. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  57. matching_devs = set()
  58. for dev in devs:
  59. # See if we have developers matching by package name
  60. for f in files:
  61. if dev.hasfile(f):
  62. matching_devs.add(dev.name)
  63. # See if we have developers matching by package infra
  64. for i in infras:
  65. if i in dev.infras:
  66. matching_devs.add(dev.name)
  67. result = "--to buildroot@buildroot.org"
  68. for dev in matching_devs:
  69. result += " --cc \"%s\"" % dev
  70. if result != "":
  71. print("git send-email %s" % result)
  72. __main__()