コード例 #1
0
def identify(package, product, base, ascii):
    """List products that include specified package."""
    rpm = RPM.from_name(package)
    if not rpm:
        error_exit(
            f"{package} does not appear to be in valid <name>-<version>-<release>.<arch>[.rpm]"
        )
    products = None
    conn = sqlite3.connect(db)
    query_values = rpm.to_dict()
    query_values["base_product"] = base
    query_values["product"] = product
    with conn:
        cur = conn.cursor()
        if product == "*" and base == "*":
            cur.execute(sccpdb.search_products_by_rpm, query_values)
        elif base != "*":
            cur.execute(sccpdb.create_product_family_temp_table, query_values)
            cur.execute(sccpdb.search_product_family_by_rpm, query_values)
        else:
            cur.execute(sccpdb.search_product_by_rpm, query_values)
        products = cur.fetchall()
        cur.close()
    conn.close()
    output = pretty_table(
        products,
        colnames=["id", "product", "type", "arch", "description"],
        fmt="ascii" if ascii else "csv",
    )
    print("\n".join(output))
コード例 #2
0
def base(ascii):
    """List base products."""
    products = None
    conn = sqlite3.connect(db)
    with conn:
        cur = conn.cursor()
        cur.execute(sccpdb.list_base_products)
        products = cur.fetchall()
        cur.close()
    conn.close()
    if not products:
        error_exit("No base products found, suggest an sccpsync.")
    output = pretty_table(
        products,
        colnames=["id", "product", "type", "arch", "description"],
        fmt="ascii" if ascii else "csv",
    )
    print("\n".join(output))
コード例 #3
0
def products(base, ascii):
    """List products associated with specified base."""
    products = None
    conn = sqlite3.connect(db)
    with conn:
        cur = conn.cursor()
        if base == "*":
            cur.execute(sccpdb.list_all_products)
        else:
            cur.execute(sccpdb.list_products_by_base, {"base_product": base})
        products = cur.fetchall()
        cur.close()
    conn.close()
    if not products:
        error_exit("No base products found, suggest an sccpsync.")
    output = pretty_table(
        products,
        colnames=["id", "product", "type", "arch", "description"],
        fmt="ascii" if ascii else "csv",
    )
    print("\n".join(output))
コード例 #4
0
def test_table_3x2_no_header_ascii():
    assert pretty_table(table_3x2, fmt="ascii") == table_3x2_ascii_no_header
コード例 #5
0
def test_table_3x2_no_header_csv():
    assert pretty_table(table_3x2) == table_3x2_no_header
コード例 #6
0
def test_table_wrong_column_count_less():
    with pytest.raises(IndexError):
        pretty_table(table_3x2, colnames=["oops"])
コード例 #7
0
def test_table_wrong_column_count_more():
    with pytest.raises(IndexError):
        pretty_table(table_3x1, colnames=["zero", "one"])
コード例 #8
0
def test_table_3x1_header_ascii():
    assert (pretty_table(table_3x1, colnames=table_3x1_colnames,
                         fmt="ascii") == table_3x1_ascii_header)
コード例 #9
0
def test_table_3x1_header_csv():
    assert pretty_table(table_3x1,
                        colnames=table_3x1_colnames) == table_3x1_csv_header
コード例 #10
0
def test_table_just_headers_ascii():
    assert (pretty_table(
        table_null, fmt="ascii",
        colnames=table_null_colnames) == table_just_headers_out_ascii)
コード例 #11
0
def test_table_just_headers_csv():
    assert (pretty_table(
        table_null,
        colnames=table_null_colnames) == table_just_headers_out_csv)
コード例 #12
0
def test_table_0_ascii():
    assert pretty_table(table_null, fmt="ascii") == table_null_out_ascii
コード例 #13
0
def test_table_0_csv():
    assert pretty_table(table_null) == table_null_out_csv
コード例 #14
0
def test_table_2x5_header_ascii():
    assert (pretty_table(table_2x5, colnames=table_2x5_colnames,
                         fmt="ascii") == table_2x5_ascii_header)