get-developers 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. devs = getdeveloperlib.parse_developers()
  23. if devs is None:
  24. sys.exit(1)
  25. args = parse_args()
  26. # Check that only one action is given
  27. action = 0
  28. if args.architecture is not None:
  29. action += 1
  30. if args.package is not None:
  31. action += 1
  32. if args.files:
  33. action += 1
  34. if args.check:
  35. action += 1
  36. if len(args.patches) != 0:
  37. action += 1
  38. if action > 1:
  39. print("Cannot do more than one action")
  40. return
  41. if action == 0:
  42. print("No action specified")
  43. return
  44. # Handle the check action
  45. if args.check:
  46. files = getdeveloperlib.check_developers(devs)
  47. for f in files:
  48. print(f)
  49. # Handle the architecture action
  50. if args.architecture is not None:
  51. for dev in devs:
  52. if args.architecture in dev.architectures:
  53. print(dev.name)
  54. return
  55. # Handle the package action
  56. if args.package is not None:
  57. for dev in devs:
  58. if args.package in dev.packages:
  59. print(dev.name)
  60. return
  61. # Handle the files action
  62. if args.files is not None:
  63. args.files = [os.path.abspath(f) for f in args.files]
  64. for dev in devs:
  65. for devfile in dev.files:
  66. commonfiles = [f for f in args.files if f.startswith(devfile)]
  67. if commonfiles:
  68. print(dev.name)
  69. break
  70. # Handle the patches action
  71. if len(args.patches) != 0:
  72. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  73. matching_devs = set()
  74. for dev in devs:
  75. # See if we have developers matching by package name
  76. for f in files:
  77. if dev.hasfile(f):
  78. matching_devs.add(dev.name)
  79. # See if we have developers matching by package infra
  80. for i in infras:
  81. if i in dev.infras:
  82. matching_devs.add(dev.name)
  83. if args.email:
  84. for dev in matching_devs:
  85. print(dev)
  86. else:
  87. result = "--to buildroot@buildroot.org"
  88. for dev in matching_devs:
  89. result += " --cc \"%s\"" % dev
  90. if result != "":
  91. print("git send-email %s" % result)
  92. __main__()