Committing first version of package manager add-on, index.json, and Python script to generate index.json file.
This commit is contained in:
1327
addons/index.json
Normal file
1327
addons/index.json
Normal file
File diff suppressed because it is too large
Load Diff
80
package-manager/__init__.py
Normal file
80
package-manager/__init__.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
# ====================== BEGIN GPL LICENSE BLOCK ======================
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 3
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ======================= END GPL LICENSE BLOCK ========================
|
||||||
|
|
||||||
|
bl_info = {
|
||||||
|
"name": "Package Manager",
|
||||||
|
"author": "Peter Cassetta",
|
||||||
|
"version": (1, 0),
|
||||||
|
"blender": (2, 77, 0),
|
||||||
|
"location": "User Preferences > Add-ons > System: Package Manager",
|
||||||
|
"description": "Download new add-ons and update current ones",
|
||||||
|
"support": 'TESTING',
|
||||||
|
"warning": "Early development",
|
||||||
|
"wiki_url": "",
|
||||||
|
"category": "System",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
from bpy.types import Operator, AddonPreferences
|
||||||
|
from bpy.props import StringProperty, BoolProperty, IntProperty, CollectionProperty
|
||||||
|
|
||||||
|
from . import networking
|
||||||
|
|
||||||
|
class PackageManagerAddon(bpy.types.PropertyGroup):
|
||||||
|
source = StringProperty()
|
||||||
|
name = StringProperty()
|
||||||
|
description = StringProperty()
|
||||||
|
author = StringProperty()
|
||||||
|
wiki_url = StringProperty()
|
||||||
|
tracker_url = StringProperty()
|
||||||
|
location = StringProperty()
|
||||||
|
category = StringProperty()
|
||||||
|
version = StringProperty()
|
||||||
|
blender = StringProperty()
|
||||||
|
warning = StringProperty()
|
||||||
|
support = StringProperty()
|
||||||
|
filename = StringProperty()
|
||||||
|
|
||||||
|
class PackageManagerPreferences(AddonPreferences):
|
||||||
|
# this must match the addon name, use '__package__'
|
||||||
|
# when defining this in a submodule of a python package.
|
||||||
|
bl_idname = __name__
|
||||||
|
|
||||||
|
pm_addons = CollectionProperty(type=PackageManagerAddon)
|
||||||
|
|
||||||
|
pm_addons_index = IntProperty()
|
||||||
|
|
||||||
|
def draw(self, context):
|
||||||
|
layout = self.layout
|
||||||
|
layout.operator("wm.update_index", text="Update List", icon='FILE_REFRESH')
|
||||||
|
rows = 1 if len(self.pm_addons) == 0 else 6
|
||||||
|
layout.template_list("UI_UL_list", "addons_list", self, "pm_addons",
|
||||||
|
self, "pm_addons_index", rows=rows)
|
||||||
|
|
||||||
|
def register():
|
||||||
|
networking.register()
|
||||||
|
bpy.utils.register_class(PackageManagerAddon)
|
||||||
|
bpy.utils.register_class(PackageManagerPreferences)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
networking.unregister()
|
||||||
|
bpy.utils.unregister_class(PackageManagerAddon)
|
||||||
|
bpy.utils.unregister_class(PackageManagerPreferences)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
register()
|
76
package-manager/networking.py
Normal file
76
package-manager/networking.py
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
# ====================== BEGIN GPL LICENSE BLOCK ======================
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or
|
||||||
|
# modify it under the terms of the GNU General Public License
|
||||||
|
# as published by the Free Software Foundation; either version 3
|
||||||
|
# of the License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ======================= END GPL LICENSE BLOCK ========================
|
||||||
|
|
||||||
|
import bpy
|
||||||
|
import json
|
||||||
|
import urllib.request
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateIndex(bpy.types.Operator):
|
||||||
|
"""Update the list of add-ons available for download"""
|
||||||
|
bl_idname = "wm.update_index"
|
||||||
|
bl_label = "Update list of add-ons"
|
||||||
|
|
||||||
|
def execute(self, context):
|
||||||
|
try:
|
||||||
|
req = urllib.request.urlopen("https://git.blender.org/gitweb/gitweb.cgi/"
|
||||||
|
"blender-package-manager-addon.git/blob_plain/HEAD:/addons/index.json")
|
||||||
|
index_file = req.read()
|
||||||
|
del req
|
||||||
|
except urllib.error.HTTPError as err:
|
||||||
|
self.report({'ERROR'}, "Error requesting update: "
|
||||||
|
+ str(err.code) + " " + err.reason)
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
try:
|
||||||
|
addon_list = json.loads(index_file)
|
||||||
|
except ValueError:
|
||||||
|
self.report({'ERROR'}, "Error: JSON file could not parse.")
|
||||||
|
return {'CANCELLED'}
|
||||||
|
|
||||||
|
for addon_list["addons"] as name, content:
|
||||||
|
addon = PackageManagerAddon()
|
||||||
|
addon.name = name
|
||||||
|
addon.source = content["source"]
|
||||||
|
addon.description = content["description"]
|
||||||
|
addon.author = content["author"]
|
||||||
|
addon.wiki_url = content["wiki_url"]
|
||||||
|
addon.tracker_url = content["tracker_url"]
|
||||||
|
addon.location = content["location"]
|
||||||
|
addon.category = content["category"]
|
||||||
|
for content["version"] as item:
|
||||||
|
# TODO: add multi-version functionality
|
||||||
|
for item as version, value:
|
||||||
|
addon.version = key
|
||||||
|
addon.blender = value["blender"]
|
||||||
|
addon.support = value["support"].upper()
|
||||||
|
try:
|
||||||
|
addon.warning = content["warning"]
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
addon.filename = value["filename"]
|
||||||
|
|
||||||
|
print(index_file)
|
||||||
|
|
||||||
|
return {'FINISHED'}
|
||||||
|
|
||||||
|
|
||||||
|
def register():
|
||||||
|
bpy.utils.register_class(UpdateIndex)
|
||||||
|
|
||||||
|
def unregister():
|
||||||
|
bpy.utils.unregister_class(UpdateIndex)
|
230
tools/generate-json.py
Normal file
230
tools/generate-json.py
Normal file
@@ -0,0 +1,230 @@
|
|||||||
|
# ====================== BEGIN GPL LICENSE BLOCK ======================
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
# ======================= END GPL LICENSE BLOCK ========================
|
||||||
|
#
|
||||||
|
# This script is a prototype which generates a JSON file
|
||||||
|
# for use in the package manager add-on.
|
||||||
|
|
||||||
|
import os
|
||||||
|
import shlex
|
||||||
|
|
||||||
|
addons_directory = 'C:\\Users\\Peter\\Documents\\blender-git\\blender\\release\\scripts\\addons\\'
|
||||||
|
contrib_directory = 'C:\\Users\\Peter\\Documents\\blender-git\\blender\\release\\scripts\\addons_contrib\\'
|
||||||
|
index_directory = 'C:\\Users\\Peter\\Documents\\blender-package-manager-addon\\addons\\'
|
||||||
|
|
||||||
|
# This script is functional for now, but rather "hacky" and much of it
|
||||||
|
# will be replaced by a modified version of the code which Blender uses
|
||||||
|
# to parse add-on's bl_info dictionary.
|
||||||
|
|
||||||
|
def list_addons (dir, addon=""):
|
||||||
|
json_text = ""
|
||||||
|
for item in os.scandir(dir):
|
||||||
|
if item.name[0] == '.':
|
||||||
|
continue
|
||||||
|
if '.' not in item.name:
|
||||||
|
if addon not in item.name and addon != "":
|
||||||
|
continue
|
||||||
|
if item.is_dir() and (item.name == addon or addon == ""):
|
||||||
|
filename = os.path.join(item.path, '__init__.py')
|
||||||
|
if item.is_file() and '.py' in item and (item.name[:-3] == addon or addon == ""):
|
||||||
|
filename = item.path
|
||||||
|
|
||||||
|
try:
|
||||||
|
file_lines = open(filename, mode='r').readlines()
|
||||||
|
except FileNotFoundError:
|
||||||
|
continue
|
||||||
|
new_lines = []
|
||||||
|
for line in file_lines:
|
||||||
|
if not line.startswith('#'):
|
||||||
|
#line = line[:line.find('#')] FIXME did not take into
|
||||||
|
# account '#' symbols inside quotes.
|
||||||
|
if line.__len__() > 0:
|
||||||
|
new_lines.append(line)
|
||||||
|
file_text = ''.join(new_lines)
|
||||||
|
|
||||||
|
bl_info_at = file_text.find('bl_info')
|
||||||
|
file_text = file_text[bl_info_at:]
|
||||||
|
open_bracket_at = file_text.find('{')
|
||||||
|
offset = 0
|
||||||
|
quote_type = ""
|
||||||
|
in_quote = False
|
||||||
|
current_quote = "key"
|
||||||
|
escape_next = False
|
||||||
|
|
||||||
|
bl_info = {}
|
||||||
|
key = ""
|
||||||
|
value = ""
|
||||||
|
tuple_item = 0
|
||||||
|
|
||||||
|
for char in file_text[open_bracket_at+1:]:
|
||||||
|
if char == '\\':
|
||||||
|
escape_next = not escape_next
|
||||||
|
|
||||||
|
was_in_quote = in_quote
|
||||||
|
if (not escape_next and (char == "'" or char == '"') and (not in_quote or (in_quote and char == quote_type))):
|
||||||
|
in_quote = not in_quote
|
||||||
|
quote_type = char
|
||||||
|
|
||||||
|
if in_quote and quote_type == ')' and (char == "'" or char == '"'):
|
||||||
|
quote_type = char
|
||||||
|
value = ""
|
||||||
|
|
||||||
|
if not in_quote and char == '(':
|
||||||
|
in_quote = True
|
||||||
|
value = ()
|
||||||
|
quote_type = ')'
|
||||||
|
elif in_quote and char == quote_type and quote_type == ')':
|
||||||
|
in_quote = False
|
||||||
|
elif in_quote and char != quote_type:
|
||||||
|
if quote_type != ')':
|
||||||
|
if current_quote == "key":
|
||||||
|
key += char
|
||||||
|
else:
|
||||||
|
value += char
|
||||||
|
else:
|
||||||
|
if char == ',':
|
||||||
|
value = value + (tuple_item, )
|
||||||
|
tuple_item = 0
|
||||||
|
elif char.isdigit():
|
||||||
|
tuple_item = (tuple_item * 10) + int(char)
|
||||||
|
|
||||||
|
if not in_quote:
|
||||||
|
if char == ',' or char == '}':
|
||||||
|
current_quote = "key"
|
||||||
|
if key != "":
|
||||||
|
if value != "" or value != None:
|
||||||
|
bl_info[key] = value
|
||||||
|
else:
|
||||||
|
bl_info[key] = ""
|
||||||
|
key = ""
|
||||||
|
value = ""
|
||||||
|
tuple_item = 0
|
||||||
|
elif was_in_quote:
|
||||||
|
if current_quote == "value" and quote_type == ')':
|
||||||
|
current_quote = "key"
|
||||||
|
value = value + (tuple_item, )
|
||||||
|
bl_info[key] = value
|
||||||
|
key = ""
|
||||||
|
value = ""
|
||||||
|
tuple_item = 0
|
||||||
|
else:
|
||||||
|
current_quote = "value"
|
||||||
|
|
||||||
|
offset += 1
|
||||||
|
|
||||||
|
if not in_quote and char == '}':
|
||||||
|
break
|
||||||
|
|
||||||
|
#print(file_text[:offset+open_bracket_at+1])
|
||||||
|
#for k, v in bl_info.items():
|
||||||
|
# print('"' + k + '": ' + repr(v))
|
||||||
|
if item.is_dir():
|
||||||
|
json_text += bl_info_to_json(bl_info, item.name)
|
||||||
|
else:
|
||||||
|
json_text += bl_info_to_json(bl_info, item.name, is_zip = False)
|
||||||
|
|
||||||
|
return json_text
|
||||||
|
|
||||||
|
def bl_info_to_json (bl_info, addon_id, source = 'internal', is_zip = True):
|
||||||
|
required_keys = ['name', 'blender']
|
||||||
|
recommended_keys = ['author', 'description', 'location', 'wiki_url', 'category']
|
||||||
|
|
||||||
|
for key in required_keys:
|
||||||
|
if key not in bl_info:
|
||||||
|
print("Error: missing key \"" + key + "\" in add-on " + addon_id
|
||||||
|
+ "'s bl_info, or bl_info dict may be malformed")
|
||||||
|
return ""
|
||||||
|
|
||||||
|
for key in recommended_keys:
|
||||||
|
if key not in bl_info:
|
||||||
|
print("Warning: missing key \"" + key + "\" in add-on " + addon_id
|
||||||
|
+ "'s bl_info, or bl_info dict may be malformed")
|
||||||
|
|
||||||
|
author = ""
|
||||||
|
if 'author' in bl_info:
|
||||||
|
author = bl_info['author']
|
||||||
|
|
||||||
|
description = ""
|
||||||
|
if 'description' in bl_info:
|
||||||
|
description = bl_info['description']
|
||||||
|
|
||||||
|
tracker_url = ""
|
||||||
|
if 'tracker_url' in bl_info:
|
||||||
|
tracker_url = bl_info['tracker_url']
|
||||||
|
|
||||||
|
wiki_url = ""
|
||||||
|
if 'wiki_url' in bl_info:
|
||||||
|
wiki_url = bl_info['wiki_url']
|
||||||
|
|
||||||
|
location = ""
|
||||||
|
if 'location' in bl_info:
|
||||||
|
location = bl_info['location']
|
||||||
|
|
||||||
|
category = ""
|
||||||
|
if 'category' in bl_info:
|
||||||
|
category = bl_info['category']
|
||||||
|
|
||||||
|
warning = ""
|
||||||
|
if 'warning' in bl_info:
|
||||||
|
warning = bl_info['warning']
|
||||||
|
|
||||||
|
version = "unversioned"
|
||||||
|
if 'version' in bl_info:
|
||||||
|
version = '.'.join(map(str, bl_info['version']))
|
||||||
|
|
||||||
|
support = 'community'.lower()
|
||||||
|
if 'support' in bl_info:
|
||||||
|
support = bl_info['support'].lower()
|
||||||
|
|
||||||
|
json_text = ""
|
||||||
|
|
||||||
|
json_text += "\t\t\"" + addon_id + "\": {\n"
|
||||||
|
json_text += "\t\t\t\"source\": \"" + source + "\"\n"
|
||||||
|
json_text += "\t\t\t\"name\": \"" + bl_info['name'] + "\"\n"
|
||||||
|
json_text += "\t\t\t\"description\": \"" + description + "\"\n"
|
||||||
|
json_text += "\t\t\t\"author\": \"" + author + "\"\n"
|
||||||
|
json_text += "\t\t\t\"wiki_url\": \"" + wiki_url + "\"\n"
|
||||||
|
json_text += "\t\t\t\"tracker_url\": \"" + tracker_url + "\"\n"
|
||||||
|
json_text += "\t\t\t\"location\": \"" + location + "\"\n"
|
||||||
|
json_text += "\t\t\t\"category\": \"" + category + "\"\n"
|
||||||
|
json_text += "\t\t\t\"version\": {\n"
|
||||||
|
json_text += "\t\t\t\t\"" + version + "\": {\n"
|
||||||
|
json_text += "\t\t\t\t\t\"blender\": \"" + '.'.join(map(str, bl_info['blender'])) + "\"\n"
|
||||||
|
if warning != "":
|
||||||
|
json_text += "\t\t\t\t\t\"warning\": \"" + warning + "\"\n"
|
||||||
|
json_text += "\t\t\t\t\t\"support\": \"" + support + "\"\n"
|
||||||
|
if is_zip:
|
||||||
|
json_text += "\t\t\t\t\t\"filename\": \"" + version + ".zip\"\n"
|
||||||
|
else:
|
||||||
|
json_text += "\t\t\t\t\t\"filename\": \"" + version + ".py\"\n"
|
||||||
|
json_text += "\t\t\t\t}\n"
|
||||||
|
json_text += "\t\t\t}\n"
|
||||||
|
json_text += "\t\t}\n"
|
||||||
|
|
||||||
|
return json_text
|
||||||
|
|
||||||
|
addon = ""
|
||||||
|
json_text = "{\n"
|
||||||
|
json_text += "\t\"schema-version\": \"1\"\n"
|
||||||
|
json_text += "\t\"internal-url\": \"https://git.blender.org/gitweb/gitweb.cgi/blender-package-manager-addon.git/blob_plain/HEAD:/addons/\"\n"
|
||||||
|
json_text += "\t\"addons\": {\n"
|
||||||
|
json_text += list_addons(addons_directory, addon)
|
||||||
|
json_text += list_addons(contrib_directory, addon)
|
||||||
|
json_text += "\t}\n"
|
||||||
|
json_text += "}\n"
|
||||||
|
|
||||||
|
index_file = open(os.path.join(index_directory, 'index.json'), mode='w')
|
||||||
|
index_file.write(json_text)
|
Reference in New Issue
Block a user