Exemplo n.º 1
0
def run(pl_path, ds_path):
    out_dir = '.'
    out_path = os.path.join(out_dir, os.path.basename(pl_path) + '.csv')

    pl_entries = patchtoolslib.read_txt_as_list(pl_path)
    #print(pl_entries)

    merged_data_rows = []
    num_rows = 0
    for product_fex_path in pl_entries:

        csv_data_path = os.path.normpath(os.path.join(ds_path, os.path.join(product_fex_path, 'fex-overview.csv')))
        data_rows = patchtoolslib.read_csv_as_list(csv_data_path)

        csv_label_path = os.path.normpath(os.path.join(ds_path, product_fex_path + ".txt"))
        label_rows = patchtoolslib.read_csv_as_list(csv_label_path)

        if len(data_rows) != len(label_rows):
            raise ValueError('Expected ' + str(len(data_rows)) + ' labelled rows, but got ' + str(len(label_rows)))

        for i in range(len(data_rows)):
            data_row = data_rows[i]
            label_row = label_rows[i]
            if i == 0 and num_rows == 0:
                data_row.insert(0, 'product')
                data_row.extend(label_row)
                merged_data_rows.append(data_row)
                num_rows += 1
            elif i > 0:
                data_row.insert(0, product_fex_path)
                data_row.extend(label_row)
                merged_data_rows.append(data_row)
                num_rows += 1


    #print(merged_data_rows)

    with open(out_path, 'w', newline='') as file:
        w = csv.writer(file, delimiter='\t')
        w.writerows(merged_data_rows)

    print('Written ' + out_path)
Exemplo n.º 2
0
def read_patch_list_entries(pl_path):
    return [os.path.split(pl_line.strip()) for pl_line in patchtoolslib.read_txt_as_list(pl_path)]