diff --git a/find_python2.py b/find_python2.py new file mode 100755 index 0000000000000000000000000000000000000000..c79c600b88654f15e658246fa46baed7a08634d3 --- /dev/null +++ b/find_python2.py @@ -0,0 +1,84 @@ +#!/usr/bin/python3 + +import re +import sys +import pwd +import os + +if __name__ == '__main__': + FILES = set() + BY_HOST = {} + BY_PATH = {} + host = None + path = tuple() + for l in sys.stdin: + m = re.match('^(\S+)', l) + if m: + # Host + host = m.group(1) + print('host %s' % host) + continue + m = re.match('^(\s+)(/\S+)', l) + if m: + # Mio rule + depth = len(m.group(1))//2 + path = path[0:(depth-1)] + (m.group(2),) + continue + m = re.match('^\s+\[f\]\s*\S+\s*=\s*(\S+)', l) + if m: + # file rules + name = m.group(1) + FILES.add(name) + if not name in BY_HOST: + BY_HOST[name] = set() + pass + BY_HOST[name].add(host) + if not name in BY_PATH: + BY_PATH[name] = set() + pass + BY_PATH[name].add(path) + continue + m = re.match('^\s+\[s\]', l) + if m: + # Ignore symlink rules + continue + m = re.match('^\s+@', l) + if m: + # Ignore comps.xml rules + continue + print('XXX ', l) + + pass + print(FILES) + print(len(FILES)) + PYTHON = set() + PYTHON2 = set() + for f in FILES: + for l in open('/home/mio/%s' % f, 'rb'): + if l.startswith(b'#!/usr/bin/python3'): + # OK, this should work for some years more + break + if l.startswith(b'#!/usr/bin/python2'): + # OK for now, but needs to be handled + PYTHON2.add(f) + break + if l.startswith(b'#!/usr/bin/python'): + # This needs fixing + PYTHON.add(f) + break + # Skip after first line !!! + break + pass + for f in sorted(PYTHON): + who = pwd.getpwuid(os.stat('/home/mio/%s' % f).st_uid).pw_name + print(f, who) + for p in sorted(BY_PATH[f]): + print(' %s' % str(p)) + pass + for h in sorted(BY_HOST[f]): + print(' %s' % (h)) + pass + pass + print('Explicit python2') + for f in sorted(PYTHON2): + print(' %s' % f)