Statistics
| Branch: | Tag: | Revision:

root / astakos / im / interface.py @ 4f15c5eb

History | View | Annotate | Download (2.4 kB)

1 aba1e498 Antony Chazapis
# Copyright 2011-2012 GRNET S.A. All rights reserved.
2 64cd4730 Antony Chazapis
# 
3 64cd4730 Antony Chazapis
# Redistribution and use in source and binary forms, with or
4 64cd4730 Antony Chazapis
# without modification, are permitted provided that the following
5 64cd4730 Antony Chazapis
# conditions are met:
6 64cd4730 Antony Chazapis
# 
7 64cd4730 Antony Chazapis
#   1. Redistributions of source code must retain the above
8 64cd4730 Antony Chazapis
#      copyright notice, this list of conditions and the following
9 64cd4730 Antony Chazapis
#      disclaimer.
10 64cd4730 Antony Chazapis
# 
11 64cd4730 Antony Chazapis
#   2. Redistributions in binary form must reproduce the above
12 64cd4730 Antony Chazapis
#      copyright notice, this list of conditions and the following
13 64cd4730 Antony Chazapis
#      disclaimer in the documentation and/or other materials
14 64cd4730 Antony Chazapis
#      provided with the distribution.
15 64cd4730 Antony Chazapis
# 
16 64cd4730 Antony Chazapis
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 64cd4730 Antony Chazapis
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 64cd4730 Antony Chazapis
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 64cd4730 Antony Chazapis
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 64cd4730 Antony Chazapis
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 64cd4730 Antony Chazapis
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 64cd4730 Antony Chazapis
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 64cd4730 Antony Chazapis
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 64cd4730 Antony Chazapis
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 64cd4730 Antony Chazapis
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 64cd4730 Antony Chazapis
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 64cd4730 Antony Chazapis
# POSSIBILITY OF SUCH DAMAGE.
28 64cd4730 Antony Chazapis
# 
29 64cd4730 Antony Chazapis
# The views and conclusions contained in the software and
30 64cd4730 Antony Chazapis
# documentation are those of the authors and should not be
31 64cd4730 Antony Chazapis
# interpreted as representing official policies, either expressed
32 64cd4730 Antony Chazapis
# or implied, of GRNET S.A.
33 64cd4730 Antony Chazapis
34 92defad4 Sofia Papagiannaki
from astakos.im.settings import BACKEND_BLOCK_MODULE, BACKEND_BLOCK_PATH, BACKEND_DB_CONNECTION, BACKEND_DB_MODULE, BACKEND_QUOTA, BACKEND_VERSIONING
35 4b8f5b96 Antony Chazapis
36 64cd4730 Antony Chazapis
from pithos.backends import connect_backend
37 64cd4730 Antony Chazapis
38 4b8f5b96 Antony Chazapis
def get_backend():
39 92defad4 Sofia Papagiannaki
    backend = connect_backend(db_module=BACKEND_DB_MODULE,
40 92defad4 Sofia Papagiannaki
                              db_connection=BACKEND_DB_CONNECTION,
41 92defad4 Sofia Papagiannaki
                              block_module=BACKEND_BLOCK_MODULE,
42 92defad4 Sofia Papagiannaki
                              block_path=BACKEND_BLOCK_PATH)
43 92defad4 Sofia Papagiannaki
    backend.default_policy['quota'] = BACKEND_QUOTA
44 92defad4 Sofia Papagiannaki
    backend.default_policy['versioning'] = BACKEND_VERSIONING
45 4b8f5b96 Antony Chazapis
    return backend
46 4b8f5b96 Antony Chazapis
47 64cd4730 Antony Chazapis
def get_quota(user):
48 4b8f5b96 Antony Chazapis
    backend = get_backend()
49 64cd4730 Antony Chazapis
    quota = backend.get_account_policy(user, user)['quota']
50 64cd4730 Antony Chazapis
    backend.close()
51 64cd4730 Antony Chazapis
    return quota
52 64cd4730 Antony Chazapis
53 64cd4730 Antony Chazapis
def set_quota(user, quota):
54 4b8f5b96 Antony Chazapis
    backend = get_backend()
55 64cd4730 Antony Chazapis
    backend.update_account_policy(user, user, {'quota': quota})
56 64cd4730 Antony Chazapis
    backend.close()
57 64cd4730 Antony Chazapis
    return quota