Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # -*- test-case-name: twisted.words.test.test_tap -*-
  2. # Copyright (c) Twisted Matrix Laboratories.
  3. # See LICENSE for details.
  4. """
  5. Shiny new words service maker
  6. """
  7. import socket
  8. import sys
  9. from typing import List, Optional, Sequence
  10. from twisted import plugin
  11. from twisted.application import strports
  12. from twisted.application.service import MultiService
  13. from twisted.cred import checkers, credentials, portal, strcred
  14. from twisted.python import usage
  15. from twisted.words import iwords, service
  16. class Options(usage.Options, strcred.AuthOptionMixin):
  17. supportedInterfaces = [credentials.IUsernamePassword]
  18. optParameters: List[Sequence[Optional[str]]] = [
  19. (
  20. "hostname",
  21. None,
  22. socket.gethostname(),
  23. "Name of this server; purely an informative",
  24. )
  25. ]
  26. compData = usage.Completions(multiUse=["group"])
  27. interfacePlugins = {}
  28. plg = None
  29. for plg in plugin.getPlugins(iwords.IProtocolPlugin):
  30. assert plg.name not in interfacePlugins
  31. interfacePlugins[plg.name] = plg
  32. optParameters.append(
  33. (
  34. plg.name + "-port",
  35. None,
  36. None,
  37. "strports description of the port to bind for the "
  38. + plg.name
  39. + " server",
  40. )
  41. )
  42. del plg
  43. def __init__(self, *a, **kw):
  44. usage.Options.__init__(self, *a, **kw)
  45. self["groups"] = []
  46. def opt_group(self, name):
  47. """Specify a group which should exist"""
  48. self["groups"].append(name.decode(sys.stdin.encoding))
  49. def opt_passwd(self, filename):
  50. """
  51. Name of a passwd-style file. (This is for
  52. backwards-compatibility only; you should use the --auth
  53. command instead.)
  54. """
  55. self.addChecker(checkers.FilePasswordDB(filename))
  56. def makeService(config):
  57. credCheckers = config.get("credCheckers", [])
  58. wordsRealm = service.InMemoryWordsRealm(config["hostname"])
  59. wordsPortal = portal.Portal(wordsRealm, credCheckers)
  60. msvc = MultiService()
  61. # XXX Attribute lookup on config is kind of bad - hrm.
  62. for plgName in config.interfacePlugins:
  63. port = config.get(plgName + "-port")
  64. if port is not None:
  65. factory = config.interfacePlugins[plgName].getFactory(
  66. wordsRealm, wordsPortal
  67. )
  68. svc = strports.service(port, factory)
  69. svc.setServiceParent(msvc)
  70. # This is bogus. createGroup is async. makeService must be
  71. # allowed to return a Deferred or some crap.
  72. for g in config["groups"]:
  73. wordsRealm.createGroup(g)
  74. return msvc