Skip to content
Snippets Groups Projects
Commit e3a24732 authored by Pavel Břoušek's avatar Pavel Břoušek
Browse files

chore: merge branch 'check_php_syntax' into 'main'

fix: check_php_syntax to work with containers

See merge request perun-proxy-aai/python/perun-proxy-utils!41
parents 227b8eee 5cfec908
No related branches found
No related tags found
1 merge request!41fix: check_php_syntax to work with containers
Pipeline #311892 passed with warnings
#!/usr/bin/env python3
import os
import subprocess
import sys
import argparse
......@@ -20,39 +19,42 @@ def get_args():
" automatically generated files"
)
)
parser.add_argument(
"-c",
"--container",
required=True,
help="Docker container name to run PHP syntax check inside",
)
parser.add_argument(
"-d",
"--directory",
required=True,
help="path which will be scanned for PHP files, including subdirectories",
help=(
"path inside container which will be scanned for PHP files, including"
" subdirectories"
),
)
return parser.parse_args()
def main():
dir = get_args().directory
os.chdir(dir)
paths = []
for (
dirpath,
dirname,
filenames,
) in os.walk("."):
for f in filenames:
if f.endswith(".php"):
paths.append(
os.path.join(
dirpath,
f,
)
)
args = get_args()
dir = args.directory
container = args.container
container_paths = (
subprocess.getoutput(
f"docker exec {container} find {dir} -type f -name '*.php'"
)
.strip()
.split("\n")
)
global_result = ""
for path in paths:
if os.path.isfile(path):
result = subprocess.getoutput(f"php -l {path}")
if not result.startswith("No syntax errors"):
global_result += f"{result} | "
for path in container_paths:
result = subprocess.getoutput(f"docker exec {container} php -l {path}")
if "No syntax errors" not in result:
global_result += f"{result} | "
if not global_result:
print(f"{OK} check_php_syntax - OK")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment