mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-20 10:34:30 +00:00
deluge: Fix set default daemon
Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
ff27f1d21b
commit
721e09fee9
@ -20,15 +20,22 @@ Configuration helper for BitTorrent web client.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import fileinput
|
import os
|
||||||
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import augeas
|
import augeas
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
|
|
||||||
|
try:
|
||||||
|
from deluge import config
|
||||||
|
except ImportError:
|
||||||
|
# deluge is not installed or is python2 version
|
||||||
|
config = None
|
||||||
|
|
||||||
DELUGED_DEFAULT_FILE = '/etc/default/deluged'
|
DELUGED_DEFAULT_FILE = '/etc/default/deluged'
|
||||||
DELUGE_WEB_CONFIG_FILE = '/var/lib/deluged/.config/deluge/web.conf'
|
DELUGE_CONF_DIR = '/var/lib/deluged/.config/deluge/'
|
||||||
|
|
||||||
DELUGE_WEB_SYSTEMD_SERVICE_PATH = '/etc/systemd/system/deluge-web.service'
|
DELUGE_WEB_SYSTEMD_SERVICE_PATH = '/etc/systemd/system/deluge-web.service'
|
||||||
DELUGE_WEB_SYSTEMD_SERVICE = '''
|
DELUGE_WEB_SYSTEMD_SERVICE = '''
|
||||||
@ -86,11 +93,18 @@ def _set_configuration(filename, parameter, value):
|
|||||||
if deluge_web_is_running:
|
if deluge_web_is_running:
|
||||||
action_utils.service_stop('deluge-web')
|
action_utils.service_stop('deluge-web')
|
||||||
|
|
||||||
for line in fileinput.FileInput(filename, inplace=True):
|
filepath = os.path.join(DELUGE_CONF_DIR, filename)
|
||||||
if '"{0}"'.format(parameter) in line:
|
if config is None:
|
||||||
print(' "{0}": "{1}", '.format(parameter, value))
|
script = 'from deluge import config;\
|
||||||
else:
|
conf = config.Config(filename="{0}");\
|
||||||
print(line, end='')
|
conf["{1}"] = "{2}";\
|
||||||
|
conf.save()'.format(filepath, parameter, value)
|
||||||
|
subprocess.check_call(['python2', '-c', script])
|
||||||
|
else:
|
||||||
|
conf = config.Config(filename=filepath)
|
||||||
|
conf[parameter] = value
|
||||||
|
conf.save()
|
||||||
|
shutil.chown(filepath, 'debian-deluged', 'debian-deluged')
|
||||||
|
|
||||||
if deluged_is_running:
|
if deluged_is_running:
|
||||||
action_utils.service_start('deluged')
|
action_utils.service_start('deluged')
|
||||||
@ -98,6 +112,21 @@ def _set_configuration(filename, parameter, value):
|
|||||||
action_utils.service_start('deluge-web')
|
action_utils.service_start('deluge-web')
|
||||||
|
|
||||||
|
|
||||||
|
def _get_host_id():
|
||||||
|
"""Get default host id."""
|
||||||
|
if config is None:
|
||||||
|
hosts_conf_file = os.path.join(DELUGE_CONF_DIR, 'hostlist.conf.1.2')
|
||||||
|
script = 'from deluge import config;\
|
||||||
|
conf = config.Config(filename="{0}");\
|
||||||
|
print(conf["hosts"][0][0])'.format(hosts_conf_file)
|
||||||
|
output = subprocess.check_output(['python2', '-c', script]).decode()
|
||||||
|
return output.strip()
|
||||||
|
else:
|
||||||
|
hosts_conf_file = os.path.join(DELUGE_CONF_DIR, 'hostlist.conf')
|
||||||
|
conf = config.Config(filename=hosts_conf_file)
|
||||||
|
return conf["hosts"][0][0]
|
||||||
|
|
||||||
|
|
||||||
def _set_deluged_daemon_options():
|
def _set_deluged_daemon_options():
|
||||||
"""Set deluged daemon options."""
|
"""Set deluged daemon options."""
|
||||||
aug = augeas.Augeas(
|
aug = augeas.Augeas(
|
||||||
@ -130,8 +159,8 @@ def subcommand_setup(_):
|
|||||||
|
|
||||||
# configure deluge-web to autoconnect to the default deluged daemon, also
|
# configure deluge-web to autoconnect to the default deluged daemon, also
|
||||||
# restarts deluged and deluge-web services again to create config files
|
# restarts deluged and deluge-web services again to create config files
|
||||||
_set_configuration(DELUGE_WEB_CONFIG_FILE, 'default_daemon',
|
host_id = _get_host_id()
|
||||||
'127.0.0.1:58846')
|
_set_configuration('web.conf', 'default_daemon', host_id)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|||||||
@ -320,8 +320,20 @@ def _deluge_get_active_window_title(browser):
|
|||||||
def _deluge_ensure_logged_in(browser):
|
def _deluge_ensure_logged_in(browser):
|
||||||
"""Ensure that password dialog is answered and we can interact."""
|
"""Ensure that password dialog is answered and we can interact."""
|
||||||
url = config['DEFAULT']['url'] + '/deluge'
|
url = config['DEFAULT']['url'] + '/deluge'
|
||||||
|
|
||||||
|
def service_is_available():
|
||||||
|
if browser.is_element_present_by_xpath(
|
||||||
|
'//h1[text()="Service Unavailable"]'):
|
||||||
|
access_url(browser, 'deluge')
|
||||||
|
return False
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
if browser.url != url:
|
if browser.url != url:
|
||||||
browser.visit(url)
|
browser.visit(url)
|
||||||
|
# After a backup restore, service may not be available immediately
|
||||||
|
eventually(service_is_available)
|
||||||
|
|
||||||
time.sleep(1) # Wait for Ext.js application in initialize
|
time.sleep(1) # Wait for Ext.js application in initialize
|
||||||
|
|
||||||
if _deluge_get_active_window_title(browser) != 'Login':
|
if _deluge_get_active_window_title(browser) != 'Login':
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user