Example #1
0
def create_exportdb(dbfilename):
    db_export = ldb.LogsDB(dbfilename)
    db_export_file = os.path.abspath(db_export.database_file)
    logging.info("using db file: " + db_export_file)
    # make sure export db is new
    if os.path.exists(db_export_file):
        raise Exception("export db must be new. exists already: " +
                        db_export_file)
    # return db (is intended to be used in a "with" statement)
    return db_export
Example #2
0
args = parser.parse_args()

# set log level
if args.verbose:
	logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
else:
	logging.basicConfig(stream=sys.stderr, level=logging.WARNING)

if args.force_cleanup_all and args.force_cleanup_ignored:
	raise Exception("inconsistent parameters: not --force_cleanup_all and --force_cleanup_ignored at the same time")

if args.force_cleanup_all:
	force_cleanup = "all"
elif args.force_cleanup_ignored:
	force_cleanup = "ignored"
else:
	force_cleanup = None

# create prog platform object
progplat = progplatform.get_embexp_ProgPlatform(args.embexp_path)

# db connection
print("opening db...")
print()
with ldb.LogsDB() as db:
	exp = experiment.Experiment(db, int(args.exp_id))
	exp_runner.run_experiment(exp, progplat, args.board_type, args.branchname, args.conn_mode, force_cleanup, args.no_post_clean, True, run_input_state=args.input_state)



Example #3
0
# obtain run_spec
run_spec = args.run_spec
if run_spec == None:
    assert arch_id == "arm8"
    assert board_type == "rpi3" or board_type == "rpi4"
    progplat_hash = progplatform.get_embexp_ProgPlatform(
        None).get_branch_commit_hash(
            progplatform.get_default_branch(board_type))
    run_spec = experiment._mk_run_spec(progplat_hash, board_type)

print(f"run_spec = {run_spec}")
print()

print("opening db...")
print()
db = ldb.LogsDB(read_only=True)
db.connect()

if args.print_structures:
    print("holba runs: ")
    for hbar in holbarun.HolbaRun._get_all(db):
        print(f"- '{hbar.get_name()}'")
    print("experiment lists: ")
    for el in logslist.LogsList._get_all(db, "exp"):
        print(
            f"- '{el.get_name()}' (cnt={len(el.get_entry_ids())}, '{el.get_description()}')"
        )
    print("program lists: ")
    for el in logslist.LogsList._get_all(db, "prog"):
        print(
            f"- '{el.get_name()}' (cnt={len(el.get_entry_ids())}, '{el.get_description()}')"
Example #4
0
if args.verbose:
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
else:
    logging.basicConfig(stream=sys.stderr, level=logging.WARNING)

listname = args.listname
board_type = args.board_type
run_once = args.run_once

# create prog platform object
progplat = progplatform.get_embexp_ProgPlatform(args.embexp_path)

# db connection
print("opening db...")
print()
db = ldb.LogsDB()
db.connect()

# define experiment finding
progplat_hash = progplat.get_branch_commit_hash(
    progplatform.get_default_branch(board_type))
run_spec = experiment._mk_run_spec(progplat_hash, board_type)


def is_latest_exp_run_not_complete(exp):
    run_id = exp.get_latest_run_id(run_spec)
    if run_id == None:
        return True  # no run
    run_data = exp.get_run_data(run_id)
    return not experiment.Experiment.is_complete_run(run_data)
Example #5
0
    logging.basicConfig(stream=sys.stderr, level=logging.WARNING)

input_data = args.input
is_testing = args.testing

# retrieve query string from stdin
logging.info(f"loading query string.")
if input_data != None:
    sql_str = input_data
else:
    logging.info(f"from stdin...")
    sql_str = sys.stdin.read()

# create db access object
alt_db_file = None if not is_testing else "data/testing.db"
with ldb.LogsDB(alt_db_file, read_only=True) as db:
    # execute query
    (fields, rows) = db.get_tablerecords_sql(sql_str)


def simple_print(fields, rows):
    print(fields)
    print("=" * 40)
    print()
    for row in rows:
        print(row)


def print_with_pandas(fields, rows):
    import pandas as pd
Example #6
0
import argparse
import logging

import logsdb as ldb

# parse arguments
parser = argparse.ArgumentParser()

parser.add_argument("-t", "--testing", help="uses testing database (i.e. for testing only)", action="store_true")

parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true")

args = parser.parse_args()

# set log level
if args.verbose:
	logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
else:
	logging.basicConfig(stream=sys.stderr, level=logging.WARNING)

is_testing = args.testing

# create db access object and run backup
alt_db_file = None if not is_testing else "data/testing.db"
with ldb.LogsDB(alt_db_file) as db:
	db.backup()


print("Backup finished.")

Example #7
0
		# fetching arguments
		sql = q["sql"]
		# execute sql query and return results
		(fields, rows) = db.get_tablerecords_sql(sql)
		return {"fields": fields, "rows": rows}

	# d) unknown query type
	else:
		raise Exception("unknown query type: " + q_type)


opdict = {"create"  : op_create,
          "append"  : op_append,
          "query"   : op_query}

# select operation accordingly
logging.info(f"executing operation {operation}")
opfun = opdict[operation]

# create db access object
alt_db_file = None if not is_testing else "data/testing.db"
with ldb.LogsDB(alt_db_file, read_only=is_read_only) as db:
	# execute operation
	ret_val = opfun(db, json_arguments)

# return value is serialized with json and printed on stdout
print(json.dumps(ret_val))



Example #8
0
    print(f"exps until first cexp gen    = {firstcounterexample_id}")


def iterate_holba_runs(db):
    res = db.get_tablerecords_sql("""
-- go through holba run parameters and find corresponding experiment list
-- ================================================
select r.id, r.name, r_m.value, r.exp_exps_lists_id, r.exp_progs_lists_id
from holba_runs_meta as r_m
inner join holba_runs as r on r.id = r_m.holba_runs_id
where r_m.kind = "args"
""")
    for (holba_run_id, holba_run_name, holba_run_args, exps_list_id,
         progs_list_id) in res[1]:
        print(f"Scam-V/HolBA run id: {holba_run_name}")
        print(50 * "=")
        print(f"exps_list_id = {exps_list_id}")
        print(f"progs_list_id = {progs_list_id}")
        print()
        print(f"Scam-V arguments = {holba_run_args}")
        print()
        print_gen_run_time(db, holba_run_id)
        print()
        print_experimentdata(db, exps_list_id)
        print()
        print()


with ldb.LogsDB(dbfile_src, read_only=True) as db:
    iterate_holba_runs(db)
Example #9
0
    # query something without tablename
    _db_meta_ver_3 = db.get_tablerecords_sql(
        "select kind from db_meta where id = 0")
    assert (_db_meta_ver_3 == (['kind'], [['logsdb']]))


# start with testing procedure
# ======================================================================================================================

# clear testing database
db_file = "data/testing.db"
if os.path.isfile(db_file):
    os.remove(db_file)

# run initial tests on logsdb library (initializes db into defined state)
with ldb.LogsDB(db_file) as db:
    initial_db_tests(db)
# run initial readonly tests (raw sql query)
with ldb.LogsDB(db_file, read_only=True) as db:
    initial_readonly_db_tests(db)


# helper to check calls to db-interface.py
# ======================================================================================================================
def run_db_interface_py(c, i, str_in_output=None, read_only=False):
    from subprocess import Popen, PIPE, STDOUT
    import json
    p = Popen(["./scripts/db-interface.py", "-t", c] +
              (["-ro"] if read_only else []),
              stdout=PIPE,
              stdin=PIPE,