def delete_unused_versions(self, versions_to_keep=<NUM_LIT:10>):
<EOL>environments = self.ebs.describe_environments(application_name=self.app_name, include_deleted=False)<EOL>environments = environments['<STR_LIT>']['<STR_LIT>']['<STR_LIT>']<EOL>versions_in_use = []<EOL>for env in environments:<EOL><INDENT>versions_in_use.append(env['<STR_LIT>'])<EOL><DEDENT>versions = self.ebs.describe_application_versions(application_name=self.app_name)<EOL>versions = versions['<STR_LIT>']['<STR_LIT>'][<EOL>'<STR_LIT>']<EOL>versions = sorted(versions, reverse=True, key=functools.cmp_to_key(lambda x, y: (x['<STR_LIT>'] > y['<STR_LIT>']) - (x['<STR_LIT>'] < y['<STR_LIT>'])))<EOL>for version in versions[versions_to_keep:]:<EOL><INDENT>if version['<STR_LIT>'] in versions_in_use:<EOL><INDENT>out("<STR_LIT>" + version["<STR_LIT>"] + "<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>out("<STR_LIT>" + version["<STR_LIT>"])<EOL>self.ebs.delete_application_version(application_name=self.app_name,<EOL>version_label=version['<STR_LIT>'])<EOL>sleep(<NUM_LIT:2>)<EOL><DEDENT><DEDENT>
Deletes unused versions