Repository downloading
This commit is contained in:
@@ -232,6 +232,71 @@ class BPKG_OT_install(SubprocMixin, bpy.types.Operator):
|
||||
self.log.error('Process died without telling us! Exit code was 0 though')
|
||||
self.report({'WARNING'}, 'Error downloading package, but process finished OK. This is weird.')
|
||||
|
||||
class BPKG_OT_refresh(SubprocMixin, bpy.types.Operator):
|
||||
bl_idname = "bpkg.refresh"
|
||||
bl_label = "Refresh Packages"
|
||||
bl_description = 'Check for new and updated packages'
|
||||
bl_options = {'REGISTER'}
|
||||
|
||||
log = logging.getLogger(__name__ + ".BPKG_OT_refresh")
|
||||
|
||||
def invoke(self, context, event):
|
||||
return super().invoke(context, event)
|
||||
|
||||
def create_subprocess(self):
|
||||
"""Starts the download process.
|
||||
|
||||
Also registers the message handlers.
|
||||
|
||||
:rtype: multiprocessing.Process
|
||||
"""
|
||||
|
||||
import multiprocessing
|
||||
|
||||
self.msg_handlers = {
|
||||
subproc.Progress: self._subproc_progress,
|
||||
subproc.SubprocError: self._subproc_error,
|
||||
subproc.DownloadError: self._subproc_download_error,
|
||||
subproc.Success: self._subproc_success,
|
||||
subproc.Aborted: self._subproc_aborted,
|
||||
}
|
||||
|
||||
import pathlib
|
||||
|
||||
storage_path = pathlib.Path(bpy.utils.user_resource('CONFIG', 'addons', create=True))
|
||||
repository_url = bpy.context.user_preferences.addons[__package__].preferences.repository_url
|
||||
|
||||
proc = multiprocessing.Process(target=subproc.refresh,
|
||||
args=(self.pipe_subproc, storage_path, repository_url))
|
||||
return proc
|
||||
|
||||
def _subproc_progress(self, progress: subproc.Progress):
|
||||
self.log.info('Task progress at %i%%', progress.progress * 100)
|
||||
|
||||
def _subproc_error(self, error: subproc.SubprocError):
|
||||
self.report({'ERROR'}, 'Unable to refresh package list: %s' % error.message)
|
||||
self.quit()
|
||||
|
||||
def _subproc_download_error(self, error: subproc.DownloadError):
|
||||
self.report({'ERROR'}, 'Unable to download package list: %s' % error.description)
|
||||
self.quit()
|
||||
|
||||
def _subproc_success(self, success: subproc.Success):
|
||||
self.report({'INFO'}, 'Package list retrieved successfully')
|
||||
self.quit()
|
||||
|
||||
def _subproc_aborted(self, aborted: subproc.Aborted):
|
||||
self.report({'ERROR'}, 'Package list retrieval aborted per your request')
|
||||
self.quit()
|
||||
|
||||
def report_process_died(self):
|
||||
if self.process.exitcode:
|
||||
self.log.error('Process died without telling us! Exit code was %i', self.process.exitcode)
|
||||
self.report({'ERROR'}, 'Error refreshing package lists, exit code %i' % self.process.exitcode)
|
||||
else:
|
||||
self.log.error('Process died without telling us! Exit code was 0 though')
|
||||
self.report({'WARNING'}, 'Error refreshing package lists, but process finished OK. This is weird.')
|
||||
|
||||
|
||||
class BPKG_OT_hang(SubprocMixin, bpy.types.Operator):
|
||||
bl_idname = 'bpkg.hang'
|
||||
@@ -265,23 +330,29 @@ class PackageManagerPreferences(bpy.types.AddonPreferences):
|
||||
name='Package URL',
|
||||
description='Just a temporary place to store the URL of a package to download')
|
||||
|
||||
repository_url = bpy.props.StringProperty(
|
||||
name='Repository URL',
|
||||
description='Temporary repository URL')
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
temp_box = layout.box()
|
||||
temp_box.label(text="Temporary stuff while we're developing")
|
||||
temp_box.prop(self, 'package_url')
|
||||
temp_box.operator(BPKG_OT_install.bl_idname).package_url = self.package_url
|
||||
temp_box.prop(self, 'repository_url')
|
||||
temp_box.operator(BPKG_OT_refresh.bl_idname)
|
||||
temp_box.operator(BPKG_OT_hang.bl_idname)
|
||||
|
||||
|
||||
def register():
|
||||
bpy.utils.register_class(BPKG_OT_install)
|
||||
bpy.utils.register_class(BPKG_OT_refresh)
|
||||
bpy.utils.register_class(BPKG_OT_hang)
|
||||
bpy.utils.register_class(PackageManagerPreferences)
|
||||
|
||||
|
||||
def unregister():
|
||||
bpy.utils.unregister_class(BPKG_OT_install)
|
||||
bpy.utils.unregister_class(BPKG_OT_refresh)
|
||||
bpy.utils.unregister_class(BPKG_OT_hang)
|
||||
bpy.utils.unregister_class(PackageManagerPreferences)
|
||||
|
Reference in New Issue
Block a user