Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SG-36346 Dynamic hard drive lookup in windows #204

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 32 additions & 14 deletions startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,11 @@ class AliasLauncher(SoftwareLauncher):
# Fallback code name to use when none is given
FALLBACK_CODE_NAME = "AutoStudio"

# This dictionary defines a list of executable template strings for each
# of the supported operating systems. The templates are used for both
# globbing and regex matches by replacing the named format placeholders
# with an appropriate glob or regex string. As Side FX adds modifies the
# install path on a given OS for a new release, a new template will need
# to be added here.
EXECUTABLE_TEMPLATES = {
"win32": [
# Example: C:\Program Files\Autodesk\AliasAutoStudio2019\bin\Alias.exe
r"C:\Program Files\Autodesk\Alias{code_name}{version}\bin\Alias.exe",
],
}
# Example: C:\Program Files\Autodesk\AliasAutoStudio2019\bin\Alias.exe
# <drive> will be replaced later with the available drive letters
BASE_TEMPLATE = (
r"<drive>:\Program Files\Autodesk\Alias{code_name}{version}\bin\Alias.exe"
)

@property
def minimum_supported_version(self):
Expand Down Expand Up @@ -200,8 +193,19 @@ def _icon_from_executable(self, code_name):
def _find_software(self):
"""Find executables in the default install locations."""

# This dictionary defines a list of executable template strings for each
# of the supported operating systems. The templates are used for both
# globbing and regex matches by replacing the named format placeholders
# with an appropriate glob or regex string.
templates = {
"win32": [
self.BASE_TEMPLATE.replace("<drive>", d)
for d in self._get_used_drive_letters()
],
}

# all the executable templates for the current OS
executable_templates = self.EXECUTABLE_TEMPLATES.get(sys.platform, [])
executable_templates = templates.get(sys.platform, [])

# all the discovered executables
sw_versions = []
Expand All @@ -214,7 +218,7 @@ def _find_software(self):
)

# Extract all products from that executable.
for (executable_path, key_dict) in executable_matches:
for executable_path, key_dict in executable_matches:
# extract the matched keys form the key_dict (default to None if
# not included)
version = key_dict.get("version")
Expand Down Expand Up @@ -283,6 +287,20 @@ def _get_release_version(self, exec_path, code_name):

return release_version

def _get_used_drive_letters(self):
try:
import win32api

drives = win32api.GetLogicalDriveStrings()
drives = drives.split("\000")[:-1]
return [d[0] for d in drives]
except:
# Fallback
self.logger.debug(
f"win32api not available. Falling back to default drive letter C:"
)
return ["C"]
julien-lang marked this conversation as resolved.
Show resolved Hide resolved

##########################################################################################
# private methods

Expand Down