Lichen

Annotated tools/showalias.py

934:2989aab1b4f7
10 months ago Paul Boddie Renamed the utf8string class to unicode, eliminating the unicode function. This means that the simple case of merely returning an object if it is already a Unicode object no longer occurs when using the unicode callable, but such behaviour might be better supported with more general customised instantiation functionality.
paul@833 1
#!/usr/bin/env python
paul@833 2
paul@841 3
from os.path import abspath, exists, join, split
paul@833 4
import sys
paul@833 5
paul@833 6
# Find the modules.
paul@833 7
paul@833 8
try:
paul@833 9
    import encoders
paul@833 10
except ImportError:
paul@833 11
    parent = abspath(split(split(__file__)[0])[0])
paul@833 12
    if split(parent)[1] == "Lichen":
paul@833 13
        sys.path.append(parent)
paul@833 14
paul@833 15
from encoders import decode_alias_location
paul@833 16
paul@833 17
if len(sys.argv) < 3:
paul@841 18
    print >>sys.stderr, "Usage: %s <directory> <alias>" % sys.argv[0]
paul@833 19
    sys.exit(1)
paul@833 20
paul@841 21
dirname = sys.argv[1]
paul@833 22
alias = sys.argv[2]
paul@833 23
paul@841 24
filename = join(dirname, "_deduced", "aliases")
paul@841 25
paul@841 26
if not exists(filename):
paul@841 27
    print >>sys.stderr, "Directory %s does not provide file %s." % (dirname, filename)
paul@841 28
    sys.exit(1)
paul@841 29
paul@833 30
f = open(filename)
paul@833 31
try:
paul@833 32
    for line in f.xreadlines():
paul@833 33
        columns = line.rstrip().split(" ")
paul@833 34
        if not columns[0].startswith(alias):
paul@833 35
            continue
paul@833 36
paul@833 37
        first = True
paul@833 38
paul@833 39
        for column in columns:
paul@833 40
            location = decode_alias_location(column.rstrip(","))
paul@833 41
            path, name, attrnames, version, access_number, invocation = location
paul@833 42
paul@833 43
            print first and "Alias:" or "Path:", path
paul@833 44
            print "Name:", name
paul@833 45
            print "Attribute names:", attrnames
paul@833 46
            print "Version:", version is None and "{}" or version
paul@833 47
            print "Access number:", access_number is None and "{}" or access_number
paul@833 48
            print "Invocation:", invocation and "true" or "false"
paul@833 49
            print
paul@833 50
paul@833 51
            first = False
paul@833 52
paul@833 53
        print "----"
paul@833 54
        print
paul@833 55
paul@833 56
finally:
paul@833 57
    f.close()
paul@833 58
paul@833 59
# vim: tabstop=4 expandtab shiftwidth=4