2017-06-22 01:43:08 -07:00
|
|
|
#!/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')
|
2017-06-22 17:41:41 -07:00
|
|
|
|
2017-06-22 01:43:08 -07:00
|
|
|
import requests
|
2017-06-22 17:41:41 -07:00
|
|
|
import json
|
|
|
|
import os
|
2017-06-23 20:05:10 -07:00
|
|
|
import pathlib
|
2017-06-22 17:41:41 -07:00
|
|
|
import ast
|
|
|
|
import argparse
|
|
|
|
import zipfile
|
|
|
|
import logging
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
2017-06-23 13:23:11 -07:00
|
|
|
REQUIRED_KEYS = set(['name', 'blender', 'version'])
|
2017-06-22 20:04:15 -07:00
|
|
|
SCHEMA_VERSION = 1
|
|
|
|
|
2017-06-23 19:10:26 -07:00
|
|
|
class BadAddon(Exception):
|
|
|
|
pass
|
2017-06-22 01:43:08 -07:00
|
|
|
|
2017-07-05 02:45:30 -07:00
|
|
|
|
|
|
|
# TODO add repolist class
|
|
|
|
|
|
|
|
def load_repo(url):
|
|
|
|
"""
|
|
|
|
Searches local repo.json for repository with a matching 'url' and returns it
|
|
|
|
"""
|
|
|
|
pass #TODO
|
|
|
|
|
|
|
|
def write_repo(repo):
|
|
|
|
"""
|
|
|
|
Writes repo to local repolist json
|
|
|
|
"""
|
|
|
|
pass #TODO
|
|
|
|
|
|
|
|
def fetch_repo(url: str) -> dict:
|
|
|
|
""" Requests repo.json from URL and embeds etag/last-modification headers"""
|
|
|
|
local_copy = load_repo(url)
|
|
|
|
headers = {}
|
|
|
|
if 'etag' in local_copy: headers['If-None-Match'] = local_copy['etag']
|
|
|
|
if 'last-modified' in local_copy: headers['If-Modified-Since'] = local_copy['last-modified']
|
|
|
|
|
|
|
|
resp = requests.get(url, headers=headers)
|
|
|
|
|
|
|
|
repo = json.loads(resp.json())
|
|
|
|
repo['etag'] = resp.headers.get('etag')
|
|
|
|
repo['last-modified'] = resp.headers.get('last-modified')
|
|
|
|
|
|
|
|
write_repo(repo)
|
|
|
|
|
|
|
|
def refresh(url):
|
2017-06-29 19:55:35 -07:00
|
|
|
# we have to explicitly close the end of the pipe we are NOT using,
|
|
|
|
# otherwise no exception will be generated when the other process closes its end.
|
2017-06-29 17:46:08 -07:00
|
|
|
pipe[0].close()
|
2017-06-29 19:55:35 -07:00
|
|
|
|
|
|
|
local_repo_path = pathlib.Path(__file__).parent / 'packages'
|
|
|
|
local_repo_path.mkdir(exist_ok=True)
|
|
|
|
|
2017-06-29 17:46:08 -07:00
|
|
|
try:
|
2017-07-05 02:45:30 -07:00
|
|
|
fetch_repojson(url)
|
2017-06-29 19:55:35 -07:00
|
|
|
pipe[1].send(re.status_code)
|
2017-06-29 17:46:08 -07:00
|
|
|
finally:
|
|
|
|
pipe[1].close()
|
|
|
|
|
|
|
|
|
2017-06-29 19:55:35 -07:00
|
|
|
# class Package:
|
2017-06-29 17:46:08 -07:00
|
|
|
# def __init__(self):
|
2017-06-29 19:55:35 -07:00
|
|
|
# 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__)
|
2017-06-23 19:10:26 -07:00
|
|
|
|
2017-06-22 17:41:41 -07:00
|
|
|
|
|
|
|
|
|
|
|
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')
|
2017-06-23 20:05:10 -07:00
|
|
|
make.set_defaults(func=lambda args: make_repo(pathlib.Path(args.path)))
|
2017-06-22 17:41:41 -07:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
args.func(args)
|
|
|
|
|
|
|
|
main()
|
|
|
|
|