get-developers 3.5 KB

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