aboutsummaryrefslogtreecommitdiffstats
path: root/jm2l/scripts/initializedb.py
blob: 38776dd2fca7945e688f3a627b34dd65d10e132b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf8 -*-
import os
import sys
import transaction
import time
import lxml.etree as ET

from sqlalchemy import engine_from_config
from sqlalchemy import create_engine
import unicodedata
import urllib
# Usefull tools
from slugify import slugify
from sqlite3 import dbapi2 as sqlite
from os import path
from pyramid.paster import (
    get_appsettings,
    setup_logging,
    )
    
from jm2l.models import *
from datetime import datetime

def usage(argv):
    cmd = os.path.basename(argv[0])
    print('usage: %s <config_uri>\n'
          '(example: "%s development.ini")' % (cmd, cmd)) 
    sys.exit(1)


def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.create_all(engine)
    with transaction.manager:
        admin = User(nom=u'jm2l', prenom='contact',
            slug='contact jm2l', password=u'jm2l',
            mail=u'contact@jm2l.linux-azur.org',
            Staff=1
            )
        DBSession.add(admin)

        # Create 2015 year event
        jm2l = JM2L_Year(year_uid=2015, 
                state="Ongoing",
                description=u"%d, %dème édition des JM2L." % ( 2015, 9 ),
                start_time=datetime.strptime("28-11-2015 10:00","%d-%m-%Y %H:%M"),
                end_time=datetime.strptime("28-11-2015 19:00","%d-%m-%Y %H:%M")
                )
        DBSession.add(jm2l)

        # Create 2015 Physic room event
        phy_salle = SallePhy( name=u"Polytech salle 211",
            description=u"Salle informatique, présence de postes de travail",)
        DBSession.add(phy_salle)
        DBSession.flush()

        # Create matching room place (Name could change each year)
        salle = Salles(name=u"Mystère",  description=u"Salle Mystère",
                    phy_salle_id = phy_salle.uid,
                    year_uid = jm2l.year_uid)
        DBSession.add(salle)