<commit_before>#!/usr/bin/env python
# vim: sts=4 sw=4 et

import os, sys

path = '.'
if len(sys.argv) < 3:
    sys.stderr.write("Usage: %s links.db link [path]\n" % sys.argv[0])
    sys.exit(1)

if not sys.argv[1]:
    sys.exit(0)

links = {}

for l in open(sys.argv[1]):
    l = l.split('\t', 1)
    if len(l) != 2:
        continue
    links[l[0]] = l[1].strip()

if len(sys.argv) > 3:
    path = sys.argv[3]

l = sys.argv[2]
if l in links:
    print os.path.relpath(links[l] + '.html', path)
<commit_msg>docs/backwards compatibility: fix links.py to run on 8.04<commit_after>#!/usr/bin/env python
# vim: sts=4 sw=4 et

import os, sys

try:
    from os.path import relpath
except:
    def relpath(path, start=os.path.curdir):
        """Return a relative version of a path"""
        
        if not path:
            raise ValueError("no path specified")
        
        start_list = os.path.abspath(start).split(os.path.sep)
        path_list = os.path.abspath(path).split(os.path.sep)

        # Work out how much of the filepath is shared by start and path.
        i = len(os.path.commonprefix([start_list, path_list]))
        
        rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
        if not rel_list:
            return os.path.curdir
        return os.path.join(*rel_list)

path = '.'
if len(sys.argv) < 3:
    sys.stderr.write("Usage: %s links.db link [path]\n" % sys.argv[0])
    sys.exit(1)

if not sys.argv[1]:
    sys.exit(0)

links = {}

for l in open(sys.argv[1]):
    l = l.split('\t', 1)
    if len(l) != 2:
        continue
    links[l[0]] = l[1].strip()

if len(sys.argv) > 3:
    path = sys.argv[3]

l = sys.argv[2]
if l in links:
    print relpath(links[l] + '.html', path)

{'fraction_non_alphanumeric': 0.16705336426914152, 'fraction_numerical': 0.0191415313225058, 'mean_word_length': 2.45, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5170490', 'n_tokens_mistral': 688, 'n_tokens_neox': 673, 'n_words': 167}