3 # Michal Proszek, 2014 (poxip)
6 Detect the version of Blender, path
7 and install the extension:
14 bld(name='io_mesh_raw',
16 files=['file1.py', 'file2.py']
18 If name variable is empty, files are installed in scripts/addons, otherwise scripts/addons/name
19 Use ./waf configure --system to set the installation directory to system path
23 from getpass import getuser
25 from waflib import Utils
26 from waflib.TaskGen import feature
27 from waflib.Configure import conf
32 dest='directory_system',
35 help='determines installation directory (default: user)'
39 def find_blender(ctx):
40 '''Return version number of blender, if not exist return None'''
41 blender = ctx.find_program('blender')
42 output = ctx.cmd_and_log(blender + ['--version'])
43 m = re.search(r'Blender\s*((\d+(\.|))*)', output)
45 ctx.fatal('Could not retrieve blender version')
48 blender_version = m.group(1)
50 ctx.fatal('Could not retrieve blender version')
52 ctx.env['BLENDER_VERSION'] = blender_version
56 def configure_paths(ctx):
57 """Setup blender paths"""
60 _platform = Utils.unversioned_sys_platform()
61 config_path = {'user': '', 'system': ''}
62 if _platform.startswith('linux'):
63 config_path['user'] = '/home/%s/.config/blender/' % user
64 config_path['system'] = '/usr/share/blender/'
65 elif _platform == 'darwin':
67 config_path['user'] = \
68 '/Users/%s/Library/Application Support/Blender/' % user
69 config_path['system'] = '/Library/Application Support/Blender/'
72 appdata_path = ctx.getenv('APPDATA').replace('\\', '/')
73 homedrive = ctx.getenv('HOMEDRIVE').replace('\\', '/')
75 config_path['user'] = '%s/Blender Foundation/Blender/' % appdata_path
76 config_path['system'] = \
77 '%sAll Users/AppData/Roaming/Blender Foundation/Blender/' % homedrive
80 'Unsupported platform. '
81 'Available platforms: Linux, OSX, MS-Windows.'
84 blender_version = ctx.env['BLENDER_VERSION']
86 config_path['user'] += blender_version + '/'
87 config_path['system'] += blender_version + '/'
89 ctx.env['BLENDER_CONFIG_DIR'] = os.path.abspath(config_path['user'])
90 if ctx.options.directory_system:
91 ctx.env['BLENDER_CONFIG_DIR'] = config_path['system']
93 ctx.env['BLENDER_ADDONS_DIR'] = os.path.join(
94 ctx.env['BLENDER_CONFIG_DIR'], 'scripts/addons'
96 Utils.check_dir(ctx.env['BLENDER_ADDONS_DIR'])
100 ctx.configure_paths()
102 @feature('blender_list')
104 # Two ways to install a blender extension: as a module or just .py files
105 dest_dir = os.path.join(self.env.BLENDER_ADDONS_DIR, self.get_name())
106 Utils.check_dir(dest_dir)
107 self.add_install_files(install_to=dest_dir, install_from=getattr(self, 'files', '.'))