def name_uniquely(path, names_taken=(), proposed_name=None, unhide=False):
 if (not proposed_name):
  proposed_name = os.path.basename(path.rstrip(('/' + os.sep)))
 if unhide:
  proposed_name = proposed_name.lstrip('.').lstrip('_')
 dot_idx = proposed_name.find('.', (0 if unhide else 1))
 if (dot_idx == (-1)):
  (prefix, suffix) = (proposed_name, '')
 else:
  (prefix, suffix) = (proposed_name[:dot_idx], proposed_name[dot_idx:])
 if (prefix and (proposed_name not in names_taken)):
  return proposed_name
 for i in itertools.count(1):
  if prefix:
   name = ('%s-%d%s' % (prefix, i, suffix))
  else:
   name = ('%d%s' % (i, suffix))
  if (name not in names_taken):
   return name

def name_uniquely ( path , names_taken = ( ) , proposed_name = None , unhide = False ) : if ( not proposed_name ) : proposed_name = os . path . basename ( path . rstrip ( ( '/' + os . sep ) ) ) if unhide : proposed_name = proposed_name . lstrip ( '.' ) . lstrip ( '_' ) dot_idx = proposed_name . find ( '.' , ( 0 if unhide else 1 ) ) if ( dot_idx == ( - 1 ) ) : ( prefix , suffix ) = ( proposed_name , '' ) else : ( prefix , suffix ) = ( proposed_name [ : dot_idx ] , proposed_name [ dot_idx : ] ) if ( prefix and ( proposed_name not in names_taken ) ) : return proposed_name for i in itertools . count ( 1 ) : if prefix : name = ( '%s-%d%s' % ( prefix , i , suffix ) ) else : name = ( '%d%s' % ( i , suffix ) ) if ( name not in names_taken ) : return name
come up with a unique name for *path* .