get-developers 2.5 KB

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