executors.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2022 Project CHIP Authors
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import logging
  15. import os
  16. import shlex
  17. import subprocess
  18. class ShellRunner:
  19. def run(self, cmd, cwd=None):
  20. logging.debug(f"Executing {cmd}")
  21. subprocess.check_call(cmd, cwd=cwd)
  22. def ensure_directory_exists(self, dir):
  23. os.makedirs(dir, exist_ok=True)
  24. class DryRunner:
  25. def run(self, cmd, cwd=None):
  26. if cwd:
  27. logging.info(f"DRY-RUN: {shlex.join(cmd)} in {cwd}")
  28. else:
  29. logging.info(f"DRY-RUN: {shlex.join(cmd)}")
  30. def ensure_directory_exists(self, dir):
  31. logging.info(f"DRY-RUN: mkdir {dir}")