root/trunk/source/hes/hes

Revision 158, 1.2 kB (checked in by broder, 16 years ago)

Change hes to use PyHesiod

  • Property svn:executable set to *
Line 
1 #!/usr/bin/env python
2
3 """hes does Hesiod lookups for the most common types of Hesiod entries."""
4
5 import os
6 import sys
7 import hesiod
8
9 keys = ["passwd", "filsys", "pobox", "gid", "uid", "grplist", "sloc", "cluster",
10 "group", "pcap", "service", "lpralias", "printinfo", "palladium", "tloc"]
11
12 usage = """
13 Usage: hes thing_you_want_info_about  [next_thing ...]  [type]
14
15 Where 'type' is: %s
16 """ % ", ".join(keys)
17
18 def printQuery(thing, type):
19         """printQuery takes the output of a Hesiod query, formats it, and prints it
20         out"""
21         try:
22                 info = hesiod.resolve(thing, type)
23                 for ent in info:
24                         print "%s: %s" % (type.upper().rjust(10), ent)
25         except IOError, e:
26                 if e.errno != 2:
27                         raise
28
29 def main():
30         # Print the usage information if there were no arguments
31         if len(sys.argv) <= 1:
32                 print usage
33                 return
34        
35         # If a specific type of query was asked for, do that for each thing
36         if sys.argv[-1] in keys:
37                 type = sys.argv[-1]
38                 for thing in sys.argv[1:-1]:
39                         printQuery(thing, type)
40         # Otherwise LOOKUP EVERYTHING!
41         else:
42                 for thing in sys.argv[1:]:
43                         for type in keys:
44                                 printQuery(thing, type)
45                         # ...with a blank line between each thing being looked up
46                         print ""
47
48 if __name__ == "__main__":
49         main()
Note: See TracBrowser for help on using the browser.