From 269f26eff15a6ce4f474bdd66750978df28e7874 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 7 Mar 2019 18:54:56 +0100 Subject: [PATCH] fixup cli and add initdb --- asu/utils/database.py | 8 ++++++++ asu/views.py | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/asu/utils/database.py b/asu/utils/database.py index 30f6cc6c..44c49e42 100644 --- a/asu/utils/database.py +++ b/asu/utils/database.py @@ -2,6 +2,7 @@ import pyodbc import logging import json +import os.path class Database: @@ -32,6 +33,13 @@ def connect(self): def commit(self): self.cnxn.commit() + def init_db(self): + self.log.info("database init") + utils_folder = os.path.dirname(os.path.abspath(__file__)) + with open(utils_folder + "/tables.sql", "r") as tables_file: + self.c.execute(tables_file.read()) + self.log.info("database init successful") + def insert_target(self, distro, version, targets): sql = "insert into targets (distro, version, target) values (?, ?, ?);" self.cnxn.autocommit = False diff --git a/asu/views.py b/asu/views.py index 888ead4b..cbeabe94 100644 --- a/asu/views.py +++ b/asu/views.py @@ -7,6 +7,7 @@ from http import HTTPStatus import urllib.request import yaml +import click from asu.build_request import BuildRequest from asu.upgrade_check import UpgradeCheck @@ -181,6 +182,18 @@ def api_supported(): return mime_json(database.get_supported_targets_json()) +@app.cli.command() +def initdb(): + database.init_db() + + +@app.cli.command() +def loaddb(): + fetch_targets() + load_tables() + insert_board_rename() + + @app.cli.command() def run_worker(): from asu.utils.garbagecollector import GarbageCollector @@ -205,14 +218,6 @@ def run_worker(): uper.start() -@app.cli.command() -def load_database(): - fetch_targets() - load_tables() - insert_board_rename() - - -@app.cli.command() def fetch_targets(): for distro in config.get("active_distros", ["openwrt"]): # set distro alias like OpenWrt, fallback would be openwrt