def unique_lineage_name(path, filename, chmod=420, mode='w'):
 preferred_path = os.path.join(path, ('%s.conf' % filename))
 try:
  return (safe_open(preferred_path, chmod=chmod), preferred_path)
 except OSError as err:
  if (err.errno != errno.EEXIST):
   raise
 return _unique_file(path, filename_pat=(lambda count: ('%s-%04d.conf' % (filename, count))), count=1, chmod=chmod, mode=mode)

def unique_lineage_name ( path , filename , chmod = 420 , mode = 'w' ) : preferred_path = os . path . join ( path , ( '%s.conf' % filename ) ) try : return ( safe_open ( preferred_path , chmod = chmod ) , preferred_path ) except OSError as err : if ( err . errno != errno . EEXIST ) : raise return _unique_file ( path , filename_pat = ( lambda count : ( '%s-%04d.conf' % ( filename , count ) ) ) , count = 1 , chmod = chmod , mode = mode )
safely finds a unique file using lineage convention .