get-developers 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 devfile in dev.files:
  69. commonfiles = [f for f in args.files if f.startswith(devfile)]
  70. if commonfiles:
  71. print(dev.name)
  72. break
  73. # Handle the patches action
  74. if len(args.patches) != 0:
  75. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  76. matching_devs = set()
  77. for dev in devs:
  78. # See if we have developers matching by package name
  79. for f in files:
  80. if dev.hasfile(f):
  81. matching_devs.add(dev.name)
  82. # See if we have developers matching by package infra
  83. for i in infras:
  84. if i in dev.infras:
  85. matching_devs.add(dev.name)
  86. if args.email:
  87. for dev in matching_devs:
  88. print(dev)
  89. else:
  90. result = "--to buildroot@buildroot.org"
  91. for dev in matching_devs:
  92. result += " --cc \"%s\"" % dev
  93. if result != "":
  94. print("git send-email %s" % result)
  95. __main__()