'Build/index all versions or a single project\'s version'

def handle(self, *args, **options):

    project = options['project']
    queryset = Version.objects.all()
    if project:
        queryset = queryset.filter(project__slug=project)
        if (not queryset.exists()):
            raise CommandError('No    project    with    slug:    {slug}'.format(slug=project))
        log.info('Building    all    versions    for    %s', project)
    elif getattr(settings, 'INDEX_ONLY_LATEST', True):
        queryset = queryset.filter(slug=LATEST)
    for version in queryset:
        log.info('Reindexing    %s', version)
        try:
            commit = version.project.vcs_repo(version.slug).commit
        except:
            commit = None
        try:
            update_search(version.pk, commit, delete_non_commit_files=False)
        except Exception:
            log.error('Reindex    failed    for    %s', version, exc_info=True)
