mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
deluge: Allow to set a download directory
- add directory selection form to the app configuration page - add debian-deluged user to the freedombox-share group - storage: new validator parameter check-creatable (because deluged is able to create subdirectories) Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
e217a4c87e
commit
8e698987de
8 files changed
+195
-17
No files matched your search
@@ -20,6 +20,7 @@ Configuration helper for BitTorrent web client.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
@@ -80,6 +81,16 @@ def parse_arguments():
|
||||
|
||||
subparsers.add_parser('setup', help='Setup deluge')
|
||||
|
||||
subparsers.add_parser('get-configuration',
|
||||
help='Return the current configuration')
|
||||
|
||||
subparser = subparsers.add_parser('set-configuration',
|
||||
help='Set the configuration parameter')
|
||||
subparser.add_argument('parameter',
|
||||
help='Name of the configuration parameter')
|
||||
subparser.add_argument('value',
|
||||
help='Value of the configuration parameter')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -141,6 +152,29 @@ def _set_deluged_daemon_options():
|
||||
aug.save()
|
||||
|
||||
|
||||
def subcommand_get_configuration(_):
|
||||
"""Return the current deluged configuration in JSON format."""
|
||||
deluged_conf_file = os.path.join(DELUGE_CONF_DIR, 'core.conf')
|
||||
if config is None:
|
||||
script = 'from deluge import config;\
|
||||
conf = config.Config(filename="{0}");\
|
||||
print(conf["download_location"])'.format(deluged_conf_file)
|
||||
output = subprocess.check_output(['python2', '-c', script]).decode()
|
||||
download_location = output.strip()
|
||||
else:
|
||||
conf = config.Config(filename=deluged_conf_file)
|
||||
download_location = conf["download_location"]
|
||||
|
||||
print(json.dumps({'download_location': download_location}))
|
||||
|
||||
|
||||
def subcommand_set_configuration(arguments):
|
||||
"""Set the deluged configuration."""
|
||||
if arguments.parameter != 'download_location':
|
||||
return
|
||||
_set_configuration('core.conf', arguments.parameter, arguments.value)
|
||||
|
||||
|
||||
def subcommand_setup(_):
|
||||
"""Perform initial setup for deluge."""
|
||||
|
||||
|
||||
+25
-4
@@ -56,6 +56,9 @@ def parse_arguments():
|
||||
help='Validate a directory')
|
||||
subparser.add_argument('--path', help='Path of the directory',
|
||||
required=True)
|
||||
subparser.add_argument('--check-creatable', required=False, default=False,
|
||||
action='store_true',
|
||||
help='Check that the directory is creatable')
|
||||
subparser.add_argument('--check-writable', required=False, default=False,
|
||||
action='store_true',
|
||||
help='Check that the directory is writable')
|
||||
@@ -329,14 +332,32 @@ def subcommand_usage_info(_):
|
||||
def subcommand_validate_directory(arguments):
|
||||
"""Validate a directory"""
|
||||
directory = arguments.path
|
||||
if not os.path.exists(directory):
|
||||
print('ValidationError: 1')
|
||||
|
||||
def part_exists(path):
|
||||
"""Returns part of the path that exists."""
|
||||
if not path or os.path.exists(path):
|
||||
return path
|
||||
return part_exists(os.path.dirname(path))
|
||||
|
||||
if arguments.check_creatable:
|
||||
directory = part_exists(directory)
|
||||
if not directory:
|
||||
directory = '.'
|
||||
else:
|
||||
if not os.path.exists(directory):
|
||||
# doesn't exist
|
||||
print('ValidationError: 1')
|
||||
|
||||
if not os.path.isdir(directory):
|
||||
# is not a directory
|
||||
print('ValidationError: 2')
|
||||
if not os.access(directory, os.R_OK):
|
||||
# is not readable
|
||||
print('ValidationError: 3')
|
||||
if arguments.check_writable and not os.access(directory, os.W_OK):
|
||||
print('ValidationError: 4')
|
||||
if arguments.check_writable or arguments.check_creatable:
|
||||
if not os.access(directory, os.W_OK):
|
||||
# is not writable
|
||||
print('ValidationError: 4')
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in new issue
Block a user