Fix inport errors and maintain compatibility with python 3.5x)

This commit is contained in:
Ellwood Zwovic
2017-07-22 20:14:09 -07:00
parent 6752108930
commit 06a05c81b2
4 changed files with 38 additions and 27 deletions

View File

@@ -250,7 +250,7 @@ class PACKAGE_OT_install(SubprocMixin, bpy.types.Operator):
def _subproc_success(self, success: subproc.Success):
self.report({'INFO'}, 'Package installed successfully')
getattr(bpy.ops, __package__).refresh_packages()
bpy.ops.package.refresh_packages()
self.quit()
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):
self.report({'INFO'}, 'Package uninstalled successfully')
getattr(bpy.ops, __package__).refresh_packages()
bpy.ops.package.refresh_packages()
self.quit()
def report_process_died(self):
@@ -446,7 +446,7 @@ class PACKAGE_OT_refresh(bpy.types.Operator):
bl_description = "Check for new and updated packages"
def execute(self, context):
getattr(bpy.ops, __package__).refresh_repositories()
bpy.ops.package.refresh_repositories()
# getattr(bpy.ops, __package__).refresh_packages()
return {'FINISHED'}
@@ -791,7 +791,7 @@ class WM_OT_package_toggle_expand(bpy.types.Operator):
class PackageManagerPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
bl_idname = 'package'
package_url = bpy.props.StringProperty(
name='Package URL',

View File

@@ -1,11 +1,18 @@
from .exceptions import (
BpkgException,
InstallException,
DownloadException,
BadRepository,
)
import logging
log = logging.getLogger(__name__)
if 'bpy' in locals():
import importlib
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,
Repository,
)

View File

@@ -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:
"""Utility class for moving a file out of the way by appending a '~'"""
log = logging.getLogger('%s.inplace-backup' % __name__)
def __init__(self, path: pathlib.Path):
def __init__(self, path: Path):
self.path = path
self.backup()
@@ -13,10 +23,10 @@ class InplaceBackup:
if not self.path.exists():
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():
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))
@@ -32,17 +42,11 @@ class InplaceBackup:
if self.path.exists():
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))
def remove(self):
"""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()

View File

@@ -6,8 +6,8 @@ import logging
import pathlib
import shutil
import json
from .bpkg import utils
from .bpkg import Package, Repository
from .messages 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
# 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")
try:
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 = []
for conflict in conflicts:
log.debug("Creating backup of conflict %s", conflict)
backups.append(InplaceBackup(conflict))
backups.append(utils.InplaceBackup(conflict))
try:
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)
if dest_file.exists():
backup = InplaceBackup(dest_file)
backup = utils.InplaceBackup(dest_file)
try:
shutil.copyfile(str(pkgpath), str(dest_file))