def extract_wininst_cfg(dist_filename):
 f = open(dist_filename, 'rb')
 try:
  endrec = zipfile._EndRecData(f)
  if (endrec is None):
   return None
  prepended = ((endrec[9] - endrec[5]) - endrec[6])
  if (prepended < 12):
   return None
  f.seek((prepended - 12))
  import struct, StringIO, ConfigParser
  (tag, cfglen, bmlen) = struct.unpack('<iii', f.read(12))
  if (tag not in (305419898, 305419899)):
   return None
  f.seek((prepended - (12 + cfglen)))
  cfg = ConfigParser.RawConfigParser({'version': '', 'target_version': ''})
  try:
   cfg.readfp(StringIO.StringIO(f.read(cfglen).split(chr(0), 1)[0]))
  except ConfigParser.Error:
   return None
  if ((not cfg.has_section('metadata')) or (not cfg.has_section('Setup'))):
   return None
  return cfg
 finally:
  f.close()

def extract_wininst_cfg ( dist_filename ) : f = open ( dist_filename , 'rb' ) try : endrec = zipfile . _EndRecData ( f ) if ( endrec is None ) : return None prepended = ( ( endrec [ 9 ] - endrec [ 5 ] ) - endrec [ 6 ] ) if ( prepended < 12 ) : return None f . seek ( ( prepended - 12 ) ) import struct , StringIO , ConfigParser ( tag , cfglen , bmlen ) = struct . unpack ( '<iii' , f . read ( 12 ) ) if ( tag not in ( 305419898 , 305419899 ) ) : return None f . seek ( ( prepended - ( 12 + cfglen ) ) ) cfg = ConfigParser . RawConfigParser ( { 'version' : '' , 'target_version' : '' } ) try : cfg . readfp ( StringIO . StringIO ( f . read ( cfglen ) . split ( chr ( 0 ) , 1 ) [ 0 ] ) ) except ConfigParser . Error : return None if ( ( not cfg . has_section ( 'metadata' ) ) or ( not cfg . has_section ( 'Setup' ) ) ) : return None return cfg finally : f . close ( )
extract configuration data from a bdist_wininst .