discovery.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # coding:utf-8
  2. #!/usr/bin/python
  3. #
  4. # Copyright (c) Contributors to the Open 3D Engine Project.
  5. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  6. #
  7. # SPDX-License-Identifier: Apache-2.0 OR MIT
  8. #
  9. #
  10. # -------------------------------------------------------------------------
  11. """! A module to discover installed versions of wing pro for selection
  12. :file: < DCCsi >/Tools/IDE/Wing/discovery.py
  13. :Status: Prototype, very bare bones
  14. :Version: 0.0.1
  15. Future: provide a variety of ways to discover wing, i.e. use winreg
  16. """
  17. # -------------------------------------------------------------------------
  18. # standard imports
  19. from pathlib import Path
  20. from typing import Union
  21. import logging as _logging
  22. # -------------------------------------------------------------------------
  23. # global scope
  24. from DccScriptingInterface.Tools.IDE.Wing import _PACKAGENAME
  25. _MODULENAME = f'{_PACKAGENAME}.discovery'
  26. _LOGGER = _logging.getLogger(_MODULENAME)
  27. _LOGGER.debug('Initializing: {0}.'.format({_MODULENAME}))
  28. # -------------------------------------------------------------------------
  29. # dccsi imports
  30. # the default and currently only supported discovery path
  31. from DccScriptingInterface.Tools.IDE.Wing.constants import PATH_WINGHOME
  32. # -------------------------------------------------------------------------
  33. # currently we only support the default win install path for Wing Pro 8
  34. def get_default_install(winghome: Union[str, Path] = PATH_WINGHOME) -> Path:
  35. """! validates then returns the default dccsi winghome
  36. :return: Path(winghome), or None"""
  37. winghome = Path(winghome).resolve()
  38. if winghome.exists():
  39. return winghome
  40. else:
  41. _LOGGER.error(f'WINGHOME not valid: {winghome.as_posix()}')
  42. return None
  43. # in the future, we might want to help the user find all installs
  44. # and select the install they would like to utilize. And this should
  45. # provide robust per-platform and os-style registry support.
  46. def find_all_installs() -> list:
  47. """! finds all platform installations of wing
  48. :return: list of wing install locations"""
  49. # ! this method is not fully implemented, future work.
  50. all_install_paths = list()
  51. all_install_paths.append(get_default_install())
  52. _LOGGER.info('Wing Installs found:')
  53. for index, install in enumerate(all_install_paths):
  54. _LOGGER.info(f'Install:{index}:: {install}')
  55. return all_install_paths
  56. # then during configuration (from cli or otherwise), present the installs
  57. # to the user and allow them to select which install to use
  58. # this would potentially end up in a couple of places:
  59. # <dccsi>\Tools\IDE\Wing\settings.local.json for a developer
  60. # <project>\registry\dccsi_config_wing.json for a project configuration
  61. # --- END -----------------------------------------------------------------
  62. ###########################################################################
  63. # Main Code Block, runs this script as main (testing)
  64. # -------------------------------------------------------------------------
  65. if __name__ == '__main__':
  66. """! Run this file as main, local testing"""
  67. winghome = get_default_install(winghome=PATH_WINGHOME)
  68. find_all_installs()
  69. if winghome.exists():
  70. _LOGGER.info(f'WINGHOME: {winghome}')
  71. else:
  72. _LOGGER.error(f'WINGHOME not valid: {winghome.as_posix()}')