def execute(self, context):
import html.parser
import urllib.request
remote_platforms = []
ps = context.scene.ge_publish_settings
# create lib folder if not already available
lib_path = bpy.path.abspath(ps.lib_path)
if not os.path.exists(lib_path):
os.makedirs(lib_path)
print("Retrieving list of platforms from blender.org...", end=" ", flush=True)
class AnchorParser(html.parser.HTMLParser):
def handle_starttag(self, tag, attrs):
if tag == 'a':
for key, value in attrs:
if key == 'href' and value.startswith('blender'):
remote_platforms.append(value)
url = 'http://download.blender.org/release/Blender' + bpy.app.version_string.split()[0]
parser = AnchorParser()
data = urllib.request.urlopen(url).read()
parser.feed(str(data))
print("done", flush=True)
print("Downloading files (this will take a while depending on your internet connection speed).", flush=True)
for i in remote_platforms:
src = '/'.join((url, i))
dst = os.path.join(lib_path, i)
dst_dir = '.'.join([i for i in dst.split('.') if i not in {'zip', 'tar', 'bz2'}])
if not os.path.exists(dst) and not os.path.exists(dst.split('.')[0]):
print("Downloading " + src + "...", end=" ", flush=True)
urllib.request.urlretrieve(src, dst)
print("done", flush=True)
else:
print("Reusing existing file: " + dst, flush=True)
print("Unpacking " + dst + "...", end=" ", flush=True)
if os.path.exists(dst_dir):
shutil.rmtree(dst_dir)
shutil.unpack_archive(dst, dst_dir)
print("done", flush=True)
print("Creating platform from libs...", flush=True)
bpy.ops.scene.publish_auto_platforms()
return {'FINISHED'}
评论列表
文章目录