get-developers 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. # DEVELOPERS is one level up from here
  23. devs_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..')
  24. devs = getdeveloperlib.parse_developers(devs_dir)
  25. if devs is None:
  26. sys.exit(1)
  27. args = parse_args()
  28. # Check that only one action is given
  29. action = 0
  30. if args.architecture is not None:
  31. action += 1
  32. if args.package is not None:
  33. action += 1
  34. if args.files:
  35. action += 1
  36. if args.check:
  37. action += 1
  38. if len(args.patches) != 0:
  39. action += 1
  40. if action > 1:
  41. print("Cannot do more than one action")
  42. return
  43. if action == 0:
  44. print("No action specified")
  45. return
  46. # Handle the check action
  47. if args.check:
  48. files = getdeveloperlib.check_developers(devs, devs_dir)
  49. for f in files:
  50. print(f)
  51. # Handle the architecture action
  52. if args.architecture is not None:
  53. for dev in devs:
  54. if args.architecture in dev.architectures:
  55. print(dev.name)
  56. return
  57. # Handle the package action
  58. if args.package is not None:
  59. for dev in devs:
  60. if args.package in dev.packages:
  61. print(dev.name)
  62. return
  63. # Handle the files action
  64. if args.files is not None:
  65. args.files = [os.path.abspath(f) for f in args.files]
  66. for dev in devs:
  67. for devfile in dev.files:
  68. commonfiles = [f for f in args.files if f.startswith(devfile)]
  69. if commonfiles:
  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__()