2018-05-08 21:17:37 +00:00
|
|
|
import sqlite3
|
|
|
|
|
2018-05-10 08:07:49 +00:00
|
|
|
import config
|
2018-05-08 21:17:37 +00:00
|
|
|
import database
|
|
|
|
|
2018-06-10 12:11:28 +00:00
|
|
|
def initialize_users(db, admin_user, admin_password):
|
|
|
|
"""Creates a bare-bones user table with only admin user
|
|
|
|
This should never be run outside of the initialization script"""
|
|
|
|
|
|
|
|
cursor = db.cursor()
|
|
|
|
|
|
|
|
cursor.execute('''CREATE TABLE users (
|
|
|
|
id integer NOT NULL PRIMARY KEY,
|
|
|
|
|
|
|
|
parent integer,
|
|
|
|
status integer NOT NULL,
|
|
|
|
|
|
|
|
password text NOT NULL,
|
|
|
|
|
|
|
|
username text NOT NULL,
|
|
|
|
email text NOT NULL,
|
|
|
|
|
|
|
|
comment text NOT NULL,
|
|
|
|
|
|
|
|
FOREIGN KEY(parent) REFERENCES users(id)
|
|
|
|
);''')
|
|
|
|
|
|
|
|
# Since we just created the database, add_user cannot have conflicting user
|
|
|
|
database.add_user(db, username = admin_user, password = admin_password, email = '', parent = None, status = database.userstatus.admin)
|
|
|
|
|
|
|
|
db.commit()
|
|
|
|
|
|
|
|
def initialize_boards(db, boards):
|
|
|
|
"""Creates a table of boards
|
|
|
|
This should never be run outside of the initialization script"""
|
|
|
|
|
|
|
|
cursor = db.cursor()
|
|
|
|
|
|
|
|
cursor.execute('''CREATE TABLE boards (
|
|
|
|
id integer NOT NULL PRIMARY KEY,
|
|
|
|
name text NOT NULL
|
|
|
|
);''')
|
|
|
|
|
|
|
|
# .executemany() wants them in the format [("board1",), ("board2",), …]
|
|
|
|
boards = [(board_name,) for board_name in boards]
|
|
|
|
|
|
|
|
# Use NULL to have SQLite generate the IDs automatically
|
|
|
|
cursor.executemany('INSERT INTO boards VALUES (NULL, ?);', boards)
|
|
|
|
|
|
|
|
db.commit()
|
|
|
|
|
2018-05-08 21:17:37 +00:00
|
|
|
if __name__ == '__main__':
|
2018-05-10 08:07:49 +00:00
|
|
|
config.load('buranun.conf')
|
|
|
|
with database.connect() as db:
|
2018-05-08 21:17:37 +00:00
|
|
|
username = input('admin username: ')
|
|
|
|
password = input('admin password: ')
|
2018-06-10 12:11:28 +00:00
|
|
|
initialize_users(db, username, password)
|
2018-05-09 21:02:21 +00:00
|
|
|
|
|
|
|
boards = input('boards: ').split()
|
2018-06-10 12:11:28 +00:00
|
|
|
initialize_boards(db, boards)
|