Test Failed
Push — master ( 9ea4cd...0ffab9 )
by Koen
03:34 queued 13s
created

atramhasis.scripts.initializedb   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 136
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 107
dl 0
loc 136
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
B main() 0 115 2
A usage() 0 5 1
1
import os
2
import sys
3
4
from pyramid.paster import get_appsettings
5
from pyramid.paster import setup_logging
6
from pyramid.scripts.common import parse_vars
7
from skosprovider_sqlalchemy.models import ConceptScheme
8
from skosprovider_sqlalchemy.models import Label
9
from skosprovider_sqlalchemy.utils import import_provider
10
from sqlalchemy import engine_from_config
11
from sqlalchemy.orm import sessionmaker
12
13
14
def usage(argv):
15
    cmd = os.path.basename(argv[0])
16
    print('usage: %s <config_uri> [var=value]\n'
17
          '(example: "%s development.ini")' % (cmd, cmd))
18
    sys.exit(1)
19
20
21
def main(argv=sys.argv):
22
    from fixtures.data import trees, geo
23
    from fixtures.styles_and_cultures import styles_and_cultures
24
    from fixtures.materials import materials
25
    from fixtures.eventtypes import eventtypes
26
    from fixtures.heritagetypes import heritagetypes
27
    from fixtures.periods import periods
28
    from fixtures.species import species
29
    if len(argv) < 2:
30
        usage(argv)
31
    config_uri = argv[1]
32
    options = parse_vars(argv[2:])
33
    setup_logging(config_uri)
34
    settings = get_appsettings(config_uri, options=options)
35
    engine = engine_from_config(settings, 'sqlalchemy.')
36
    db_session = sessionmaker(bind=engine)()
37
    import_provider(
38
        trees,
39
        ConceptScheme(
40
            id=1,
41
            uri='urn:x-skosprovider:trees',
42
            labels=[
43
                Label('Verschillende soorten bomen', 'prefLabel', 'nl'),
44
                Label('Different types of trees', 'prefLabel', 'en')
45
            ]
46
        ),
47
        db_session
48
    )
49
    import_provider(
50
        geo,
51
        ConceptScheme(
52
            id=2,
53
            uri='urn:x-skosprovider:geo',
54
            labels=[
55
                Label('Geografie', 'prefLabel', 'nl'),
56
                Label('Geography', 'prefLabel', 'en')
57
            ]
58
        ),
59
        db_session
60
    )
61
    import_provider(
62
        styles_and_cultures,
63
        ConceptScheme(
64
            id=3,
65
            uri='https://id.erfgoed.net/thesauri/stijlen_en_culturen',
66
            labels=[
67
                Label('Stijlen en Culturen', 'prefLabel', 'nl'),
68
                Label('Styles and Cultures', 'prefLabel', 'en')
69
            ]
70
        ),
71
        db_session
72
    )
73
    import_provider(
74
        materials,
75
        ConceptScheme(
76
            id=4,
77
            uri='https://id.erfgoed.net/thesauri/materialen',
78
            labels=[
79
                Label('Materialen', 'prefLabel', 'nl'),
80
                Label('Materials', 'prefLabel', 'en')
81
            ]
82
        ),
83
        db_session
84
    )
85
    import_provider(
86
        eventtypes,
87
        ConceptScheme(
88
            id=5,
89
            uri='https://id.erfgoed.net/thesauri/gebeurtenistypes',
90
            labels=[
91
                Label('Gebeurtenistypes', 'prefLabel', 'nl'),
92
                Label('Event types', 'prefLabel', 'en')
93
            ]
94
        ),
95
        db_session
96
    )
97
    import_provider(
98
        heritagetypes,
99
        ConceptScheme(
100
            id=6,
101
            uri='https://id.erfgoed.net/thesauri/erfgoedtypes',
102
            labels=[
103
                Label('Erfgoedtypes', 'prefLabel', 'nl'),
104
                Label('Heritage types', 'prefLabel', 'en')
105
            ]
106
        ),
107
        db_session
108
    )
109
    import_provider(
110
        periods,
111
        ConceptScheme(
112
            id=7,
113
            uri='https://id.erfgoed.net/thesauri/dateringen',
114
            labels=[
115
                Label('Dateringen', 'prefLabel', 'nl'),
116
                Label('Periods', 'prefLabel', 'en')
117
            ]
118
        ),
119
        db_session
120
    )
121
    import_provider(
122
        species,
123
        ConceptScheme(
124
            id=8,
125
            uri='https://id.erfgoed.net/thesauri/soorten',
126
            labels=[
127
                Label('Soorten', 'prefLabel', 'nl'),
128
                Label('Species', 'prefLabel', 'en')
129
            ]
130
        ),
131
        db_session
132
    )
133
    db_session.commit()
134
    db_session.close()
135
    print('--atramhasis-db-initialized--')
136