Skip to content
Snippets Groups Projects
Verified Commit 5cfec908 authored by Jiří Prokop's avatar Jiří Prokop
Browse files

fix: check_php_syntax to work with containers

parent 0d9e1624
No related branches found
No related tags found
1 merge request!41fix: check_php_syntax to work with containers
Pipeline #311875 passed
#!/usr/bin/env python3 #!/usr/bin/env python3
import os
import subprocess import subprocess
import sys import sys
import argparse import argparse
...@@ -20,39 +19,42 @@ def get_args(): ...@@ -20,39 +19,42 @@ def get_args():
" automatically generated files" " automatically generated files"
) )
) )
parser.add_argument(
"-c",
"--container",
required=True,
help="Docker container name to run PHP syntax check inside",
)
parser.add_argument( parser.add_argument(
"-d", "-d",
"--directory", "--directory",
required=True, 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() return parser.parse_args()
def main(): def main():
dir = get_args().directory args = get_args()
os.chdir(dir) dir = args.directory
paths = [] container = args.container
for (
dirpath, container_paths = (
dirname, subprocess.getoutput(
filenames, f"docker exec {container} find {dir} -type f -name '*.php'"
) in os.walk("."): )
for f in filenames: .strip()
if f.endswith(".php"): .split("\n")
paths.append( )
os.path.join(
dirpath,
f,
)
)
global_result = "" global_result = ""
for path in paths: for path in container_paths:
if os.path.isfile(path): result = subprocess.getoutput(f"docker exec {container} php -l {path}")
result = subprocess.getoutput(f"php -l {path}") if "No syntax errors" not in result:
if not result.startswith("No syntax errors"): global_result += f"{result} | "
global_result += f"{result} | "
if not global_result: if not global_result:
print(f"{OK} check_php_syntax - OK") 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