Skip to content
Snippets Groups Projects
Commit 90fbd177 authored by Pullusb's avatar Pullusb
Browse files

GPencil Tools: update brush pack url

Changed brush pack donwload to a blender official url. Comply with add-on key requirements (T95442)
Also disable registers in background mode to avoid keymap error.
parent b0502cd8
Branches
Tags
No related merge requests found
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
bl_info = { bl_info = {
"name": "Grease Pencil Tools", "name": "Grease Pencil Tools",
"description": "Extra tools for Grease Pencil", "description": "Extra tools for Grease Pencil",
"author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola", "author": "Samuel Bernou, Antonio Vazquez, Daniel Martinez Lara, Matias Mendiola",
"version": (1, 5, 4), "version": (1, 5, 5),
"blender": (2, 91, 0), "blender": (2, 91, 0),
"location": "Sidebar > Grease Pencil > Grease Pencil Tools", "location": "Sidebar > Grease Pencil > Grease Pencil Tools",
"warning": "", "warning": "",
...@@ -26,6 +25,8 @@ from . import (prefs, ...@@ -26,6 +25,8 @@ from . import (prefs,
) )
def register(): def register():
if bpy.app.background:
return
prefs.register() prefs.register()
timeline_scrub.register() timeline_scrub.register()
box_deform.register() box_deform.register()
...@@ -38,6 +39,8 @@ def register(): ...@@ -38,6 +39,8 @@ def register():
prefs.update_panel(prefs.get_addon_prefs(), bpy.context) prefs.update_panel(prefs.get_addon_prefs(), bpy.context)
def unregister(): def unregister():
if bpy.app.background:
return
ui_panels.unregister() ui_panels.unregister()
import_brush_pack.unregister() import_brush_pack.unregister()
rotate_canvas.unregister() rotate_canvas.unregister()
......
# SPDX-License-Identifier: GPL-2.0-or-later # SPDX-License-Identifier: GPL-2.0-or-later
import bpy import bpy
import re
import ssl import ssl
import urllib.request import urllib.request
import urllib.parse import urllib.parse
...@@ -26,23 +25,6 @@ def simple_dl_url(url, dest, fallback_url=None): ...@@ -26,23 +25,6 @@ def simple_dl_url(url, dest, fallback_url=None):
print('\nDownload page for manual install:', fallback_url) print('\nDownload page for manual install:', fallback_url)
return e return e
def download_url(url, dest):
'''download passed url to dest file (include filename)'''
import shutil
import time
ssl._create_default_https_context = ssl._create_unverified_context
start_time = time.time()
try:
with urllib.request.urlopen(url) as response, open(dest, 'wb') as out_file:
shutil.copyfileobj(response, out_file)
except Exception as e:
print('Error trying to download\n', e)
return e
print(f"Download time {time.time() - start_time:.2f}s",)
def get_brushes(blend_fp): def get_brushes(blend_fp):
cur_brushes = [b.name for b in bpy.data.brushes] cur_brushes = [b.name for b in bpy.data.brushes]
with bpy.data.libraries.load(str(blend_fp), link=False) as (data_from, data_to): with bpy.data.libraries.load(str(blend_fp), link=False) as (data_from, data_to):
...@@ -92,13 +74,9 @@ class GP_OT_install_brush_pack(bpy.types.Operator): ...@@ -92,13 +74,9 @@ class GP_OT_install_brush_pack(bpy.types.Operator):
self._append_brushes(Path(self.temp) / blendname) self._append_brushes(Path(self.temp) / blendname)
def execute(self, context): def execute(self, context):
import tempfile import tempfile
import json
import hashlib
import os import os
## get temp dir
temp = tempfile.gettempdir() temp = tempfile.gettempdir()
if not temp: if not temp:
self.report({'ERROR'}, 'no os temporary directory found to download brush pack (using python tempfile.gettempdir())') self.report({'ERROR'}, 'no os temporary directory found to download brush pack (using python tempfile.gettempdir())')
...@@ -106,71 +84,40 @@ class GP_OT_install_brush_pack(bpy.types.Operator): ...@@ -106,71 +84,40 @@ class GP_OT_install_brush_pack(bpy.types.Operator):
self.temp = Path(temp) self.temp = Path(temp)
## download link from gitlab dl_url = 'http://download.blender.org/demo/bundles/bundles-3.0/grease-pencil-brush-pack.zip'
# brush pack project https://gitlab.com/pepe-school-land/gp-brush-pack
repo_url = r'https://gitlab.com/api/v4/projects/21994857'
tree_url = f'{repo_url}/repository/tree'
## need to create an SSl context or linux fail and raise unverified ssl ## need to create an SSl context or linux fail and raise unverified ssl
ssl._create_default_https_context = ssl._create_unverified_context ssl._create_default_https_context = ssl._create_unverified_context
file_size = None
try: try:
with urllib.request.urlopen(tree_url) as response: with urllib.request.urlopen(dl_url) as response:
html = response.read() file_size = int(response.getheader('Content-Length'))
except: except:
## try loading from tempdir ## try loading from tempdir
packs = [f for f in os.listdir(self.temp) if 'GP_brush_pack' in f and f.endswith('.blend')] packs = [f for f in os.listdir(self.temp) if 'gp_brush_pack' in f.lower() and f.endswith('.blend')]
if packs: if packs:
packs.sort() packs.sort()
self._append_brushes(Path(self.temp) / packs[-1]) self._append_brushes(Path(self.temp) / packs[-1])
self.report({'WARNING'}, 'Brushes loaded from temp directory (No download)') self.report({'WARNING'}, 'Brushes loaded from temp directory (No download)')
# print('Could not reach web url : Brushes were loaded from temp directory file (No download)')
return {"FINISHED"} return {"FINISHED"}
self.report({'ERROR'}, f'Check your internet connexion, Impossible to connect to url: {tree_url}') self.report({'ERROR'}, f'Check your internet connexion, Impossible to connect to url: {dl_url}')
return {"CANCELLED"} return {"CANCELLED"}
if not html: if file_size is None:
self.report({'ERROR'}, f'No response read from: {tree_url}') self.report({'ERROR'}, f'No response read from: {dl_url}')
return {"CANCELLED"} return {"CANCELLED"}
tree_dic = json.loads(html) self.brushzip = self.temp / Path(dl_url).name
zips = [fi for fi in tree_dic if fi['type'] == 'blob' and fi['name'].endswith('.zip')]
if not zips:
print(f'no zip file found in {tree_url}')
return {"CANCELLED"}
## sort by name to get last
zips.sort(key=lambda x: x['name'])
last_zip = zips[-1]
zipname = last_zip['name']
id_num = last_zip['id']
## url by filename
# filepath_encode = urllib.parse.quote(zipname, safe='')# need safe to convert possible '/'
# dl_url = f'{repo_url}/repository/files/{filepath_encode}/raw?ref=master'
## url by blobs
dl_url = f"{repo_url}/repository/blobs/{id_num}/raw"
self.brushzip = self.temp / zipname
### Load existing files instead of redownloading if exists and up to date (same hash) ### Load existing files instead of redownloading if exists and up to date (same hash)
if self.brushzip.exists(): if self.brushzip.exists():
### Test the hash against online git hash (check for update)
BLOCK_SIZE = 524288# 512 Kb buf size ### compare using file size with size from url header
file_hash = hashlib.sha1() disk_size = self.brushzip.stat().st_size
file_hash.update(("blob %u\0" % os.path.getsize(self.brushzip)).encode('utf-8')) if disk_size == file_size:
with open(self.brushzip, 'rb') as f:
fb = f.read(BLOCK_SIZE)
while len(fb) > 0:
file_hash.update(fb)
fb = f.read(BLOCK_SIZE)
if file_hash.hexdigest() == id_num: # same git SHA1
## is up to date, install ## is up to date, install
print(f'{self.brushzip} is up do date, appending brushes') print(f'{self.brushzip} is up do date, appending brushes')
self._install_from_zip() self._install_from_zip()
...@@ -178,11 +125,9 @@ class GP_OT_install_brush_pack(bpy.types.Operator): ...@@ -178,11 +125,9 @@ class GP_OT_install_brush_pack(bpy.types.Operator):
## Download, unzip, use blend ## Download, unzip, use blend
print(f'Downloading brushpack in {self.brushzip}') print(f'Downloading brushpack in {self.brushzip}')
## https://cloud.blender.org/p/gallery/5f235cc297f8815e74ffb90b
fallback_url='https://gitlab.com/pepe-school-land/gp-brush-pack/-/blob/master/Official_GP_brush_pack_v01.zip' fallback_url='https://cloud.blender.org/p/gallery/5f235cc297f8815e74ffb90b'
err = simple_dl_url(dl_url, str(self.brushzip), fallback_url) err = simple_dl_url(dl_url, str(self.brushzip), fallback_url)
# err = download_url(dl_url, str(self.brushzip), fallback_url)
if err: if err:
self.report({'ERROR'}, 'Could not download brush pack. Check your internet connection. (see console for detail)') self.report({'ERROR'}, 'Could not download brush pack. Check your internet connection. (see console for detail)')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment