X-Git-Url: https://git.bzium.org/embe/man-symlinker.git/blobdiff_plain/b073943b6e28ed5bf0db728fc81d2f62bc730a52..9ee488c8c3eb51c4690af9463a5fea8aab1851a8:/man-symlinker?ds=sidebyside diff --git a/man-symlinker b/man-symlinker index 5299829..cdca274 100755 --- a/man-symlinker +++ b/man-symlinker @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python # encoding: UTF-8 from __future__ import absolute_import, division @@ -12,7 +12,8 @@ MAX_LEN = 1024 SO_RE = re.compile(r'^\.so\s+(.*)$') def process_file(name): - m = MAN_NAME_RE.search(name) + full_name = os.path.abspath(name) + m = MAN_NAME_RE.search(full_name) if not m: return False category = m.group(1) @@ -21,10 +22,10 @@ def process_file(name): s = f.read(MAX_LEN+1) if len(s) > MAX_LEN: return False - s = s.strip() - if '\n' in s: - return False - m = SO_RE.search(s) + lines = [line for line in s.rstrip().split('\n') if not line.startswith('.\\"')] + if len(lines) != 1: + return False + m = SO_RE.search(lines[0]) if not m: return False link = m.group(1) @@ -36,7 +37,7 @@ def process_file(name): link = '../' + link os.unlink(name) os.symlink(link, name) - print 'Converted {} into a symlink to {}'.format(name, link) + print 'Converted {} into a symlink to {}'.format(full_name, link) return True def main(args=[]):