Revision c406d7d9 snf-django-lib/snf_django/management/commands/__init__.py

b/snf-django-lib/snf_django/management/commands/__init__.py
39 39
from snf_django.management import utils
40 40
from snf_django.lib.astakos import UserCache
41 41

  
42
import distutils
43

  
42 44

  
43 45
class SynnefoCommand(BaseCommand):
44 46
    option_list = BaseCommand.option_list + (
......
328 330
        for field in self.object_class._meta.fields:
329 331
            table.append((field.name, field.verbose_name, field.help_text))
330 332
        utils.pprint_table(self.stdout, table, headers)
333

  
334

  
335
class RemoveCommand(BaseCommand):
336
    help = "Generic remove command"
337
    option_list = BaseCommand.option_list + (
338
        make_option(
339
            "-f", "--force",
340
            dest="force",
341
            action="store_true",
342
            default=False,
343
            help="Do not prompt for confirmation"),
344
    )
345

  
346
    def confirm_deletion(self, force, resource='', args=''):
347
        if force is True:
348
            return True
349

  
350
        ids = ', '.join(args)
351
        self.stdout.write("Are you sure you want to delete %s %s?"
352
                          " [Y/N]\n" % (resource, ids))
353
        try:
354
            answer = distutils.util.strtobool(raw_input())
355
            if answer != 1:
356
                raise CommandError("Aborting deletion")
357
        except ValueError:
358
            raise CommandError("Invalid Y/N value, aborting")

Also available in: Unified diff