def spacewalk_report(name):
 cache_filename = os.path.join(CACHE_DIR, name)
 if ((not os.path.exists(cache_filename)) or ((time.time() - os.stat(cache_filename).st_mtime) > CACHE_AGE)):
  fh = open(cache_filename, 'w')
  p = subprocess.Popen([SW_REPORT, name], stdout=fh)
  p.wait()
  fh.close()
 lines = open(cache_filename, 'r').readlines()
 keys = lines[0].strip().split(',')
 keys = [('spacewalk_' + key) for key in keys]
 for line in lines[1:]:
  values = line.strip().split(',')
  if (len(keys) == len(values)):
   (yield dict(zip(keys, values)))

def spacewalk_report ( name ) : cache_filename = os . path . join ( CACHE_DIR , name ) if ( ( not os . path . exists ( cache_filename ) ) or ( ( time . time ( ) - os . stat ( cache_filename ) . st_mtime ) > CACHE_AGE ) ) : fh = open ( cache_filename , 'w' ) p = subprocess . Popen ( [ SW_REPORT , name ] , stdout = fh ) p . wait ( ) fh . close ( ) lines = open ( cache_filename , 'r' ) . readlines ( ) keys = lines [ 0 ] . strip ( ) . split ( ',' ) keys = [ ( 'spacewalk_' + key ) for key in keys ] for line in lines [ 1 : ] : values = line . strip ( ) . split ( ',' ) if ( len ( keys ) == len ( values ) ) : ( yield dict ( zip ( keys , values ) ) )
yield a dictionary form of each csv output produced by the specified spacewalk-report .