| """Check that executable text files have a shebang.""" |
| from __future__ import absolute_import |
| from __future__ import print_function |
| from __future__ import unicode_literals |
| from typing import Optional |
| from typing import Sequence |
| def check_has_shebang(path): # type: (str) -> int |
| with open(path, 'rb') as f: |
| '{path}: marked executable but has no (or invalid) shebang!\n' |
| " If it isn't supposed to be executable, try: chmod -x {quoted}\n" |
| ' If it is supposed to be executable, double-check its shebang.'.format( |
| quoted=pipes.quote(path), |
| def main(argv=None): # type: (Optional[Sequence[str]]) -> int |
| parser = argparse.ArgumentParser(description=__doc__) |
| parser.add_argument('filenames', nargs='*') |
| args = parser.parse_args(argv) |
| for filename in args.filenames: |
| retv |= check_has_shebang(filename) |
| if __name__ == '__main__': |