Rename "blenderpack" module to "bpackage"
Also split code into files by class
This commit is contained in:
3
bpackage/__init__.py
Normal file
3
bpackage/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
import bpackage.exceptions
|
||||||
|
from .package import Package
|
||||||
|
from .repository import Repository
|
14
bpackage/exceptions.py
Normal file
14
bpackage/exceptions.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class BadAddon(Exception):
|
||||||
|
"""
|
||||||
|
Raised when something expected to be an addon turns out not to be one after all
|
||||||
|
"""
|
||||||
|
|
||||||
|
class RepositoryListError(ValueError):
|
||||||
|
"""
|
||||||
|
Raised when something is amiss with the repo.json file
|
||||||
|
"""
|
||||||
|
|
||||||
|
class RepositoryNotFoundError(RepositoryListError):
|
||||||
|
"""
|
||||||
|
Raised when looking for a repository which isn't there
|
||||||
|
"""
|
39
bpackage/package.py
Normal file
39
bpackage/package.py
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
# HACK: seems 'requests' module bundled with blender isn't bundled with 'idna' module. So force system python for now
|
||||||
|
# import sys
|
||||||
|
# sys.path.insert(0, '/usr/lib/python3.6/site-packages')
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
class Package:
|
||||||
|
"""
|
||||||
|
Stores package methods and metadata
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, package_dict:dict = None):
|
||||||
|
self.from_dict(package_dict)
|
||||||
|
|
||||||
|
def to_dict(self) -> dict:
|
||||||
|
"""
|
||||||
|
Return a dict representation of the package
|
||||||
|
"""
|
||||||
|
return {
|
||||||
|
'bl_info': self.bl_info,
|
||||||
|
'url': self.url,
|
||||||
|
}
|
||||||
|
|
||||||
|
def from_dict(self, package_dict: dict):
|
||||||
|
"""
|
||||||
|
Get attributes from a dict such as produced by `to_dict`
|
||||||
|
"""
|
||||||
|
if package_dict is None:
|
||||||
|
package_dict = {}
|
||||||
|
|
||||||
|
for attr in ('name', 'url', 'bl_info'):
|
||||||
|
setattr(self, attr, package_dict.get(attr))
|
||||||
|
|
||||||
|
|
66
blenderpack/blenderpack.py → bpackage/repository.py
Executable file → Normal file
66
blenderpack/blenderpack.py → bpackage/repository.py
Executable file → Normal file
@@ -1,38 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
# HACK: seems 'requests' module bundled with blender isn't bundled with 'idna' module. So force system python for now
|
# HACK: seems 'requests' module bundled with blender isn't bundled with 'idna' module. So force system python for now
|
||||||
import sys
|
# import sys
|
||||||
sys.path.insert(0, '/usr/lib/python3.6/site-packages')
|
# sys.path.insert(0, '/usr/lib/python3.6/site-packages')
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import pathlib
|
|
||||||
import ast
|
|
||||||
import argparse
|
|
||||||
import zipfile
|
|
||||||
import logging
|
import logging
|
||||||
from collections import MutableMapping
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
REQUIRED_KEYS = set(['name', 'blender', 'version'])
|
|
||||||
SCHEMA_VERSION = 1
|
|
||||||
|
|
||||||
class BadAddon(Exception):
|
|
||||||
"""
|
|
||||||
Raised when something expected to be an addon turns out not to be
|
|
||||||
"""
|
|
||||||
|
|
||||||
class RepositoryListError(ValueError):
|
|
||||||
"""
|
|
||||||
Raised when something is amiss with the repo.json file
|
|
||||||
"""
|
|
||||||
|
|
||||||
class RepositoryNotFoundError(RepositoryListError):
|
|
||||||
"""
|
|
||||||
Raised when looking for a repository which isn't there
|
|
||||||
"""
|
|
||||||
|
|
||||||
class Package:
|
class Package:
|
||||||
"""
|
"""
|
||||||
@@ -119,7 +97,7 @@ class Repository:
|
|||||||
|
|
||||||
setattr(self, attr, value)
|
setattr(self, attr, value)
|
||||||
|
|
||||||
def dump(self, path: pathlib.Path):
|
def dump(self, path: Path):
|
||||||
"""
|
"""
|
||||||
Dump repository as a repo.json file in 'path'
|
Dump repository as a repo.json file in 'path'
|
||||||
"""
|
"""
|
||||||
@@ -133,7 +111,7 @@ def refresh(url):
|
|||||||
# otherwise no exception will be generated when the other process closes its end.
|
# otherwise no exception will be generated when the other process closes its end.
|
||||||
pipe[0].close()
|
pipe[0].close()
|
||||||
|
|
||||||
local_repo_path = pathlib.Path(__file__).parent / 'packages'
|
local_repo_path = Path(__file__).parent / 'packages'
|
||||||
local_repo_path.mkdir(exist_ok=True)
|
local_repo_path.mkdir(exist_ok=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -143,37 +121,3 @@ def refresh(url):
|
|||||||
pipe[1].close()
|
pipe[1].close()
|
||||||
|
|
||||||
|
|
||||||
# class Package:
|
|
||||||
# def __init__(self):
|
|
||||||
# self.bl_info = None
|
|
||||||
# self.url = None
|
|
||||||
# self.type = None
|
|
||||||
#
|
|
||||||
# class Repository:
|
|
||||||
# def __init__(self, name):
|
|
||||||
# self.name = name
|
|
||||||
# self.packages = None
|
|
||||||
#
|
|
||||||
# def json(self):
|
|
||||||
# return json.dumps(self.__dict__)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
pass
|
|
||||||
# print(args)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = argparse.ArgumentParser(description='Search, install, and manage packages for Blender')
|
|
||||||
subparsers = parser.add_subparsers()
|
|
||||||
|
|
||||||
make = subparsers.add_parser('make')
|
|
||||||
make.add_argument('path')
|
|
||||||
make.set_defaults(func=lambda args: make_repo(pathlib.Path(args.path)))
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
args.func(args)
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|
@@ -4,7 +4,7 @@ import unittest
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
import json
|
import json
|
||||||
import blenderpack as BP
|
import bpackage as BP
|
||||||
|
|
||||||
logging.basicConfig(level=logging.DEBUG,
|
logging.basicConfig(level=logging.DEBUG,
|
||||||
format='%(levelname)8s: %(message)s')
|
format='%(levelname)8s: %(message)s')
|
||||||
|
Reference in New Issue
Block a user