2
1

tool.py 907 B

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