blob: 21627648509e9b45c6de2f5316577c4c73259832 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001#!/usr/bin/env python3
2#
3# Copyright (c) 2017, Intel Corporation.
4#
5# This program is free software; you can redistribute it and/or modify it
6# under the terms and conditions of the GNU General Public License,
7# version 2, as published by the Free Software Foundation.
8#
9# This program is distributed in the hope it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12# more details.
13#
14
15import os
16import shutil
17import csv
18import sys
19import argparse
20
21__version__ = "0.1.0"
22
23# set of BPNs
24recipenames = set()
25# map of recipe -> data
26allrecipes = {}
27
28def make_bpn(recipe):
29 prefixes = ("nativesdk-",)
30 suffixes = ("-native", "-cross", "-initial", "-intermediate", "-crosssdk", "-cross-canadian")
31 for ix in prefixes + suffixes:
32 if ix in recipe:
33 recipe = recipe.replace(ix, "")
34 return recipe
35
36def gather_recipes(rows):
37 for row in rows:
38 recipe = row[0]
39 bpn = make_bpn(recipe)
40 if bpn not in recipenames:
41 recipenames.add(bpn)
42 if recipe not in allrecipes:
43 allrecipes[recipe] = row
44
45def generate_recipe_list():
46 # machine list
47 machine_list = ( "qemuarm64", "qemuarm", "qemumips64", "qemumips", "qemuppc", "qemux86-64", "qemux86" )
48 # set filename format
49 fnformat = 'distrodata.%s.csv'
50
51 # store all data files in distrodata
52 datadir = 'distrodata'
53
54 # create the directory if it does not exists
55 if not os.path.exists(datadir):
56 os.mkdir(datadir)
57
58 # doing bitbake distrodata
59 for machine in machine_list:
60 os.system('MACHINE='+ machine + ' bitbake -k universe -c distrodata')
61 shutil.copy('tmp/log/distrodata.csv', 'distrodata/' + fnformat % machine)
62
63 for machine in machine_list:
64 with open('distrodata/' + fnformat % machine) as f:
65 reader = csv.reader(f)
66 rows = reader.__iter__()
67 gather_recipes(rows)
68
69 with open('recipe-list.txt', 'w') as f:
70 for recipe in sorted(recipenames):
71 f.write("%s\n" % recipe)
72 print("file : recipe-list.txt is created with %d entries." % len(recipenames))
73
74 with open('all-recipe-list.txt', 'w') as f:
75 for recipe, row in sorted(allrecipes.items()):
76 f.write("%s\n" % ','.join(row))
77
78
79def diff_for_new_recipes(recipe1, recipe2):
80 prev_recipe_path = recipe1 + '/'
81 curr_recipe_path = recipe2 + '/'
82 if not os.path.isfile(prev_recipe_path + 'recipe-list.txt') or not os.path.isfile(curr_recipe_path + 'recipe-list.txt'):
83 print("recipe files do not exists. please verify that the file exists.")
84 exit(1)
85
86 import csv
87
88 prev = []
89 new = []
90
91 with open(prev_recipe_path + 'recipe-list.txt') as f:
92 prev = f.readlines()
93
94 with open(curr_recipe_path + 'recipe-list.txt') as f:
95 new = f.readlines()
96
97 updates = []
98 for pn in new:
99 if not pn in prev:
100 updates.append(pn.rstrip())
101
102 allrecipe = []
103 with open(recipe1 + '_' + recipe2 + '_new_recipe_list.txt','w') as dr:
104 with open(curr_recipe_path + 'all-recipe-list.txt') as f:
105 reader = csv.reader(f, delimiter=',')
106 for row in reader:
107 if row[0] in updates:
108 dr.write("%s,%s,%s" % (row[0], row[3], row[5]))
109 if len(row[9:]) > 0:
110 dr.write(",%s" % ','.join(row[9:]))
111 dr.write("\n")
112
113def main(argv):
114 if argv[0] == "generate_recipe_list":
115 generate_recipe_list()
116 elif argv[0] == "compare_recipe":
117 diff_for_new_recipes(argv[1], argv[2])
118 else:
119 print("no such option. choose either 'generate_recipe_list' or 'compare_recipe'")
120
121 exit(0)
122
123if __name__ == "__main__":
124 try:
125 sys.exit(main(sys.argv[1:]))
126 except Exception as e:
127 print("Exception :", e)
128 sys.exit(1)
129