2015-12-19 09:05:37 +00:00
|
|
|
|
import os
|
|
|
|
|
import tempfile
|
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
|
|
from irctest.basecontrollers import BaseClientController
|
2016-07-20 09:41:35 +00:00
|
|
|
|
from irctest.basecontrollers import NotImplementedByController
|
2015-12-19 09:05:37 +00:00
|
|
|
|
|
|
|
|
|
TEMPLATE_CONFIG = """
|
|
|
|
|
[core]
|
|
|
|
|
nick = Sopel
|
|
|
|
|
host = {hostname}
|
|
|
|
|
use_ssl = false
|
|
|
|
|
port = {port}
|
|
|
|
|
owner = me
|
|
|
|
|
channels =
|
2015-12-20 09:52:32 +00:00
|
|
|
|
timeout = 5
|
2015-12-19 16:52:38 +00:00
|
|
|
|
auth_username = {username}
|
|
|
|
|
auth_password = {password}
|
|
|
|
|
{auth_method}
|
2015-12-19 09:05:37 +00:00
|
|
|
|
"""
|
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
|
2015-12-19 09:05:37 +00:00
|
|
|
|
class SopelController(BaseClientController):
|
2021-02-22 18:02:13 +00:00
|
|
|
|
software_name = "Sopel"
|
2015-12-20 09:52:32 +00:00
|
|
|
|
supported_sasl_mechanisms = {
|
2021-02-22 18:02:13 +00:00
|
|
|
|
"PLAIN",
|
|
|
|
|
}
|
2021-02-14 21:22:01 +00:00
|
|
|
|
supported_capabilities = set() # Not exhaustive
|
2019-12-08 20:26:21 +00:00
|
|
|
|
|
2021-02-20 09:42:37 +00:00
|
|
|
|
def __init__(self, test_config):
|
|
|
|
|
super().__init__(test_config)
|
2021-02-22 18:02:13 +00:00
|
|
|
|
self.filename = next(tempfile._get_candidate_names()) + ".cfg"
|
2015-12-19 09:05:37 +00:00
|
|
|
|
self.proc = None
|
2021-02-22 18:02:13 +00:00
|
|
|
|
|
2015-12-19 16:52:38 +00:00
|
|
|
|
def kill(self):
|
2015-12-19 09:05:37 +00:00
|
|
|
|
if self.proc:
|
|
|
|
|
self.proc.kill()
|
|
|
|
|
if self.filename:
|
|
|
|
|
try:
|
2021-02-22 18:02:13 +00:00
|
|
|
|
os.unlink(os.path.join(os.path.expanduser("~/.sopel/"), self.filename))
|
|
|
|
|
except OSError: # File does not exist
|
2015-12-19 09:05:37 +00:00
|
|
|
|
pass
|
|
|
|
|
|
2021-02-22 18:02:13 +00:00
|
|
|
|
def open_file(self, filename, mode="a"):
|
|
|
|
|
return open(os.path.join(os.path.expanduser("~/.sopel/"), filename), mode)
|
2015-12-19 09:05:37 +00:00
|
|
|
|
|
|
|
|
|
def create_config(self):
|
|
|
|
|
with self.open_file(self.filename) as fd:
|
|
|
|
|
pass
|
|
|
|
|
|
2016-07-20 09:41:35 +00:00
|
|
|
|
def run(self, hostname, port, auth, tls_config):
|
2015-12-19 09:05:37 +00:00
|
|
|
|
# Runs a client with the config given as arguments
|
2016-07-20 09:41:35 +00:00
|
|
|
|
if tls_config is not None:
|
2021-02-22 18:02:13 +00:00
|
|
|
|
raise NotImplementedByController("TLS configuration")
|
2015-12-19 16:52:38 +00:00
|
|
|
|
assert self.proc is None
|
2015-12-19 09:05:37 +00:00
|
|
|
|
self.create_config()
|
|
|
|
|
with self.open_file(self.filename) as fd:
|
2021-02-22 18:02:13 +00:00
|
|
|
|
fd.write(
|
|
|
|
|
TEMPLATE_CONFIG.format(
|
|
|
|
|
hostname=hostname,
|
|
|
|
|
port=port,
|
|
|
|
|
username=auth.username if auth else "",
|
|
|
|
|
password=auth.password if auth else "",
|
|
|
|
|
auth_method="auth_method = sasl" if auth else "",
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
self.proc = subprocess.Popen(["sopel", "--quiet", "-c", self.filename])
|
|
|
|
|
|
2015-12-19 09:05:37 +00:00
|
|
|
|
|
|
|
|
|
def get_irctest_controller_class():
|
|
|
|
|
return SopelController
|