import sqlite3 import config import database 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() if __name__ == '__main__': config.load('buranun.conf') with database.connect() as db: username = input('admin username: ') password = input('admin password: ') initialize_users(db, username, password) boards = input('boards: ').split() initialize_boards(db, boards)