43 config.enabled_sources = ('system', 'admin') |
43 config.enabled_sources = ('system', 'admin') |
44 repo = Repository(config, vreg=vreg) |
44 repo = Repository(config, vreg=vreg) |
45 assert len(repo.sources) == 1, repo.sources |
45 assert len(repo.sources) == 1, repo.sources |
46 schema = repo.schema |
46 schema = repo.schema |
47 sourcescfg = config.sources() |
47 sourcescfg = config.sources() |
48 print 'creating necessary tables into the system source' |
48 print '-> creating necessary tables into the system source.' |
49 source = sourcescfg['system'] |
49 source = sourcescfg['system'] |
50 driver = source['db-driver'] |
50 driver = source['db-driver'] |
51 sqlcnx = repo.system_source.get_connection() |
51 sqlcnx = repo.system_source.get_connection() |
52 sqlcursor = sqlcnx.cursor() |
52 sqlcursor = sqlcnx.cursor() |
53 execute = sqlcursor.execute |
53 execute = sqlcursor.execute |
54 if drop: |
54 if drop: |
55 dropsql = sqldropschema(schema, driver) |
55 dropsql = sqldropschema(schema, driver) |
56 try: |
56 try: |
57 sqlexec(dropsql, execute) |
57 sqlexec(dropsql, execute) |
58 except Exception, ex: |
58 except Exception, ex: |
59 print 'drop failed, skipped (%s)' % ex |
59 print '-> drop failed, skipped (%s).' % ex |
60 sqlcnx.rollback() |
60 sqlcnx.rollback() |
61 # schema entities and relations tables |
61 # schema entities and relations tables |
62 # can't skip entities table even if system source doesn't support them, |
62 # can't skip entities table even if system source doesn't support them, |
63 # they are used sometimes by generated sql. Keeping them empty is much |
63 # they are used sometimes by generated sql. Keeping them empty is much |
64 # simpler than fixing this... |
64 # simpler than fixing this... |
69 #skip_entities=[str(e) for e in schema.entities() |
69 #skip_entities=[str(e) for e in schema.entities() |
70 # if not repo.system_source.support_entity(str(e))]) |
70 # if not repo.system_source.support_entity(str(e))]) |
71 sqlexec(schemasql, execute) |
71 sqlexec(schemasql, execute) |
72 # install additional driver specific sql files |
72 # install additional driver specific sql files |
73 for fpath in glob(join(config.schemas_lib_dir(), '*.sql.%s' % driver)): |
73 for fpath in glob(join(config.schemas_lib_dir(), '*.sql.%s' % driver)): |
74 print 'install', fpath |
74 print '-> installing', fpath |
75 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
75 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
76 for directory in config.cubes_path(): |
76 for directory in config.cubes_path(): |
77 for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): |
77 for fpath in glob(join(directory, 'schema', '*.sql.%s' % driver)): |
78 print 'install', fpath |
78 print '-> installing', fpath |
79 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
79 sqlexec(open(fpath).read(), execute, False, delimiter=';;') |
80 sqlcursor.close() |
80 sqlcursor.close() |
81 sqlcnx.commit() |
81 sqlcnx.commit() |
82 sqlcnx.close() |
82 sqlcnx.close() |
83 session = repo.internal_session() |
83 session = repo.internal_session() |
88 if interactive: |
88 if interactive: |
89 msg = 'enter login and password of the initial manager account' |
89 msg = 'enter login and password of the initial manager account' |
90 login, pwd = manager_userpasswd(msg=msg, confirm=True) |
90 login, pwd = manager_userpasswd(msg=msg, confirm=True) |
91 else: |
91 else: |
92 login, pwd = unicode(source['db-user']), source['db-password'] |
92 login, pwd = unicode(source['db-user']), source['db-password'] |
93 print 'inserting default user and groups' |
93 print '-> inserting default user and default groups.' |
94 needisfix = [] |
94 needisfix = [] |
95 for group in BASEGROUPS: |
95 for group in BASEGROUPS: |
96 rset = session.execute('INSERT CWGroup X: X name %(name)s', |
96 rset = session.execute('INSERT CWGroup X: X name %(name)s', |
97 {'name': unicode(group)}) |
97 {'name': unicode(group)}) |
98 needisfix.append( (rset.rows[0][0], rset.description[0][0]) ) |
98 needisfix.append( (rset.rows[0][0], rset.description[0][0]) ) |
138 config.creating = False |
138 config.creating = False |
139 config.read_application_schema = read_application_schema |
139 config.read_application_schema = read_application_schema |
140 config.bootstrap_schema = bootstrap_schema |
140 config.bootstrap_schema = bootstrap_schema |
141 config.consider_user_state = True |
141 config.consider_user_state = True |
142 config.set_language = True |
142 config.set_language = True |
143 print 'application %s initialized' % config.appid |
143 print '-> application %s initialized.' % config.appid |
144 |
144 |
145 |
145 |
146 def initialize_schema(config, schema, mhandler, event='create'): |
146 def initialize_schema(config, schema, mhandler, event='create'): |
147 from cubicweb.server.schemaserial import serialize_schema |
147 from cubicweb.server.schemaserial import serialize_schema |
148 paths = [p for p in config.cubes_path() + [config.apphome] |
148 paths = [p for p in config.cubes_path() + [config.apphome] |