Revision d50ed8d4 snf-pithos-app/pithos/api/management/commands/storagequota.py

b/snf-pithos-app/pithos/api/management/commands/storagequota.py
36 36
from django.core.management.base import BaseCommand, CommandError
37 37

  
38 38
from pithos.api.settings import (BACKEND_DB_MODULE, BACKEND_DB_CONNECTION,
39
                                    BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH,
40
                                    BACKEND_BLOCK_UMASK,
41
                                    BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION,
42
                                    BACKEND_QUOTA, BACKEND_VERSIONING)
39
                                 BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH,
40
                                 BACKEND_BLOCK_UMASK,
41
                                 BACKEND_QUEUE_MODULE, BACKEND_QUEUE_CONNECTION,
42
                                 BACKEND_QUOTA, BACKEND_VERSIONING)
43 43
from pithos.backends import connect_backend
44 44

  
45 45

  
46 46
class Command(BaseCommand):
47 47
    args = "<user>"
48 48
    help = "Get/set a user's quota"
49
    
49

  
50 50
    option_list = BaseCommand.option_list + (
51 51
        make_option('--set-quota',
52
            dest='quota',
53
            metavar='BYTES',
54
            help="Set user's quota"),
55
        )
56
    
52
                    dest='quota',
53
                    metavar='BYTES',
54
                    help="Set user's quota"),
55
    )
56

  
57 57
    def handle(self, *args, **options):
58 58
        if len(args) != 1:
59 59
            raise CommandError("Please provide a user")
60
        
60

  
61 61
        user = args[0]
62 62
        quota = options.get('quota')
63 63
        if quota is not None:
......
65 65
                quota = int(quota)
66 66
            except ValueError:
67 67
                raise CommandError("Invalid quota")
68
        
68

  
69 69
        backend = connect_backend(db_module=BACKEND_DB_MODULE,
70 70
                                  db_connection=BACKEND_DB_CONNECTION,
71 71
                                  block_module=BACKEND_BLOCK_MODULE,
......
78 78
        if quota is not None:
79 79
            backend.update_account_policy(user, user, {'quota': quota})
80 80
        else:
81
            self.stdout.write("Quota for %s: %s\n" % (user, backend.get_account_policy(user, user)['quota']))
81
            self.stdout.write("Quota for %s: %s\n" % (
82
                user, backend.get_account_policy(user, user)['quota']))
82 83
        backend.close()

Also available in: Unified diff