Skip to content

Commit 269f26e

Browse files
committed
fixup cli and add initdb
1 parent 958f5ce commit 269f26e

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

asu/utils/database.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import pyodbc
33
import logging
44
import json
5+
import os.path
56

67

78
class Database:
@@ -32,6 +33,13 @@ def connect(self):
3233
def commit(self):
3334
self.cnxn.commit()
3435

36+
def init_db(self):
37+
self.log.info("database init")
38+
utils_folder = os.path.dirname(os.path.abspath(__file__))
39+
with open(utils_folder + "/tables.sql", "r") as tables_file:
40+
self.c.execute(tables_file.read())
41+
self.log.info("database init successful")
42+
3543
def insert_target(self, distro, version, targets):
3644
sql = "insert into targets (distro, version, target) values (?, ?, ?);"
3745
self.cnxn.autocommit = False

asu/views.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from http import HTTPStatus
88
import urllib.request
99
import yaml
10+
import click
1011

1112
from asu.build_request import BuildRequest
1213
from asu.upgrade_check import UpgradeCheck
@@ -181,6 +182,18 @@ def api_supported():
181182
return mime_json(database.get_supported_targets_json())
182183

183184

185+
@app.cli.command()
186+
def initdb():
187+
database.init_db()
188+
189+
190+
@app.cli.command()
191+
def loaddb():
192+
fetch_targets()
193+
load_tables()
194+
insert_board_rename()
195+
196+
184197
@app.cli.command()
185198
def run_worker():
186199
from asu.utils.garbagecollector import GarbageCollector
@@ -205,14 +218,6 @@ def run_worker():
205218
uper.start()
206219

207220

208-
@app.cli.command()
209-
def load_database():
210-
fetch_targets()
211-
load_tables()
212-
insert_board_rename()
213-
214-
215-
@app.cli.command()
216221
def fetch_targets():
217222
for distro in config.get("active_distros", ["openwrt"]):
218223
# set distro alias like OpenWrt, fallback would be openwrt

0 commit comments

Comments
 (0)