_linux.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #*****************************************************************************
  2. # Copyright 2013 Thomas Calmant
  3. #
  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. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. #*****************************************************************************
  17. import os
  18. from . import _jvmfinder
  19. # ------------------------------------------------------------------------------
  20. class LinuxJVMFinder(_jvmfinder.JVMFinder):
  21. """
  22. Linux JVM library finder class
  23. """
  24. def __init__(self):
  25. """
  26. Sets up members
  27. """
  28. # Call the parent constructor
  29. _jvmfinder.JVMFinder.__init__(self)
  30. # Java bin file
  31. self._java = "/usr/bin/java"
  32. # Library file name
  33. self._libfile = "libjvm.so"
  34. # Predefined locations
  35. self._locations = ("/usr/lib/jvm", "/usr/java", "/opt/sun")
  36. # Search methods
  37. self._methods = (self._get_from_java_home,
  38. self._get_from_bin,
  39. self._get_from_known_locations)
  40. def _get_from_bin(self):
  41. """
  42. Retrieves the Java library path according to the real installation of
  43. the java executable
  44. :return: The path to the JVM library, or None
  45. """
  46. # Find the real interpreter installation path
  47. java_bin = os.path.realpath(self._java)
  48. if os.path.exists(java_bin):
  49. # Get to the home directory
  50. java_home = os.path.abspath(os.path.join(os.path.dirname(java_bin),
  51. '..'))
  52. # Look for the JVM library
  53. return self.find_libjvm(java_home)