mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
storage: Directory selection form and validator
Directory selection allows to: - select from default directory - select from available Samba shares - specify subdirectory - insert custom directory - directory validator checks: path exists, is directory, is readable, is writable - samba: action script: include share path in share list - create freedombox-share group inside users module instead of samba module Closes #1703 Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
1 parent
8d51adcc05
commit
ea48f9a74b
5 files changed
+203
-5
No files matched your search
+3
-2
@@ -163,9 +163,10 @@ def _get_shares():
|
||||
config = configparser.ConfigParser()
|
||||
config.read_string(output.decode())
|
||||
for name in config.sections():
|
||||
mount_point = _get_mount_point(config[name]['path'])
|
||||
path = config[name]['path']
|
||||
mount_point = _get_mount_point(path)
|
||||
mount_point = os.path.normpath(mount_point)
|
||||
shares.append(dict(name=name, mount_point=mount_point))
|
||||
shares.append(dict(name=name, mount_point=mount_point, path=path))
|
||||
|
||||
return shares
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ Configuration helper for disks manager.
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -51,6 +52,14 @@ def parse_arguments():
|
||||
subparsers.add_parser('usage-info',
|
||||
help='Get information about disk space usage')
|
||||
|
||||
subparser = subparsers.add_parser('validate-directory',
|
||||
help='Validate a directory')
|
||||
subparser.add_argument('--path', help='Path of the directory',
|
||||
required=True)
|
||||
subparser.add_argument('--check-writable', required=False, default=False,
|
||||
action='store_true',
|
||||
help='Check that the directory is writable')
|
||||
|
||||
subparsers.required = True
|
||||
return parser.parse_args()
|
||||
|
||||
@@ -316,6 +325,19 @@ def subcommand_usage_info(_):
|
||||
subprocess.run(command, check=True)
|
||||
|
||||
|
||||
def subcommand_validate_directory(arguments):
|
||||
"""Validate a directory"""
|
||||
directory = arguments.path
|
||||
if not os.path.exists(directory):
|
||||
print('ValidationError: 1')
|
||||
if not os.path.isdir(directory):
|
||||
print('ValidationError: 2')
|
||||
if not os.access(directory, os.R_OK):
|
||||
print('ValidationError: 3')
|
||||
if arguments.check_writable and not os.access(directory, os.W_OK):
|
||||
print('ValidationError: 4')
|
||||
|
||||
|
||||
def main():
|
||||
"""Parse arguments and perform all duties."""
|
||||
arguments = parse_arguments()
|
||||
|
||||
Reference in new issue
Block a user