tool.py 996 B

1234567891011121314151617181920212223242526272829
  1. import os
  2. import subprocess
  3. from checkpackagelib.base import _Tool
  4. class NotExecutable(_Tool):
  5. def ignore(self):
  6. return False
  7. def run(self):
  8. if self.ignore():
  9. return
  10. if os.access(self.filename, os.X_OK):
  11. return ["{}:0: This file does not need to be executable{}".format(self.filename, self.hint())]
  12. class Shellcheck(_Tool):
  13. def run(self):
  14. cmd = ['shellcheck', self.filename]
  15. try:
  16. p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  17. stdout = p.communicate()[0]
  18. processed_output = [str(line.decode().rstrip()) for line in stdout.splitlines() if line]
  19. if p.returncode == 0:
  20. return
  21. return ["{}:0: run 'shellcheck' and fix the warnings".format(self.filename),
  22. '\n'.join(processed_output)]
  23. except FileNotFoundError:
  24. return ["{}:0: failed to call 'shellcheck'".format(self.filename)]