def mayaDocsLocation(version=None): docLocation = None if (version == None or version == versions.installName() ) and mayaIsRunning(): # Return the doc location for the running version of maya from maya.cmds import showHelp docLocation = showHelp("", q=True, docs=True) # Older implementations had no trailing slash, but the result returned by # showHelp has a trailing slash... so eliminate any trailing slashes for # consistency while docLocation != "" and os.path.basename(docLocation) == "": docLocation = os.path.dirname(docLocation) # Want the docs for a different version, or maya isn't initialized yet if not docLocation or not os.path.isdir(docLocation): docLocation = getMayaLocation(version) # use original version if docLocation is None and version is not None: docLocation = getMayaLocation(None) _logger.warning("Could not find an installed Maya for exact version %s, using first installed Maya location found in %s" % (version, docLocation) ) if version: short_version = versions.parseVersionStr(version, extension=False) else: short_version = versions.shortName() if platform.system() == 'Darwin': docLocation = os.path.dirname(os.path.dirname(docLocation)) docLocation = os.path.join(docLocation , 'docs/Maya%s/en_US' % short_version) return os.path.realpath(docLocation)
def mayaDocsLocation(version=None): docLocation = os.environ.get('MAYA_DOC_DIR') if (not docLocation and (version is None or version == versions.installName() ) and mayaIsRunning()): # Return the doc location for the running version of maya from maya.cmds import showHelp docLocation = showHelp("", q=True, docs=True) # Older implementations had no trailing slash, but the result returned by # showHelp has a trailing slash... so eliminate any trailing slashes for # consistency while docLocation != "" and os.path.basename(docLocation) == "": docLocation = os.path.dirname(docLocation) # Want the docs for a different version, or maya isn't initialized yet if not docLocation or not os.path.isdir(docLocation): docBaseDir = os.environ.get('MAYA_DOC_BASE_DIR') if not docBaseDir: docBaseDir = getMayaLocation(version) # use original version if docBaseDir is None and version is not None: docBaseDir = getMayaLocation(None) _logger.warning("Could not find an installed Maya for exact version %s, using first installed Maya location found in %s" % (version, docBaseDir) ) if platform.system() == 'Darwin': docBaseDir = os.path.dirname(os.path.dirname(docBaseDir)) docBaseDir = os.path.join(docBaseDir, 'docs') if version: short_version = versions.parseVersionStr(version, extension=False) else: short_version = versions.shortName() docLocation = os.path.join(docBaseDir , 'Maya%s' % short_version, 'en_US') return os.path.realpath(docLocation)
def getMayaLocation(version=None): # type: (bool) -> Optional[str] """ Get the path to the Maya install directory. .. note:: The Maya location is defined as the directory above /bin. Uses the ``MAYA_LOCATION`` environment variable and ``sys.executable`` path. Returns None if not found. Parameters ---------- version : bool if passed, will attempt to find a matching Maya location. If the version found above does not match the requested version, this function uses a simple find/replace heuristic to modify the path and test if the desired version exists. Returns ------- Optional[str] """ try: loc = os.path.realpath(os.environ['MAYA_LOCATION']) except: loc = os.path.dirname(os.path.dirname(sys.executable)) # get the path of a different maya version than current if version: # note that a recursive loop between getMayaLocation / getMayaVersion # is avoided because getMayaVersion always calls getMayaLocation with # version == None actual_long_version = versions.installName() actual_short_version = versions.shortName() if version != actual_long_version: short_version = versions.parseVersionStr(version, extension=False) if version == short_version: try_version = actual_long_version.replace(actual_short_version, short_version) else: try_version = version try_loc = loc.replace(actual_long_version, try_version) if os.path.exists(try_loc): loc = try_loc else: _logger.warn("No Maya found for version %s" % version) loc = None return loc
def getMayaLocation(version=None): """ Get the path to the Maya install directory. .. note:: The Maya location is defined as the directory above /bin. Uses the ``MAYA_LOCATION`` environment variable and ``sys.executable`` path. Parameters ---------- version : bool if passed, will attempt to find a matching Maya location. If the version found above does not match the requested version, this function uses a simple find/replace heuristic to modify the path and test if the desired version exists. Returns ------- str or None The path to Maya's installation directory or None, if not found """ try: loc = os.path.realpath(os.environ['MAYA_LOCATION']) except: loc = os.path.dirname(os.path.dirname(sys.executable)) # get the path of a different maya version than current if version: # note that a recursive loop between getMayaLocation / getMayaVersion # is avoided because getMayaVersion always calls getMayaLocation with # version == None actual_long_version = versions.installName() actual_short_version = versions.shortName() if version != actual_long_version: short_version = versions.parseVersionStr(version, extension=False) if version == short_version: try_version = actual_long_version.replace(actual_short_version, short_version) else: try_version = version try_loc = loc.replace(actual_long_version, try_version) if os.path.exists(try_loc): loc = try_loc else: _logger.warn("No Maya found for version %s" % version) loc = None return loc