4 from __future__ import absolute_import, division
10 MAN_NAME_RE = re.compile(r'/man/(?:[^/]+/)?man([^/]+)/[^/]+.\1$')
12 SO_RE = re.compile(r'^\.so\s+(.*)$')
20 def process_file(name, suffix):
21 full_name = os.path.abspath(name)
22 m = MAN_NAME_RE.search(full_name)
26 dir_name = 'man' + category
27 with open(name, 'r') as f:
31 lines = [line for line in s.rstrip().split('\n') if not line.startswith('.\\"')]
34 m = SO_RE.search(lines[0])
38 if link.startswith('/') or link.count('/') > 1:
40 if link.startswith(dir_name+'/'):
41 link = link[len(dir_name)+1:]
45 os.symlink(link + suffix, name + suffix)
46 print 'Converted {} into a symlink to {}'.format(full_name, link)
51 dashes = args.index('--')
56 compressor = args[:dashes]
57 all_files = args[dashes+1:]
59 suffix = SUFFIXES.get(compressor[0], '')
63 for name in all_files:
64 if not process_file(name, suffix):
66 if not compressor or not files:
68 os.execvp(compressor[0], compressor + files)
71 if __name__ == '__main__':
72 sys.exit(main(sys.argv[1:]))