mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-03-11 09:04:54 +00:00
config: rename functions (improve readability)
Idem for apache component. See !1952. Signed-off-by: Fioddor Superconcentrado <fioddor@gmail.com> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
337e8c28dd
commit
ec870a1766
@ -70,17 +70,17 @@ def setup(helper, old_version=None):
|
||||
# (U)ser (W)eb (S)ites
|
||||
|
||||
|
||||
def uws_usr2dir(user):
|
||||
def uws_directory_of_user(user):
|
||||
"""Returns the directory of the given user's website."""
|
||||
return '/home/{}/public_html'.format(user)
|
||||
|
||||
|
||||
def uws_usr2url(user):
|
||||
def uws_url_of_user(user):
|
||||
"""Returns the url path of the given user's website."""
|
||||
return '/~{}/'.format(user)
|
||||
|
||||
|
||||
def uws_dir2usr(directory):
|
||||
def user_of_uws_directory(directory):
|
||||
"""Returns the user of a given user website directory."""
|
||||
if directory.startswith('/home/'):
|
||||
pos_ini = 6
|
||||
@ -97,7 +97,7 @@ def uws_dir2usr(directory):
|
||||
return user if is_valid_user_name(user) else None
|
||||
|
||||
|
||||
def uws_url2usr(url):
|
||||
def user_of_uws_url(url):
|
||||
"""Returns the user of a given user website url path."""
|
||||
MISSING = -1
|
||||
|
||||
@ -113,20 +113,20 @@ def uws_url2usr(url):
|
||||
return user if is_valid_user_name(user) else None
|
||||
|
||||
|
||||
def uws_url2dir(url):
|
||||
def uws_directory_of_url(url):
|
||||
"""Returns the directory of the user's website for the given url path.
|
||||
|
||||
Note: It doesn't return the full OS file path to the url path!
|
||||
"""
|
||||
return uws_usr2dir(uws_url2usr(url))
|
||||
return uws_directory_of_user(user_of_uws_url(url))
|
||||
|
||||
|
||||
def uws_dir2url(directory):
|
||||
def uws_url_of_directory(directory):
|
||||
"""Returns the url base path of the user's website for the given OS path.
|
||||
|
||||
Note: It doesn't return the url path for the file!
|
||||
"""
|
||||
return uws_usr2url(uws_dir2usr(directory))
|
||||
return uws_url_of_user(user_of_uws_directory(directory))
|
||||
|
||||
|
||||
def get_users_with_website():
|
||||
@ -140,6 +140,7 @@ def get_users_with_website():
|
||||
]
|
||||
|
||||
return {
|
||||
name: uws_usr2url(name)
|
||||
for name in lst_sub_dirs('/home') if os.path.isdir(uws_usr2dir(name))
|
||||
name: uws_url_of_user(name)
|
||||
for name in lst_sub_dirs('/home')
|
||||
if os.path.isdir(uws_directory_of_user(name))
|
||||
}
|
||||
|
||||
@ -3,28 +3,29 @@
|
||||
Test module for (U)ser (Web) (S)ites.
|
||||
"""
|
||||
|
||||
from plinth.modules.apache import (uws_usr2dir, uws_dir2url, uws_url2usr,
|
||||
uws_usr2url, uws_url2dir, uws_dir2usr)
|
||||
from plinth.modules.apache import (uws_directory_of_user, uws_url_of_user,
|
||||
uws_directory_of_url, uws_url_of_directory,
|
||||
user_of_uws_directory, user_of_uws_url)
|
||||
|
||||
|
||||
def test_uws_namings():
|
||||
"""Test name solvers for user, url and directory of UWS."""
|
||||
|
||||
assert '/home/usr/public_html' == uws_usr2dir('usr')
|
||||
assert '/~usr/' == uws_usr2url('usr')
|
||||
assert '/home/usr/public_html' == uws_directory_of_user('usr')
|
||||
assert '/~usr/' == uws_url_of_user('usr')
|
||||
|
||||
f = uws_dir2usr
|
||||
f = user_of_uws_directory
|
||||
assert f('/home/usr/lacks/the/UWS/directory') is None
|
||||
assert 'usr' == f('/home/usr/public_html/is/a/normal/UWS/file')
|
||||
assert 'usr' == f('/home/usr/public_html/is/a/normal/UWS/path/')
|
||||
assert '€.;#@|' == f('/home/€.;#@|/public_html/is/stange/but/valid/')
|
||||
|
||||
f = uws_url2usr
|
||||
f = user_of_uws_url
|
||||
assert f('/usr/is/not/a/valid/UWS/url/due/to/missing/tilde') is None
|
||||
assert 'usr' == f('whatever/~usr/is/considered/a/valid/UWS/path')
|
||||
assert 'usr' == f('~usr')
|
||||
assert 'usr' == f('~usr/')
|
||||
assert 'usr' == f('/~usr/')
|
||||
|
||||
assert '/home/usr/public_html' == uws_url2dir('~usr/any/file')
|
||||
assert '/~usr/' == uws_dir2url('/home/usr/public_html/path/to/file')
|
||||
assert '/home/usr/public_html' == uws_directory_of_url('~usr/any/file')
|
||||
assert '/~usr/' == uws_url_of_directory('/home/usr/public_html/any/file')
|
||||
|
||||
@ -12,7 +12,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from plinth import actions
|
||||
from plinth import app as app_module
|
||||
from plinth import frontpage, menu
|
||||
from plinth.modules.apache import (uws_url2usr, uws_usr2url,
|
||||
from plinth.modules.apache import (user_of_uws_url, uws_url_of_user,
|
||||
get_users_with_website)
|
||||
from plinth.modules.names.components import DomainType
|
||||
from plinth.signals import domain_added
|
||||
@ -93,7 +93,7 @@ def home_page_url2scid(url):
|
||||
return 'apache-default'
|
||||
|
||||
if url and url.startswith('/~'):
|
||||
return 'uws-{}'.format(uws_url2usr(url))
|
||||
return 'uws-{}'.format(user_of_uws_url(url))
|
||||
|
||||
shortcuts = frontpage.Shortcut.list()
|
||||
for shortcut in shortcuts:
|
||||
@ -114,7 +114,7 @@ def _home_page_scid2url(shortcut_id):
|
||||
elif shortcut_id.startswith('uws-'):
|
||||
user = shortcut_id[4:]
|
||||
if user in get_users_with_website():
|
||||
url = uws_usr2url(user)
|
||||
url = uws_url_of_user(user)
|
||||
else:
|
||||
url = None
|
||||
else:
|
||||
|
||||
@ -9,7 +9,7 @@ import os
|
||||
from unittest.mock import (patch, MagicMock)
|
||||
|
||||
from plinth import __main__ as plinth_main
|
||||
from plinth.modules.apache import uws_usr2dir
|
||||
from plinth.modules.apache import uws_directory_of_user
|
||||
from plinth.modules.config import (home_page_url2scid, get_home_page,
|
||||
_home_page_scid2url, change_home_page)
|
||||
from plinth.modules.config.forms import ConfigurationForm
|
||||
@ -92,7 +92,7 @@ def test_homepage_mapping_skip_ci():
|
||||
"""Special tests for homepage functions."""
|
||||
|
||||
try:
|
||||
UWS_DIRECTORY = uws_usr2dir(os.getlogin())
|
||||
UWS_DIRECTORY = uws_directory_of_user(os.getlogin())
|
||||
except OSError:
|
||||
reason = "Needs access to ~/ directory. " \
|
||||
+ "CI sandboxed workspace doesn't provide it."
|
||||
@ -143,7 +143,7 @@ def test_homepage_field():
|
||||
Currently they share the same test case.
|
||||
"""
|
||||
try:
|
||||
UWS_DIRECTORY = uws_usr2dir(os.getlogin())
|
||||
UWS_DIRECTORY = uws_directory_of_user(os.getlogin())
|
||||
except OSError:
|
||||
reason = "Needs access to ~/ directory, etc. " \
|
||||
+ "CI sandboxed workspace doesn't provide it."
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user