yocto-bsp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. #!/usr/bin/env python
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. #
  5. # Copyright (c) 2012, Intel Corporation.
  6. # All rights reserved.
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. # DESCRIPTION
  22. # 'yocto-bsp' is the Yocto BSP Tool that helps users create a new
  23. # Yocto BSP. Invoking it without any arguments will display help
  24. # screens for the 'yocto-bsp' command and list the available
  25. # 'yocto-bsp' subcommands. Invoking a subcommand without any
  26. # arguments will likewise display help screens for the specified
  27. # subcommand. Please use that interface for detailed help.
  28. #
  29. # AUTHORS
  30. # Tom Zanussi <tom.zanussi (at] intel.com>
  31. #
  32. __version__ = "0.1.0"
  33. import os
  34. import sys
  35. import optparse
  36. import logging
  37. scripts_path = os.path.abspath(os.path.dirname(os.path.abspath(sys.argv[0])))
  38. lib_path = scripts_path + '/lib'
  39. sys.path = sys.path + [lib_path]
  40. from bsp.help import *
  41. from bsp.engine import *
  42. def yocto_bsp_create_subcommand(args, usage_str):
  43. """
  44. Command-line handling for BSP creation. The real work is done by
  45. bsp.engine.yocto_bsp_create()
  46. """
  47. parser = optparse.OptionParser(usage = usage_str)
  48. parser.add_option("-o", "--outdir", dest = "outdir", action = "store",
  49. help = "name of BSP dir to create")
  50. parser.add_option("-i", "--infile", dest = "properties_file", action = "store",
  51. help = "name of file containing the values for BSP properties as a JSON file")
  52. parser.add_option("-c", "--codedump", dest = "codedump", action = "store_true",
  53. default = False, help = "dump the generated code to bspgen.out")
  54. parser.add_option("-s", "--skip-git-check", dest = "git_check", action = "store_false",
  55. default = True, help = "skip the git connectivity check")
  56. (options, args) = parser.parse_args(args)
  57. if len(args) != 2:
  58. logging.error("Wrong number of arguments, exiting\n")
  59. parser.print_help()
  60. sys.exit(1)
  61. machine = args[0]
  62. karch = args[1]
  63. if options.outdir:
  64. bsp_output_dir = options.outdir
  65. else:
  66. bsp_output_dir = "meta-" + machine
  67. if options.git_check and not options.properties_file:
  68. print "Checking basic git connectivity..."
  69. if not verify_git_repo(GIT_CHECK_URI):
  70. print "Couldn't verify git connectivity, exiting\n"
  71. print "Details: couldn't access %s" % GIT_CHECK_URI
  72. print " (this most likely indicates a network connectivity problem or"
  73. print " a misconfigured git intallation)"
  74. sys.exit(1)
  75. else:
  76. print "Done.\n"
  77. yocto_bsp_create(machine, karch, scripts_path, bsp_output_dir, options.codedump, options.properties_file)
  78. def yocto_bsp_list_subcommand(args, usage_str):
  79. """
  80. Command-line handling for listing available BSP properties and
  81. values. The real work is done by bsp.engine.yocto_bsp_list()
  82. """
  83. parser = optparse.OptionParser(usage = usage_str)
  84. parser.add_option("-o", "--outfile", action = "store", dest = "properties_file",
  85. help = "dump the possible values for BSP properties to a JSON file")
  86. (options, args) = parser.parse_args(args)
  87. if not yocto_bsp_list(args, scripts_path, options.properties_file):
  88. logging.error("Bad list arguments, exiting\n")
  89. parser.print_help()
  90. sys.exit(1)
  91. subcommands = {
  92. "create": [yocto_bsp_create_subcommand,
  93. yocto_bsp_create_usage,
  94. yocto_bsp_create_help],
  95. "list": [yocto_bsp_list_subcommand,
  96. yocto_bsp_list_usage,
  97. yocto_bsp_list_help],
  98. }
  99. def start_logging(loglevel):
  100. logging.basicConfig(filname = 'yocto-bsp.log', filemode = 'w', level=loglevel)
  101. def main():
  102. parser = optparse.OptionParser(version = "yocto-bsp version %s" % __version__,
  103. usage = yocto_bsp_usage)
  104. parser.disable_interspersed_args()
  105. parser.add_option("-D", "--debug", dest = "debug", action = "store_true",
  106. default = False, help = "output debug information")
  107. (options, args) = parser.parse_args()
  108. loglevel = logging.INFO
  109. if options.debug:
  110. loglevel = logging.DEBUG
  111. start_logging(loglevel)
  112. if len(args):
  113. if args[0] == "help":
  114. if len(args) == 1:
  115. parser.print_help()
  116. sys.exit(1)
  117. invoke_subcommand(args, parser, yocto_bsp_help_usage, subcommands)
  118. if __name__ == "__main__":
  119. try:
  120. ret = main()
  121. except Exception:
  122. ret = 1
  123. import traceback
  124. traceback.print_exc(5)
  125. sys.exit(ret)