- with open(fpath, 'rt', encoding='utf-8', errors='replace') as f:
- try:
- fline = f.read(128)
- f = io.StringIO(fline)
- shebang = f.readline()
- except UnicodeDecodeError as e:
- print("%s: skipping file `%s': %s" % (sys.argv[0], fpath, e), file=sys.stderr)
- continue
- if re.compile(r'^#!/usr/bin/env python\s').match(shebang) \
- or re.compile(r'^#!/usr/bin/env python2\s').match(shebang) \
- or re.compile(r'^#!/usr/bin/python\s').match(shebang):
- rep['python2'].append(fpath)
- elif re.compile(r'^#!/usr/bin/env python3\s').match(shebang):
- rep['python3'].append(fpath)
- elif re.compile(r'^#!/usr/bin/env perl\s').match(shebang):
- rep['perl'].append(fpath)
+ try:
+ with open(fpath, 'rt', encoding='utf-8', errors='replace') as f:
+ try:
+ fline = f.read(128)
+ f = io.StringIO(fline)
+ shebang = f.readline()
+ except UnicodeDecodeError as e:
+ print("%s: skipping file `%s': %s" % (sys.argv[0], fpath, e), file=sys.stderr)
+ continue
+ if re.compile(r'^#!\s*/usr/bin/env python\s').match(shebang) \
+ or re.compile(r'^#!\s*/usr/bin/env\s+python2\s').match(shebang) \
+ or re.compile(r'^#!\s*/usr/bin/python\s').match(shebang):
+ rep['python2'].append(fpath)
+ elif re.compile(r'^#!\s*/usr/bin/env\s+python3\s').match(shebang):
+ rep['python3'].append(fpath)
+ elif re.compile(r'^#!\s*/usr/bin/env\s+perl\s').match(shebang):
+ rep['perl'].append(fpath)
+ elif re.compile(r'^#!\s*/usr/bin/env\s+ruby\s').match(shebang):
+ rep['ruby'].append(fpath)
+ elif re.compile(r'^#!\s*/usr/bin/env\s+bash\s').match(shebang):
+ rep['bash'].append(fpath)
+ elif re.compile(r'^#!\s*/usr/bin/env\s+awk\s').match(shebang):
+ rep['awk'].append(fpath)
+ except FileNotFoundError:
+ pass