This repository has been archived on 2023-02-07. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-package-manager-addon/package-manager/networking.py

76 lines
2.8 KiB
Python
Raw Normal View History

# ====================== 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)