Changeset 158 for trunk

Show
Ignore:
Timestamp:
11/11/08 14:16:09 (16 years ago)
Author:
broder
Message:

Change hes to use PyHesiod

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/source/hes/hes

    r119 r158  
    55import os 
    66import sys 
     7import hesiod 
    78 
    89keys = ["passwd", "filsys", "pobox", "gid", "uid", "grplist", "sloc", "cluster", 
     
    1011 
    1112usage = """ 
    12 Usage: hes thing_you_want_info_about  [next_thing ...]  [type] 
     13Usage: hes thing_you_want_info_about  [next_thing ...] [type] 
    1314 
    1415Where 'type' is: %s 
    1516""" % ", ".join(keys) 
    1617 
    17 def query(thing, type): 
    18         input, output, err = os.popen3(('hesinfo', thing, type)) 
    19         # hesinfo prints errors (like queries not existing) to stderr, so if it's 
    20         # empty, we're probably good 
    21         if err.read() == '': 
    22                 return output.read().strip() 
    23  
    2418def printQuery(thing, type): 
    2519        """printQuery takes the output of a Hesiod query, formats it, and prints it 
    2620        out""" 
    27         info = query(thing, type) 
    28         if info != None: 
    29                 print "%s: %s" % (type.upper().rjust(10), info) 
     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 
    3028 
    3129def main():