Last active
August 18, 2021 12:22
-
-
Save zeffii/a325ab87931114311198c4571322b82b to your computer and use it in GitHub Desktop.
sverchok_bootstrap_v2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bpy | |
import urllib.request | |
from zipfile import ZipFile | |
import shutil | |
import os | |
from os.path import basename | |
from os.path import dirname | |
MAJOR, MINOR = bpy.app.version_file[0:2] | |
blender_version = f"{MAJOR}.{MINOR}" | |
url = 'https://github.com/nortikin/sverchok/archive/master.zip' | |
bpath = bpy.app.binary_path | |
bdir = dirname(bpath) | |
destination_dir = os.path.join(bdir, blender_version, 'scripts', 'addons', 'sverchok') | |
print('destination directory:', destination_dir) | |
if not os.path.exists(destination_dir): | |
os.makedirs(destination_dir) | |
zip_filename = os.path.basename(url) | |
sverchok_zip_path = os.path.join(destination_dir, zip_filename) | |
# download it | |
urllib.request.urlretrieve(url, sverchok_zip_path) | |
g = [] | |
archive = ZipFile(sverchok_zip_path) | |
for _file in archive.namelist(): | |
if _file.startswith('sverchok-master'): | |
n = archive.extract(_file, destination_dir) | |
g.append(n) | |
left = os.path.split(g[1]) | |
left = os.path.split(left[0]) | |
# move all from \sverchok\sverchok-master to \sverchok | |
for _f in g[1:]: | |
if os.path.isfile(_f): | |
m = _f.replace(g[0], left[0]) | |
dest = os.path.dirname(m) | |
if not os.path.exists(dest): | |
os.makedirs(dest) | |
shutil.move(_f, m) | |
shutil.rmtree(g[0]) | |
print('refeshing scripts paths..') | |
# bpy.utils.refresh_script_paths() | |
bpy.ops.preferences.addon_refresh() | |
print('addon enable -sverchok') | |
bpy.ops.preferences.addon_enable('INVOKE_DEFAULT', module="sverchok") | |
print("-- end bootstrapper script execution --") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment