jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.0KB

  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Michal Proszek, 2014 (poxip)
  4. """
  5. Detect the version of Blender, path
  6. and install the extension:
  7. def options(opt):
  8. opt.load('blender')
  9. def configure(cnf):
  10. cnf.load('blender')
  11. def build(bld):
  12. bld(name='io_mesh_raw',
  13. feature='blender',
  14. files=['file1.py', 'file2.py']
  15. )
  16. If name variable is empty, files are installed in scripts/addons, otherwise scripts/addons/name
  17. Use ./waf configure --system to set the installation directory to system path
  18. """
  19. import os
  20. import re
  21. from sys import platform as _platform
  22. from getpass import getuser
  23. from waflib import Utils
  24. from waflib.TaskGen import feature
  25. from waflib.Configure import conf
  26. def options(opt):
  27. opt.add_option(
  28. '-s', '--system',
  29. dest='directory_system',
  30. default=False,
  31. action='store_true',
  32. help='determines installation directory (default: user)'
  33. )
  34. @conf
  35. def find_blender(ctx):
  36. '''Return version number of blender, if not exist return None'''
  37. blender = ctx.find_program('blender')
  38. output = ctx.cmd_and_log(blender + ['--version'])
  39. m = re.search(r'Blender\s*((\d+(\.|))*)', output)
  40. if not m:
  41. ctx.fatal('Could not retrieve blender version')
  42. try:
  43. blender_version = m.group(1)
  44. except IndexError:
  45. ctx.fatal('Could not retrieve blender version')
  46. ctx.env['BLENDER_VERSION'] = blender_version
  47. return blender
  48. @conf
  49. def configure_paths(ctx):
  50. """Setup blender paths"""
  51. # Get the username
  52. user = getuser()
  53. _platform = Utils.unversioned_sys_platform()
  54. config_path = {'user': '', 'system': ''}
  55. if _platform.startswith('linux'):
  56. config_path['user'] = '/home/%s/.config/blender/' % user
  57. config_path['system'] = '/usr/share/blender/'
  58. elif _platform == 'darwin':
  59. # MAC OS X
  60. config_path['user'] = \
  61. '/Users/%s/Library/Application Support/Blender/' % user
  62. config_path['system'] = '/Library/Application Support/Blender/'
  63. elif Utils.is_win32:
  64. # Windows
  65. appdata_path = ctx.getenv('APPDATA').replace('\\', '/')
  66. homedrive = ctx.getenv('HOMEDRIVE').replace('\\', '/')
  67. config_path['user'] = '%s/Blender Foundation/Blender/' % appdata_path
  68. config_path['system'] = \
  69. '%sAll Users/AppData/Roaming/Blender Foundation/Blender/' % homedrive
  70. else:
  71. ctx.fatal(
  72. 'Unsupported platform. '
  73. 'Available platforms: Linux, OSX, MS-Windows.'
  74. )
  75. blender_version = ctx.env['BLENDER_VERSION']
  76. config_path['user'] += blender_version + '/'
  77. config_path['system'] += blender_version + '/'
  78. ctx.env['BLENDER_CONFIG_DIR'] = os.path.abspath(config_path['user'])
  79. if ctx.options.directory_system:
  80. ctx.env['BLENDER_CONFIG_DIR'] = config_path['system']
  81. ctx.env['BLENDER_ADDONS_DIR'] = os.path.join(
  82. ctx.env['BLENDER_CONFIG_DIR'], 'scripts/addons'
  83. )
  84. Utils.check_dir(ctx.env['BLENDER_ADDONS_DIR'])
  85. def configure(ctx):
  86. ctx.find_blender()
  87. ctx.configure_paths()
  88. @feature('blender_list')
  89. def blender(self):
  90. # Two ways to install a blender extension: as a module or just .py files
  91. dest_dir = os.path.join(self.env.BLENDER_ADDONS_DIR, self.get_name())
  92. Utils.check_dir(dest_dir)
  93. self.bld.install_files(
  94. dest_dir,
  95. getattr(self, 'files', '.')
  96. )