view abbrev/main.py @ 2:aa57b8f607bd default tip

still doesnt work; lets find another
author Jeff Hammel <k0scist@gmail.com>
date Thu, 14 Jul 2016 12:17:35 -0700
parents 643c1f11ad9b
children
line wrap: on
line source

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
abbreviate lists of words to e.g. single-letter switches
"""

import argparse
import os
import subprocess
import sys

__all__ = ['Abbrev', 'main']

class Abbrev(object):

    def __init__(self, max_length=None):
        self.max_length = max_length
        self.lookup = {}

    def add(self, *words):
        for word in words:
            max_length = len(word)
            if not max_length:
                continue  # nothing to do
            if self.max_length and self.max_length > max_length:
                max_length = self.max_length
            for index in range(1,max_length+1):
                abbrev = word[:index]
                if abbrev not in self.lookup:
                    self.lookup[abbrev] = word


def main(args=sys.argv[1:]):

    # parse command line options
    parser = argparse.ArgumentParser()
    parser.add_argument('words', nargs='+',
                        help="words")
    parser.add_argumnet('-m', '--max', dest='max',
                        type=int, default=1,
                        help="maximum number of letters to use")
    options = parser.parse_args(args)

    abbrev = Abbrev

if __name__ == '__main__':
  main()