Fix more pkgmgr methods
This commit is contained in:
parent
de0dcc79f4
commit
66c61e581d
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import hashlib
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
@ -30,21 +31,21 @@ class PackageManager:
|
|||||||
with open(CONF_FILE, 'w') as f:
|
with open(CONF_FILE, 'w') as f:
|
||||||
json.dump(self.conf, f, sort_keys=True, indent=4)
|
json.dump(self.conf, f, sort_keys=True, indent=4)
|
||||||
|
|
||||||
def get_online_packages(self):
|
def fetch_online_packages(self):
|
||||||
# Fetches and verifies online packages. Can raise InvalidSignature
|
# Fetches and verifies online packages. Can raise InvalidSignature
|
||||||
packages = requests.get('{}/packages'.format(self.repo_url)).content
|
packages = requests.get('{}/packages'.format(self.repo_url)).content
|
||||||
packages_sig = requests.get('{}/packages.sig'.format(self.repo_url)).content
|
packages_sig = requests.get('{}/packages.sig'.format(self.repo_url)).content
|
||||||
with open(PUB_FILE, 'rb') as f:
|
with open(PUB_FILE, 'rb') as f:
|
||||||
pub_key = load_pem_public_key(f.read(), default_backend())
|
pub_key = load_pem_public_key(f.read(), default_backend())
|
||||||
pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
pub_key.verify(packages_sig, packages, ec.ECDSA(hashes.SHA512()))
|
||||||
return json.loads(packages)
|
self.online_packages = json.loads(packages)
|
||||||
|
|
||||||
def install_package(self, name):
|
def install_package(self, name):
|
||||||
self.online_packages = get_online_packages()
|
self.fetch_online_packages()
|
||||||
for dep in self.get_deps(name):
|
for dep in self.get_deps(name):
|
||||||
if dep not in self.conf['packages']:
|
if dep not in self.conf['packages']:
|
||||||
self.download_package(name)
|
self.download_package(dep)
|
||||||
self.register_package(name)
|
self.register_package(dep)
|
||||||
self.setup_package()
|
self.setup_package()
|
||||||
|
|
||||||
def download_package(self, name):
|
def download_package(self, name):
|
||||||
@ -67,7 +68,7 @@ class PackageManager:
|
|||||||
self.conf['packages'][name] = {
|
self.conf['packages'][name] = {
|
||||||
'version': metadata['version'],
|
'version': metadata['version'],
|
||||||
}
|
}
|
||||||
if 'host' in self.online_packages[name]:
|
if 'host' in metadata:
|
||||||
self.conf['apps'][name] = {
|
self.conf['apps'][name] = {
|
||||||
'title': metadata['title'],
|
'title': metadata['title'],
|
||||||
'host': metadata['host'],
|
'host': metadata['host'],
|
||||||
|
Loading…
Reference in New Issue
Block a user