Ejemplo n.º 1
0
def report(inpt, info):
    """Performs a search with the input, then passes the results to dataprint's export to create a simply report."""
    view = -1
    
    if "-v" in inpt:
        view = inpt.index("-v")+1
    elif "--view" in inpt:
        view = inpt.index("--view")+1
        
    if view != -1:
        filename = " ".join(inpt[view:])
        print()
        
        if filename.lower() in theme.LIST_FILES:
            fileview("./reports/")
        elif filename.lower() in theme.LIST_TEMPS:
            fileview("./templates/")
        else: 
            filename += ".txt" if filename[-4:] != ".txt" else ""
            
            with open("reports/"+filename, "r") as rep:
                for line in rep:
                    print(line, end="")
                    
        input(theme.PAUSE)
    else:
        rep, templ = get_template(info, inpt)
        
        args = [el for el in inpt]
        sql_query = query.parse_sql(inpt, info[1], "search")

        columns, results = query.execute_sql(info[0], sql_query)
        dataprint.export(columns, results, tb=info[1], args="report " + " ".join(args), source=info[1], template=templ, rep_name=rep)
Ejemplo n.º 2
0
def cmd_stats(inpt, info):
    """Intermediary function for dataprint's stats function."""
    sql_query = query.parse_sql(inpt, info[1], "search")

    columns, results = query.execute_sql(info[0], sql_query)
    dataprint.stats(columns, results)
    input(theme.PAUSE)
Ejemplo n.º 3
0
def search(inpt, info):
    """Runs a DB search then acts as an intermediary function for dataprint's table function."""
    sql_query = query.parse_sql(inpt, info[1], "search")

    columns, results = query.execute_sql(info[0], sql_query)
    dataprint.table(columns, results)
    
    input(theme.PAUSE)
Ejemplo n.º 4
0
def distinct(inpt, info):
    """Executes a standard search query, then cuts out non-distinct records.
    After, executes dataprint functions: stats, report, or search on the results set."""
    rep = -1
    templ = None
    
    op = find_op(inpt, "-C", "--command")
    
    if op == "report":
        rep, templ = get_template(info, inpt)
        
    sql_query = query.parse_sql(inpt[1:], info[1], "search")
    
    columns, results = query.execute_sql(info[0], sql_query)
    pivot = columns.index(inpt[0].capitalize())
    
    dist = set()
    dupl = []
    for i in range(len(results)):
        if results[i][pivot] in dist:
            dupl += [i]
        else:
            dist = dist.union({results[i][pivot]})
            
    dupl.reverse()
    for i in dupl:
        results.pop(i)
        
    if op == "stats":
        dataprint.stats(columns, results)
    elif op == "report":
        
        dataprint.export(columns, results, info[1], "distinct " + " ".join(inpt), source=info[1], template=templ, rep_name=rep)
        return
    elif op == "tsv":
        fileout(columns, results, "\t", info[1])
        return
    elif op == "search":
        dataprint.table(columns, results)

    input(theme.PAUSE)
Ejemplo n.º 5
0
def tsv(inpt, info):
    """Exports a search query to TSV."""
    sql_query = query.parse_sql(inpt, info[1], "search")
    
    columns, results = query.execute_sql(info[0], sql_query)
    fileout(columns, results, "\t", info[1])
Ejemplo n.º 6
0
def remove(inpt, info):
    """Intermediary function to remove some set of records from the current DB host table."""
    sql_query = query.parse_sql(inpt, info[1], "remove")

    query.execute_sql(info[0], sql_query)
    info[0].commit()