def generate_unique_codename(num_words=7):
 while True:
  codename = crypto_util.genrandomid(num_words)
  if (len(codename) > Source.MAX_CODENAME_LEN):
   app.logger.warning("Generated a source codename that was too long, skipping it. This should not happen. (Codename='{}')".format(codename))
   continue
  sid = crypto_util.hash_codename(codename)
  matching_sources = Source.query.filter((Source.filesystem_id == sid)).all()
  if (len(matching_sources) == 0):
   return codename

def generate_unique_codename ( num_words = 7 ) : while True : codename = crypto_util . genrandomid ( num_words ) if ( len ( codename ) > Source . MAX_CODENAME_LEN ) : app . logger . warning ( "Generated a source codename that was too long, skipping it. This should not happen. (Codename='{}')" . format ( codename ) ) continue sid = crypto_util . hash_codename ( codename ) matching_sources = Source . query . filter ( ( Source . filesystem_id == sid ) ) . all ( ) if ( len ( matching_sources ) == 0 ) : return codename
generate random codenames until we get an unused one .