Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. """
  2. mbed SDK
  3. Copyright (c) 2011-2013 ARM Limited
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. """
  14. import sys
  15. from os import listdir, remove, makedirs
  16. from shutil import copyfile
  17. from os.path import isdir, join, exists, split, relpath, splitext
  18. from subprocess import Popen, PIPE, STDOUT, call
  19. def cmd(l, check=True, verbose=False, shell=False, cwd=None):
  20. text = l if shell else ' '.join(l)
  21. if verbose:
  22. print text
  23. rc = call(l, shell=shell, cwd=cwd)
  24. if check and rc != 0:
  25. raise Exception('ERROR %d: "%s"' % (rc, text))
  26. def run_cmd(command, wd=None, redirect=False):
  27. p = Popen(command, stdout=PIPE, stderr=STDOUT if redirect else PIPE, cwd=wd)
  28. _stdout, _stderr = p.communicate()
  29. return _stdout, _stderr, p.returncode
  30. def run_cmd_ext(command):
  31. p = Popen(command, stdout=PIPE, stderr=PIPE)
  32. _stdout, _stderr = p.communicate()
  33. return _stdout, _stderr, p.returncode
  34. def mkdir(path):
  35. if not exists(path):
  36. makedirs(path)
  37. def copy_file(src, dst):
  38. """ Implement the behaviour of "shutil.copy(src, dst)" without copying the
  39. permissions (this was causing errors with directories mounted with samba)
  40. """
  41. if isdir(dst):
  42. _, file = split(src)
  43. dst = join(dst, file)
  44. copyfile(src, dst)
  45. def delete_dir_files(dir):
  46. if not exists(dir):
  47. return
  48. for f in listdir(dir):
  49. file = join(dir, f)
  50. if not isdir(file):
  51. remove(file)
  52. def error(msg):
  53. print msg
  54. sys.exit(1)
  55. def rel_path(path, base, dot=False):
  56. p = relpath(path, base)
  57. if dot and not p.startswith('.'):
  58. p = './' + p
  59. return p
  60. class ToolException(Exception):
  61. pass
  62. def split_path(path):
  63. base, file = split(path)
  64. name, ext = splitext(file)
  65. return base, name, ext
  66. def args_error(parser, message):
  67. print "\n\n%s\n\n" % message
  68. parser.print_help()
  69. sys.exit()
  70. def construct_enum(**enums):
  71. """ Create your own pseudo-enums """
  72. return type('Enum', (), enums)
  73. def check_required_modules(required_modules, verbose=True):
  74. """ Function checks for Python modules which should be "importable" (installed)
  75. before test suite can be used.
  76. @return returns True if all modules are installed already
  77. """
  78. import imp
  79. all_modules_found = True
  80. not_installed_modules = []
  81. for module_name in required_modules:
  82. try:
  83. imp.find_module(module_name)
  84. except ImportError as e:
  85. all_modules_found = False
  86. not_installed_modules.append(module_name)
  87. if verbose:
  88. print "Error: %s"% e
  89. if verbose:
  90. if not all_modules_found:
  91. print "Warning: Module(s) %s not installed. Please install required module(s) before using this script."% (', '.join(not_installed_modules))
  92. return all_modules_found