mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-28 13:21:25 -07:00
Fix shebangs and file modes and update tests. (#40563)
* Add execute bit sanity test and apply fixes. * Add shebang test for `lib` dirs and apply fixes. * Shebang and execute bit cleanup.
This commit is contained in:
parent
f84f3de7c2
commit
8deced3e04
39 changed files with 17 additions and 11 deletions
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import stat
|
||||
import sys
|
||||
|
||||
|
||||
|
@ -24,7 +25,6 @@ def main():
|
|||
}
|
||||
|
||||
skip = set([
|
||||
'hacking/cherrypick.py',
|
||||
'test/integration/targets/win_module_utils/library/legacy_only_new_way_win_line_ending.ps1',
|
||||
'test/integration/targets/win_module_utils/library/legacy_only_old_way_win_line_ending.ps1',
|
||||
])
|
||||
|
@ -35,17 +35,27 @@ def main():
|
|||
|
||||
with open(path, 'rb') as path_fd:
|
||||
shebang = path_fd.readline().strip()
|
||||
mode = os.stat(path).st_mode
|
||||
executable = (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & mode
|
||||
|
||||
if not shebang:
|
||||
continue
|
||||
if not shebang or not shebang.startswith(b'#!'):
|
||||
if executable:
|
||||
print('%s:%d:%d: file without shebang should not be executable' % (path, 0, 0))
|
||||
|
||||
if not shebang.startswith(b'#!'):
|
||||
continue
|
||||
|
||||
is_module = False
|
||||
|
||||
if path.startswith('lib/ansible/modules/'):
|
||||
is_module = True
|
||||
elif path.startswith('lib/') or path.startswith('test/runner/lib/'):
|
||||
if executable:
|
||||
print('%s:%d:%d: should not be executable' % (path, 0, 0))
|
||||
|
||||
if shebang:
|
||||
print('%s:%d:%d: should not have a shebang' % (path, 0, 0))
|
||||
|
||||
continue
|
||||
elif path.startswith('test/integration/targets/'):
|
||||
dirname = os.path.dirname(path)
|
||||
|
||||
|
@ -57,6 +67,9 @@ def main():
|
|||
is_module = True
|
||||
|
||||
if is_module:
|
||||
if executable:
|
||||
print('%s:%d:%d: module should not be executable' % (path, 0, 0))
|
||||
|
||||
ext = os.path.splitext(path)[1]
|
||||
expected_shebang = module_shebangs.get(ext)
|
||||
expected_ext = ' or '.join(['"%s"' % k for k in module_shebangs])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue