Fix inport errors and maintain compatibility with python 3.5x)
This commit is contained in:
@@ -250,7 +250,7 @@ class PACKAGE_OT_install(SubprocMixin, bpy.types.Operator):
|
|||||||
|
|
||||||
def _subproc_success(self, success: subproc.Success):
|
def _subproc_success(self, success: subproc.Success):
|
||||||
self.report({'INFO'}, 'Package installed successfully')
|
self.report({'INFO'}, 'Package installed successfully')
|
||||||
getattr(bpy.ops, __package__).refresh_packages()
|
bpy.ops.package.refresh_packages()
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def _subproc_aborted(self, aborted: subproc.Aborted):
|
def _subproc_aborted(self, aborted: subproc.Aborted):
|
||||||
@@ -311,7 +311,7 @@ class PACKAGE_OT_uninstall(SubprocMixin, bpy.types.Operator):
|
|||||||
|
|
||||||
def _subproc_success(self, success: subproc.Success):
|
def _subproc_success(self, success: subproc.Success):
|
||||||
self.report({'INFO'}, 'Package uninstalled successfully')
|
self.report({'INFO'}, 'Package uninstalled successfully')
|
||||||
getattr(bpy.ops, __package__).refresh_packages()
|
bpy.ops.package.refresh_packages()
|
||||||
self.quit()
|
self.quit()
|
||||||
|
|
||||||
def report_process_died(self):
|
def report_process_died(self):
|
||||||
@@ -446,7 +446,7 @@ class PACKAGE_OT_refresh(bpy.types.Operator):
|
|||||||
bl_description = "Check for new and updated packages"
|
bl_description = "Check for new and updated packages"
|
||||||
|
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
getattr(bpy.ops, __package__).refresh_repositories()
|
bpy.ops.package.refresh_repositories()
|
||||||
# getattr(bpy.ops, __package__).refresh_packages()
|
# getattr(bpy.ops, __package__).refresh_packages()
|
||||||
return {'FINISHED'}
|
return {'FINISHED'}
|
||||||
|
|
||||||
@@ -791,7 +791,7 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
|
|||||||
|
|
||||||
|
|
||||||
class PackageManagerPreferences(bpy.types.AddonPreferences):
|
class PackageManagerPreferences(bpy.types.AddonPreferences):
|
||||||
bl_idname = __package__
|
bl_idname = 'package'
|
||||||
|
|
||||||
package_url = bpy.props.StringProperty(
|
package_url = bpy.props.StringProperty(
|
||||||
name='Package URL',
|
name='Package URL',
|
||||||
|
@@ -1,11 +1,18 @@
|
|||||||
from .exceptions import (
|
import logging
|
||||||
BpkgException,
|
|
||||||
InstallException,
|
log = logging.getLogger(__name__)
|
||||||
DownloadException,
|
|
||||||
BadRepository,
|
if 'bpy' in locals():
|
||||||
)
|
import importlib
|
||||||
from .types import (
|
|
||||||
|
log.debug("Reloading %s", __name__)
|
||||||
|
exceptions = importlib.reload(exceptions)
|
||||||
|
Package = importlib.reload(types.Package)
|
||||||
|
Repository = importlib.reload(types.Repository)
|
||||||
|
|
||||||
|
else:
|
||||||
|
from . import exceptions
|
||||||
|
from .types import (
|
||||||
Package,
|
Package,
|
||||||
Repository,
|
Repository,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@@ -1,10 +1,20 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import logging
|
||||||
|
|
||||||
|
def rm(path: Path):
|
||||||
|
"""Delete whatever is specified by `path`"""
|
||||||
|
if path.is_dir():
|
||||||
|
shutil.rmtree(str(path))
|
||||||
|
else:
|
||||||
|
path.unlink()
|
||||||
|
|
||||||
class InplaceBackup:
|
class InplaceBackup:
|
||||||
"""Utility class for moving a file out of the way by appending a '~'"""
|
"""Utility class for moving a file out of the way by appending a '~'"""
|
||||||
|
|
||||||
log = logging.getLogger('%s.inplace-backup' % __name__)
|
log = logging.getLogger('%s.inplace-backup' % __name__)
|
||||||
|
|
||||||
def __init__(self, path: pathlib.Path):
|
def __init__(self, path: Path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.backup()
|
self.backup()
|
||||||
|
|
||||||
@@ -13,10 +23,10 @@ class InplaceBackup:
|
|||||||
if not self.path.exists():
|
if not self.path.exists():
|
||||||
raise FileNotFoundError("Can't backup path which doesn't exist")
|
raise FileNotFoundError("Can't backup path which doesn't exist")
|
||||||
|
|
||||||
self.backup_path = pathlib.Path(str(self.path) + '~')
|
self.backup_path = Path(str(self.path) + '~')
|
||||||
if self.backup_path.exists():
|
if self.backup_path.exists():
|
||||||
self.log.warning("Overwriting existing backup '{}'".format(self.backup_path))
|
self.log.warning("Overwriting existing backup '{}'".format(self.backup_path))
|
||||||
self._rm(self.backup_path)
|
rm(self.backup_path)
|
||||||
|
|
||||||
shutil.move(str(self.path), str(self.backup_path))
|
shutil.move(str(self.path), str(self.backup_path))
|
||||||
|
|
||||||
@@ -32,17 +42,11 @@ class InplaceBackup:
|
|||||||
|
|
||||||
if self.path.exists():
|
if self.path.exists():
|
||||||
self.log.warning("Overwriting '{0}' with backup file".format(self.path))
|
self.log.warning("Overwriting '{0}' with backup file".format(self.path))
|
||||||
self._rm(self.path)
|
rm(self.path)
|
||||||
|
|
||||||
shutil.move(str(self.backup_path), str(self.path))
|
shutil.move(str(self.backup_path), str(self.path))
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Remove 'path~'"""
|
"""Remove 'path~'"""
|
||||||
self._rm(self.backup_path)
|
rm(self.backup_path)
|
||||||
|
|
||||||
def _rm(self, path: pathlib.Path):
|
|
||||||
"""Just delete whatever is specified by `path`"""
|
|
||||||
if path.is_dir():
|
|
||||||
shutil.rmtree(str(path))
|
|
||||||
else:
|
|
||||||
path.unlink()
|
|
||||||
|
@@ -6,8 +6,8 @@ import logging
|
|||||||
import pathlib
|
import pathlib
|
||||||
import shutil
|
import shutil
|
||||||
import json
|
import json
|
||||||
|
from .bpkg import utils
|
||||||
from .bpkg import Package, Repository
|
from .bpkg import Package, Repository
|
||||||
|
|
||||||
from .messages import *
|
from .messages import *
|
||||||
from .bpkg.exceptions import *
|
from .bpkg.exceptions import *
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ def _install(pipe_to_blender, pkgpath: pathlib.Path, dest: pathlib.Path, searchp
|
|||||||
# The following is adapted from `addon_install` in bl_operators/wm.py
|
# The following is adapted from `addon_install` in bl_operators/wm.py
|
||||||
|
|
||||||
# check to see if the file is in compressed format (.zip)
|
# check to see if the file is in compressed format (.zip)
|
||||||
if zipfile.is_zipfile(pkgpath):
|
if zipfile.is_zipfile(str(pkgpath)):
|
||||||
log.debug("Package is zipfile")
|
log.debug("Package is zipfile")
|
||||||
try:
|
try:
|
||||||
file_to_extract = zipfile.ZipFile(str(pkgpath), 'r')
|
file_to_extract = zipfile.ZipFile(str(pkgpath), 'r')
|
||||||
@@ -135,7 +135,7 @@ def _install(pipe_to_blender, pkgpath: pathlib.Path, dest: pathlib.Path, searchp
|
|||||||
backups = []
|
backups = []
|
||||||
for conflict in conflicts:
|
for conflict in conflicts:
|
||||||
log.debug("Creating backup of conflict %s", conflict)
|
log.debug("Creating backup of conflict %s", conflict)
|
||||||
backups.append(InplaceBackup(conflict))
|
backups.append(utils.InplaceBackup(conflict))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
file_to_extract.extractall(str(dest))
|
file_to_extract.extractall(str(dest))
|
||||||
@@ -152,7 +152,7 @@ def _install(pipe_to_blender, pkgpath: pathlib.Path, dest: pathlib.Path, searchp
|
|||||||
dest_file = (dest / pkgpath.name)
|
dest_file = (dest / pkgpath.name)
|
||||||
|
|
||||||
if dest_file.exists():
|
if dest_file.exists():
|
||||||
backup = InplaceBackup(dest_file)
|
backup = utils.InplaceBackup(dest_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
shutil.copyfile(str(pkgpath), str(dest_file))
|
shutil.copyfile(str(pkgpath), str(dest_file))
|
||||||
|
Reference in New Issue
Block a user