# HG changeset patch # User Paul Boddie # Date 1374011535 -7200 # Node ID 779f66c84247e277098c0abcb61ac2492dc30b82 # Parent a95675d52731f5e85909b9f6ef7d60fdee575206 Moved the mapping-related tools into the tools directory. Added documentation in the mappings script. diff -r a95675d52731 -r 779f66c84247 mappings.sh --- a/mappings.sh Tue Jul 16 19:02:57 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#!/bin/sh - -MAPPINGS=$* -ID_MAPPING="mapping-id-to-page.txt" -TINY_ID_MAPPING="mapping-tiny-to-id.txt" -TINY_MAPPING="mapping-tiny-to-page.txt" -TAB=`printf '\t'` - -# Combine the space mappings into a common mapping from page identifiers to -# page names. -sort -n -u $MAPPINGS > "$ID_MAPPING" - -# Produce a common mapping from tiny URL identifiers to page names. -cut -f 1 "$ID_MAPPING" | uniq | python tiny.py - > "$TINY_ID_MAPPING" -join -t "$TAB" -1 2 -2 1 "$TINY_ID_MAPPING" "$ID_MAPPING" | cut -f 2,3 | LC_ALL=C sort > "$TINY_MAPPING" diff -r a95675d52731 -r 779f66c84247 tiny.py --- a/tiny.py Tue Jul 16 19:02:57 2013 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -#!/usr/bin/env python - -# See: https://answers.atlassian.com/questions/87971/what-is-the-algorithm-used-to-create-the-tiny-links - -from base64 import b64decode, b64encode -from struct import pack, unpack -import sys - -def tiny_url(s): - return b64encode(pack(" 2 and sys.argv[2] in ("-r", "--reverse") -fn = reverse and identifier or tiny_url - -if arg == "-": - for line in sys.stdin.readlines(): - line = line.strip() - if line: - print "%s\t%s" % (fn(line), line) -else: - print fn(arg) - -# vim: tabstop=4 expandtab shiftwidth=4 diff -r a95675d52731 -r 779f66c84247 tools/mappings.sh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mappings.sh Tue Jul 16 23:52:15 2013 +0200 @@ -0,0 +1,24 @@ +#!/bin/sh + +PROGNAME=`basename $0` +THISDIR=`dirname $0` + +MAPPINGS=$* + +if [ ! "$MAPPINGS" ]; then + echo "$PROGNAME ..." + exit 1 +fi + +ID_MAPPING="mapping-id-to-page.txt" +TINY_ID_MAPPING="mapping-tiny-to-id.txt" +TINY_MAPPING="mapping-tiny-to-page.txt" +TAB=`printf '\t'` + +# Combine the space mappings into a common mapping from page identifiers to +# page names. +sort -n -u $MAPPINGS > "$ID_MAPPING" + +# Produce a common mapping from tiny URL identifiers to page names. +cut -f 1 "$ID_MAPPING" | uniq | "$THISDIR/tiny.py" - > "$TINY_ID_MAPPING" +join -t "$TAB" -1 2 -2 1 "$TINY_ID_MAPPING" "$ID_MAPPING" | cut -f 2,3 | LC_ALL=C sort > "$TINY_MAPPING" diff -r a95675d52731 -r 779f66c84247 tools/tiny.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/tiny.py Tue Jul 16 23:52:15 2013 +0200 @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +# See: https://answers.atlassian.com/questions/87971/what-is-the-algorithm-used-to-create-the-tiny-links + +from base64 import b64decode, b64encode +from struct import pack, unpack +import sys + +def tiny_url(s): + return b64encode(pack(" 2 and sys.argv[2] in ("-r", "--reverse") +fn = reverse and identifier or tiny_url + +if arg == "-": + for line in sys.stdin.readlines(): + line = line.strip() + if line: + print "%s\t%s" % (fn(line), line) +else: + print fn(arg) + +# vim: tabstop=4 expandtab shiftwidth=4