First test for conditional requests
Involves lots of mocking. Part of the issue is that there is no way (?) to know where repo.json is stored when blender isn't running the show.
This commit is contained in:
@@ -21,7 +21,37 @@ SCHEMA_VERSION = 1
|
||||
class BadAddon(Exception):
|
||||
pass
|
||||
|
||||
def fetch(url, pipe):
|
||||
|
||||
# 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):
|
||||
# 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()
|
||||
@@ -30,18 +60,8 @@ def fetch(url, pipe):
|
||||
local_repo_path.mkdir(exist_ok=True)
|
||||
|
||||
try:
|
||||
# TODO: do conditional request
|
||||
re = requests.get(url)
|
||||
|
||||
fetch_repojson(url)
|
||||
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()
|
||||
|
||||
|
Reference in New Issue
Block a user