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))
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))
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))
def test_table_3x2_no_header_ascii(): assert pretty_table(table_3x2, fmt="ascii") == table_3x2_ascii_no_header
def test_table_3x2_no_header_csv(): assert pretty_table(table_3x2) == table_3x2_no_header
def test_table_wrong_column_count_less(): with pytest.raises(IndexError): pretty_table(table_3x2, colnames=["oops"])
def test_table_wrong_column_count_more(): with pytest.raises(IndexError): pretty_table(table_3x1, colnames=["zero", "one"])
def test_table_3x1_header_ascii(): assert (pretty_table(table_3x1, colnames=table_3x1_colnames, fmt="ascii") == table_3x1_ascii_header)
def test_table_3x1_header_csv(): assert pretty_table(table_3x1, colnames=table_3x1_colnames) == table_3x1_csv_header
def test_table_just_headers_ascii(): assert (pretty_table( table_null, fmt="ascii", colnames=table_null_colnames) == table_just_headers_out_ascii)
def test_table_just_headers_csv(): assert (pretty_table( table_null, colnames=table_null_colnames) == table_just_headers_out_csv)
def test_table_0_ascii(): assert pretty_table(table_null, fmt="ascii") == table_null_out_ascii
def test_table_0_csv(): assert pretty_table(table_null) == table_null_out_csv
def test_table_2x5_header_ascii(): assert (pretty_table(table_2x5, colnames=table_2x5_colnames, fmt="ascii") == table_2x5_ascii_header)