fold_block.py 796 B

123456789101112131415161718192021222324252627282930
  1. import os
  2. next_block_id = 1
  3. class Fold(object):
  4. def __init__(self):
  5. global next_block_id
  6. self.block_id = next_block_id
  7. next_block_id += 1
  8. def get_message(self, msg=''):
  9. if os.environ.get('TRAVIS') == 'true':
  10. if msg:
  11. msg += ', '
  12. msg += "see folded block '%s' above for details" % self.get_block_name()
  13. return msg
  14. def get_block_name(self):
  15. return 'block%d' % self.block_id
  16. def __enter__(self):
  17. if os.environ.get('TRAVIS') == 'true':
  18. print('travis_fold:start:%s' % self.get_block_name())
  19. return self
  20. def __exit__(self, type, value, traceback):
  21. if os.environ.get('TRAVIS') == 'true':
  22. print('travis_fold:end:%s' % self.get_block_name())