Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / management / commands / term_add.py @ fc1e2f02

History | View | Annotate | Download (2.2 kB)

1 270dd48d Sofia Papagiannaki
# Copyright 2012 GRNET S.A. All rights reserved.
2 270dd48d Sofia Papagiannaki
#
3 270dd48d Sofia Papagiannaki
# Redistribution and use in source and binary forms, with or
4 270dd48d Sofia Papagiannaki
# without modification, are permitted provided that the following
5 270dd48d Sofia Papagiannaki
# conditions are met:
6 270dd48d Sofia Papagiannaki
#
7 270dd48d Sofia Papagiannaki
#   1. Redistributions of source code must retain the above
8 270dd48d Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
9 270dd48d Sofia Papagiannaki
#      disclaimer.
10 270dd48d Sofia Papagiannaki
#
11 270dd48d Sofia Papagiannaki
#   2. Redistributions in binary form must reproduce the above
12 270dd48d Sofia Papagiannaki
#      copyright notice, this list of conditions and the following
13 270dd48d Sofia Papagiannaki
#      disclaimer in the documentation and/or other materials
14 270dd48d Sofia Papagiannaki
#      provided with the distribution.
15 270dd48d Sofia Papagiannaki
#
16 270dd48d Sofia Papagiannaki
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 270dd48d Sofia Papagiannaki
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 270dd48d Sofia Papagiannaki
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 270dd48d Sofia Papagiannaki
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 270dd48d Sofia Papagiannaki
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 270dd48d Sofia Papagiannaki
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 270dd48d Sofia Papagiannaki
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 270dd48d Sofia Papagiannaki
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 270dd48d Sofia Papagiannaki
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 270dd48d Sofia Papagiannaki
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 270dd48d Sofia Papagiannaki
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 270dd48d Sofia Papagiannaki
# POSSIBILITY OF SUCH DAMAGE.
28 270dd48d Sofia Papagiannaki
#
29 270dd48d Sofia Papagiannaki
# The views and conclusions contained in the software and
30 270dd48d Sofia Papagiannaki
# documentation are those of the authors and should not be
31 270dd48d Sofia Papagiannaki
# interpreted as representing official policies, either expressed
32 270dd48d Sofia Papagiannaki
# or implied, of GRNET S.A.
33 270dd48d Sofia Papagiannaki
34 963dfc33 Sofia Papagiannaki
from os.path import abspath
35 270dd48d Sofia Papagiannaki
36 270dd48d Sofia Papagiannaki
from django.core.management.base import BaseCommand, CommandError
37 270dd48d Sofia Papagiannaki
38 270dd48d Sofia Papagiannaki
from astakos.im.models import ApprovalTerms
39 270dd48d Sofia Papagiannaki
40 270dd48d Sofia Papagiannaki
class Command(BaseCommand):
41 270dd48d Sofia Papagiannaki
    args = "<location>"
42 270dd48d Sofia Papagiannaki
    help = "Insert approval terms"
43 270dd48d Sofia Papagiannaki
    
44 270dd48d Sofia Papagiannaki
    def handle(self, *args, **options):
45 270dd48d Sofia Papagiannaki
        if len(args) != 1:
46 270dd48d Sofia Papagiannaki
            raise CommandError("Invalid number of arguments")
47 270dd48d Sofia Papagiannaki
        
48 963dfc33 Sofia Papagiannaki
        location = abspath(args[0].decode('utf8'))
49 270dd48d Sofia Papagiannaki
        try:
50 aab4d540 Sofia Papagiannaki
            open(location, 'r')
51 270dd48d Sofia Papagiannaki
        except IOError:
52 270dd48d Sofia Papagiannaki
            raise CommandError("Invalid location")
53 270dd48d Sofia Papagiannaki
        
54 270dd48d Sofia Papagiannaki
        terms = ApprovalTerms(location=location)
55 270dd48d Sofia Papagiannaki
        terms.save()
56 270dd48d Sofia Papagiannaki
        
57 270dd48d Sofia Papagiannaki
        msg = "Created term id %d" % (terms.id,)
58 270dd48d Sofia Papagiannaki
        self.stdout.write(msg + '\n')