Bowrna commented on code in PR #623:
URL: https://github.com/apache/airflow-site/pull/623#discussion_r924405759
##########
site.py:
##########
@@ -0,0 +1,233 @@
+from pathlib import Path
+import os
+import sys
+import argparse
+import subprocess
+from typing import Union, List, Optional, Mapping
+
+IMAGE_NAME="airflow-site"
+CONTAINER_NAME="airflow-site-c"
+SITE_DIST="landing-pages/dist"
+THEME_GEN="sphinx_airflow_theme/sphinx_airflow_theme/static/_gen"
+RunCommandResult = Union[subprocess.CompletedProcess,
subprocess.CalledProcessError]
+
+
+def run_command(cmd: List[str],
+ env: Optional[Mapping[str, str]] = None,
+ cwd: Optional[Path] = None,
+ input: Optional[str] = None,
+ check: bool = True,
+ **kwargs,
+)-> RunCommandResult:
+ workdir: str = str(cwd) if cwd else os.getcwd()
+ try:
+ cmd_env = os.environ.copy()
+ cmd_env.setdefault("HOME", str(Path.home()))
+ if env:
+ cmd_env.update(env)
+ return subprocess.run(cmd, input=input, check=check, env=cmd_env,
cwd=workdir, **kwargs)
+ except subprocess.CalledProcessError as ex:
+ if ex.stdout:
+ print(ex.stdout)
+ if ex.stderr:
+ print(ex.stderr)
+ return ex
Review Comment:
This is a common method to execute the script via Python subprocess. If I
could return the error, then I can log the error message according to the
command executed. If you have any other options please let me know @turbaszek
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]