get-developers 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. devs = getdeveloperlib.parse_developers()
  42. if devs is None:
  43. sys.exit(1)
  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. for dev in devs:
  64. for f in args.files:
  65. if dev.hasfile(f):
  66. print(dev.name)
  67. break
  68. # Handle the patches action
  69. if len(args.patches) != 0:
  70. (files, infras) = getdeveloperlib.analyze_patches(args.patches)
  71. matching_devs = set()
  72. for dev in devs:
  73. # See if we have developers matching by package name
  74. for f in files:
  75. if dev.hasfile(f):
  76. matching_devs.add(dev.name)
  77. # See if we have developers matching by package infra
  78. for i in infras:
  79. if i in dev.infras:
  80. matching_devs.add(dev.name)
  81. if args.email:
  82. for dev in matching_devs:
  83. print(dev)
  84. else:
  85. result = "--to buildroot@buildroot.org"
  86. for dev in matching_devs:
  87. result += " --cc \"%s\"" % dev
  88. if result != "":
  89. print("git send-email %s" % result)
  90. __main__()