Devuan deployment of britney2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2011 Niels Thykier <niels@thykier.net>
  3. # Copyright (C) 2013 Adam D. Barratt <adam@adam-barratt.org.uk>
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. import readline
  13. import bisect
  14. class Completer(object):
  15. """Completer class
  16. This class provides a readline completer for the britney hint-tester
  17. command-line interface.
  18. """
  19. def __init__(self, britney):
  20. """Constructor
  21. Creates a completer for a given britney.
  22. """
  23. self.matches = []
  24. self.cmds = ['easy', 'hint', 'force-hint', 'force', 'remove',
  25. 'force', 'age-days', 'urgent', 'block-all',
  26. 'block', 'block-udeb', 'unblock', 'unblock-udeb',
  27. 'approve', 'exit', 'quit', 'python-console']
  28. self.britney = britney
  29. suite_info = britney.suite_info
  30. # generate a completion list from excuses.
  31. # - it might contain too many items, but meh
  32. complete = []
  33. tpu = []
  34. for e in britney.excuses.values():
  35. pkg = e.name
  36. suite = suite_info.primary_source_suite.name
  37. if pkg[0] == '-':
  38. suite = suite_info.target_suite.name
  39. pkg = pkg[1:]
  40. if "_" in pkg:
  41. (pkg, suite) = pkg.split("_")
  42. if "/" in pkg:
  43. pkg = pkg.split("/")[0]
  44. name = "%s/%s" % (e.name, suite_info[suite].sources[pkg].version)
  45. complete.append(name)
  46. if suite_info[suite].suite_class.is_additional_source:
  47. tpu.append(name)
  48. self.packages = sorted(complete)
  49. self.tpu_packages = sorted(tpu)
  50. target_suite = suite_info.target_suite.sources
  51. self.testing_packages = sorted("%s/%s" % (pkg, target_suite[pkg].version) for pkg in target_suite)
  52. def completer(self, text, state):
  53. """readline completer (see the readline API)"""
  54. origline = readline.get_line_buffer()
  55. words = origline.split()
  56. if state < 1:
  57. self.matches = []
  58. if len(words) < 1 or words[0] == text:
  59. # complete a command
  60. self.matches = [x for x in self.cmds if x.startswith(text)]
  61. else:
  62. # complete pkg/[arch/]version
  63. if words[0] == 'remove':
  64. packages = self.testing_packages
  65. elif words[0] == 'approve':
  66. packages = self.tpu_packages
  67. else:
  68. packages = self.packages
  69. start = bisect.bisect_left(packages, text)
  70. while start < len(packages):
  71. if not packages[start].startswith(text):
  72. break
  73. self.matches.append(packages[start])
  74. start += 1
  75. if len(self.matches) > state:
  76. return self.matches[state]
  77. return None