summaryrefslogtreecommitdiffstats
path: root/scripts/distro/build-recipe-list.py
blob: 407debaa76a3ef73cc7167a489f9703ccaeaaf74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#!/usr/bin/env python3
#
# Copyright (c) 2017, Intel Corporation.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 2, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
# more details.
#

import os
import shutil
import csv
import sys
import argparse

__version__ = "0.1.0"

recipenames = []
allrecipes = []
 
def gather_recipes(rows):
    # store the data into the array
    for row in rows:
        if row[0] not in recipenames:
            recipenames.append(row[0])
            allrecipes.append(row)

def generate_recipe_list():
    # machine list
    machine_list = ( "qemuarm64", "qemuarm", "qemumips64", "qemumips", "qemuppc", "qemux86-64", "qemux86" )
    # set filename format
    fnformat = 'distrodata.%s.csv'

    # store all data files in distrodata
    datadir = 'distrodata'

    # create the directory if it does not exists
    if not os.path.exists(datadir):
        os.mkdir(datadir)

    # doing bitbake distrodata
    for machine in machine_list:
        os.system('MACHINE='+ machine + ' bitbake world -c distrodata')
        shutil.copy('tmp/log/distrodata.csv', 'distrodata/' + fnformat % machine)

    for machine in machine_list:
        with open('distrodata/' + fnformat % machine) as f:
            reader = csv.reader(f)
            rows = reader.__iter__()
            gather_recipes(rows)

    with open('recipe-list.txt', 'w') as f:
        for recipe in sorted(recipenames):
            f.write("%s\n" % recipe)
    print("file : recipe-list.txt is created with %d entries." % len(recipenames))

    with open('all-recipe-list.txt', 'w') as f:
        for recipe in sorted(allrecipes):
            f.write("%s\n" % ','.join([str(data) for data in recipe]))


def diff_for_new_recipes(recipe1, recipe2):
    prev_recipe_path = recipe1 + '/'
    curr_recipe_path = recipe2 + '/'
    if not os.path.isfile(prev_recipe_path + 'recipe-list.txt') or not os.path.isfile(curr_recipe_path + 'recipe-list.txt'):
        print("recipe files do not exists. please verify that the file exists.")
        exit(1)

    import csv

    prev = []
    new = []

    with open(prev_recipe_path + 'recipe-list.txt') as f:
        prev = f.readlines()

    with open(curr_recipe_path + 'recipe-list.txt') as f:
        new = f.readlines()

    updates = []
    for pn in new:
        if not pn in prev:
            updates.append(pn.rstrip())

    allrecipe = []
    with open(recipe1 + '_' + recipe2 + '_new_recipe_list.txt','w') as dr:
        with open(curr_recipe_path + 'all-recipe-list.txt') as f:
            reader = csv.reader(f, delimiter=',')
            for row in reader:
                if row[0] in updates:
                    dr.write("%s,%s,%s" % (row[0], row[3], row[5]))
                    if len(row[9:]) > 0:
                        dr.write(",%s" % ','.join(row[9:]))
                    dr.write("\n")

def main(argv):
    if argv[0] == "generate_recipe_list":
        generate_recipe_list()
    elif argv[0] == "compare_recipe":
        diff_for_new_recipes(argv[1], argv[2])
    else:
        print("no such option. choose either 'generate_recipe_list' or 'compare_recipe'")

    exit(0)

if __name__ == "__main__":
    try:
        sys.exit(main(sys.argv[1:]))
    except Exception as e:
        print("Exception :", e)
        sys.exit(1)