mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +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:
1 parent
337e8c28dd
commit
ec870a1766
4 files changed
+26
-24
No files matched your search
@@ -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')
|
||||
Reference in new issue
Block a user