build-recipe-list.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #!/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. import os
  15. import shutil
  16. import csv
  17. import sys
  18. import argparse
  19. __version__ = "0.1.0"
  20. recipenames = []
  21. allrecipes = []
  22. def gather_recipes(rows):
  23. # store the data into the array
  24. for row in rows:
  25. if row[0] not in recipenames:
  26. recipenames.append(row[0])
  27. allrecipes.append(row)
  28. def generate_recipe_list():
  29. # machine list
  30. machine_list = ( "qemuarm64", "qemuarm", "qemumips64", "qemumips", "qemuppc", "qemux86-64", "qemux86" )
  31. # set filename format
  32. fnformat = 'distrodata.%s.csv'
  33. # store all data files in distrodata
  34. datadir = 'distrodata'
  35. # create the directory if it does not exists
  36. if not os.path.exists(datadir):
  37. os.mkdir(datadir)
  38. # doing bitbake distrodata
  39. for machine in machine_list:
  40. os.system('MACHINE='+ machine + ' bitbake world -c distrodata')
  41. shutil.copy('tmp/log/distrodata.csv', 'distrodata/' + fnformat % machine)
  42. for machine in machine_list:
  43. with open('distrodata/' + fnformat % machine) as f:
  44. reader = csv.reader(f)
  45. rows = reader.__iter__()
  46. gather_recipes(rows)
  47. with open('recipe-list.txt', 'w') as f:
  48. for recipe in sorted(recipenames):
  49. f.write("%s\n" % recipe)
  50. print("file : recipe-list.txt is created with %d entries." % len(recipenames))
  51. with open('all-recipe-list.txt', 'w') as f:
  52. for recipe in sorted(allrecipes):
  53. f.write("%s\n" % ','.join([str(data) for data in recipe]))
  54. def diff_for_new_recipes(recipe1, recipe2):
  55. prev_recipe_path = recipe1 + '/'
  56. curr_recipe_path = recipe2 + '/'
  57. if not os.path.isfile(prev_recipe_path + 'recipe-list.txt') or not os.path.isfile(curr_recipe_path + 'recipe-list.txt'):
  58. print("recipe files do not exists. please verify that the file exists.")
  59. exit(1)
  60. import csv
  61. prev = []
  62. new = []
  63. with open(prev_recipe_path + 'recipe-list.txt') as f:
  64. prev = f.readlines()
  65. with open(curr_recipe_path + 'recipe-list.txt') as f:
  66. new = f.readlines()
  67. updates = []
  68. for pn in new:
  69. if not pn in prev:
  70. updates.append(pn.rstrip())
  71. allrecipe = []
  72. with open(recipe1 + '_' + recipe2 + '_new_recipe_list.txt','w') as dr:
  73. with open(curr_recipe_path + 'all-recipe-list.txt') as f:
  74. reader = csv.reader(f, delimiter=',')
  75. for row in reader:
  76. if row[0] in updates:
  77. dr.write("%s,%s,%s" % (row[0], row[3], row[5]))
  78. if len(row[9:]) > 0:
  79. dr.write(",%s" % ','.join(row[9:]))
  80. dr.write("\n")
  81. def main(argv):
  82. if argv[0] == "generate_recipe_list":
  83. generate_recipe_list()
  84. elif argv[0] == "compare_recipe":
  85. diff_for_new_recipes(argv[1], argv[2])
  86. else:
  87. print("no such option. choose either 'generate_recipe_list' or 'compare_recipe'")
  88. exit(0)
  89. if __name__ == "__main__":
  90. try:
  91. sys.exit(main(sys.argv[1:]))
  92. except Exception as e:
  93. print("Exception :", e)
  94. sys.exit(1)