Esempio n. 1
0
def _maybe_register_license(path=None):
    """Registers the MuJoCo license if not already registered.

  Args:
    path: Optional custom path to license key file.

  Raises:
    Error: If the license could not be registered.
  """
    with _REGISTRATION_LOCK:
        global _REGISTERED
        if not _REGISTERED:
            if path is None:
                path = util.get_mjkey_path()
            # TODO(b/176220357): Repeatedly activating a trial license results in
            #                    errors (for example this could happen if
            #                    `mj_activate` was already called by another library
            #                    within the same process). To avoid such errors we
            #                    unconditionally deactivate any active licenses before
            #                    calling `mj_activate`.
            mjlib.mj_deactivate()
            result = mjlib.mj_activate(util.to_binary_string(path))
            if result == 1:
                _REGISTERED = True
                # Internal analytics of mj_activate.
            elif result == 0:
                raise Error("Could not register license.")
            else:
                raise Error(
                    "Unknown registration error (code: {})".format(result))
Esempio n. 2
0
def _maybe_register_license(path=None):
  """Registers the MuJoCo license if not already registered.

  Args:
    path: Optional custom path to license key file.

  Raises:
    Error: If the license could not be registered.
  """
  global _REGISTERED
  if not _REGISTERED:
    if path is None:
      path = util.get_mjkey_path()
    result = mjlib.mj_activate(util.to_binary_string(path))
    if result == 1:
      _REGISTERED = True
    elif result == 0:
      raise Error("Could not register license.")
    else:
      raise Error("Unknown registration error (code: {})".format(result))
Esempio n. 3
0
 def testErrorCallback(self):
     with mock.patch.object(core, "logging") as mock_logging:
         mjlib.mj_activate(b"nonexistent_activation_key")
     mock_logging.fatal.assert_called_once_with(
         "Could not open activation key file nonexistent_activation_key")