Save repo.json after we've downloaded it
This commit is contained in:
@@ -22,20 +22,43 @@ class BadAddon(Exception):
|
||||
pass
|
||||
|
||||
def fetch(url, pipe):
|
||||
# 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.
|
||||
pipe[0].close()
|
||||
|
||||
local_repo_path = pathlib.Path(__file__).parent / 'packages'
|
||||
local_repo_path.mkdir(exist_ok=True)
|
||||
|
||||
try:
|
||||
# TODO: do conditional request
|
||||
re = requests.get(url)
|
||||
# print(re.json())
|
||||
pipe[1].send(re.headers)
|
||||
|
||||
pipe[1].send(re.status_code)
|
||||
|
||||
repo = re.json()
|
||||
repo['etag'] = re.headers.get('etag')
|
||||
repo['last-modified'] = re.headers.get('last-modified')
|
||||
|
||||
# just stick it here for now..
|
||||
dump_repo(local_repo_path, repo)
|
||||
|
||||
finally:
|
||||
pipe[1].close()
|
||||
|
||||
|
||||
|
||||
# class Package():
|
||||
# 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 parse_blinfo(source: str) -> dict:
|
||||
"""Parse a python file and return its bl_info dict, if there is one (else return None)"""
|
||||
@@ -117,9 +140,11 @@ def make_repo(repopath: pathlib.Path):
|
||||
|
||||
repo_data['packages'] = package_data
|
||||
|
||||
with (repopath / 'repo.json').open('w', encoding='utf-8') as repo_file:
|
||||
json.dump(repo_data, repo_file, indent=4, sort_keys=True)
|
||||
dump_repo(repopath, repo_data)
|
||||
|
||||
def dump_repo(repo_path: pathlib.Path, repo_data: dict):
|
||||
with (repo_path / 'repo.json').open('w', encoding='utf-8') as repo_file:
|
||||
json.dump(repo_data, repo_file, indent=4, sort_keys=True)
|
||||
|
||||
|
||||
def main():
|
||||
|
Reference in New Issue
Block a user