Skip to content

Commit

Permalink
fixup cli and add initdb
Browse files Browse the repository at this point in the history
  • Loading branch information
aparcar committed Mar 7, 2019
1 parent 958f5ce commit 269f26e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
8 changes: 8 additions & 0 deletions asu/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pyodbc
import logging
import json
import os.path


class Database:
Expand Down Expand Up @@ -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
Expand Down
21 changes: 13 additions & 8 deletions asu/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 269f26e

Please sign in to comment.