mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
feat: check php configuration in aurweb.spawn
Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
191198ca41
commit
82ca4ad9a0
1 changed files with 41 additions and 0 deletions
|
@ -23,11 +23,16 @@ from typing import Iterable, List
|
|||
import aurweb.config
|
||||
import aurweb.schema
|
||||
|
||||
from aurweb.exceptions import AurwebException
|
||||
|
||||
children = []
|
||||
temporary_dir = None
|
||||
verbosity = 0
|
||||
asgi_backend = ''
|
||||
|
||||
PHP_BINARY = os.environ.get("PHP_BINARY", "php")
|
||||
PHP_MODULES = ["pdo_mysql", "pdo_sqlite"]
|
||||
|
||||
|
||||
class ProcessExceptions(Exception):
|
||||
"""
|
||||
|
@ -42,6 +47,35 @@ class ProcessExceptions(Exception):
|
|||
super().__init__("\n- ".join(messages))
|
||||
|
||||
|
||||
def validate_php_config() -> None:
|
||||
"""
|
||||
Perform a validation check against PHP_BINARY's configuration.
|
||||
|
||||
AurwebException is raised here if checks fail to pass. We require
|
||||
the 'pdo_mysql' and 'pdo_sqlite' modules to be enabled.
|
||||
|
||||
:raises: AurwebException
|
||||
:return: None
|
||||
"""
|
||||
try:
|
||||
proc = subprocess.Popen([PHP_BINARY, "-m"],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE)
|
||||
out, _ = proc.communicate()
|
||||
except FileNotFoundError:
|
||||
raise AurwebException(f"Unable to locate the '{PHP_BINARY}' "
|
||||
"executable.")
|
||||
|
||||
assert proc.returncode == 0, ("Received non-zero error code "
|
||||
f"{proc.returncode} from '{PHP_BINARY}'.")
|
||||
|
||||
modules = out.decode().splitlines()
|
||||
for module in PHP_MODULES:
|
||||
if module not in modules:
|
||||
raise AurwebException(
|
||||
f"PHP does not have the '{module}' module enabled.")
|
||||
|
||||
|
||||
def generate_nginx_config():
|
||||
"""
|
||||
Generate an nginx configuration based on aurweb's configuration.
|
||||
|
@ -199,6 +233,13 @@ if __name__ == '__main__':
|
|||
parser.add_argument('-b', '--backend', choices=['hypercorn', 'uvicorn'], default='hypercorn',
|
||||
help='asgi backend used to launch the python server')
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
validate_php_config()
|
||||
except AurwebException as exc:
|
||||
print(f"error: {str(exc)}")
|
||||
sys.exit(1)
|
||||
|
||||
verbosity = args.verbose
|
||||
asgi_backend = args.backend
|
||||
with tempfile.TemporaryDirectory(prefix="aurweb-") as tmpdirname:
|
||||
|
|
Loading…
Add table
Reference in a new issue