Projet

Général

Profil

« Précédent | Suivant » 

Révision b1b5bb79

Ajouté par Thomas Noël il y a plus de 9 ans

manage prepare-whitelists

Voir les différences:

usr/local/univnautes/sp/sp/management/commands/prepare-whitelists.py
1
# -*- coding: utf-8 -*-
2
#
3
# UnivNautes
4
# Copyright (C) 2014  Entr'ouvert
5
#
6
# This program is free software: you can redistribute it and/or modify it under
7
# the terms of the GNU Affero General Public License as published by the Free
8
# Software Foundation, either version 3 of the License, or (at your option) any
9
# later version.
10
#
11
# This program is distributed in the hope that it will be useful, but WITHOUT
12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
14
# details.
15
#
16
# You should have received a copy of the GNU Affero General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18

  
19
from django.core.management.base import BaseCommand, CommandError
20
import os
21
from sp import pfconfigxml
22

  
23
WHITELISTS_DIR = os.path.join('/', 'var', 'tmp', 'univnautes-sp-whitelists')
24

  
25
class Command(BaseCommand):
26
    help = 'dump whitelists info in %s' % WHITELISTS_DIR
27

  
28
    def handle(self, *args, **options):
29
        if os.path.exists(WHITELISTS_DIR):
30
            print "error: %s already exists" % WHITELISTS_DIR
31
            return
32
        os.mkdir(WHITELISTS_DIR, 0770)
33
        whitelists = pfconfigxml.get_whitelists()
34
        for whitelist in whitelists:
35
            refid = whitelist.get('id')
36
            url = whitelist.get('url')
37
            codename = whitelist.get('codename')
38
            cacert = whitelist.get('cacert')
39
            wldir = os.path.join(WHITELISTS_DIR, refid)
40
            os.mkdir(wldir)
41
            conf_filename = os.path.join(wldir, 'conf.sh')
42
            with open(conf_filename, 'w') as f:
43
                f.write('URL="%s"\n' % url)
44
                f.write('CODENAME="%s"\n' % codename)
45
            if cacert:
46
                cacert_filename = os.path.join(wldir, 'cacert.pem')
47
                with open(cacert_filename, 'w') as f:
48
                    f.write(cacert)

Formats disponibles : Unified diff