code: def get_diag(code, command):
      
      import tempfile
      import shutil
      code = code + u'\n'
  
      try:
          tmpdir = tempfile.mkdtemp()
          fd, diag_name = tempfile.mkstemp(dir=tmpdir)
  
          f = os.fdopen(fd, "w")
          f.write(code.encode('utf-8'))
          f.close()
  
          format = _draw_mode.lower()
          draw_name = diag_name + '.' + format
  
          saved_argv = sys.argv
          argv = [diag_name, '-T', format, '-o', draw_name]
  
          if _draw_mode == 'SVG':
              argv += ['--ignore-pil']
  
          # Run command
          command.main(argv)
  
          # Read image data from file
          file_name = diag_name + '.' + _publish_mode.lower()
  
          with io.open(file_name, 'rb') as f:
              data = f.read()
              f.close()
  
      finally:
          for file in os.listdir(tmpdir):
              os.unlink(tmpdir + "/" + file)
  
          # os.rmdir will fail -> use shutil
          shutil.rmtree(tmpdir)
  
      return data
docs: Generate diagramm and return data