Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions pretext/pretext.py
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ async def extract_substitutions(dynamic_elements, baseurl, subst_file):
if "debug.rs.dev" not in stringparams:
# See if we can get Runestone Services from the Runestone CDN.
# "altrs" = alternate Runestone
altrs_js, altrs_css, altrs_cdn_url, altrs_version = _runestone_services(stringparams)
altrs_js, altrs_css, altrs_cdn_url, altrs_version, services_xml = _runestone_services(stringparams)
# Previous line will raise a fatal error if the Runestone servers
# do not cooperate, so we assume we have good information for
# locating the most recent version of Runestone Services
Expand Down Expand Up @@ -3551,7 +3551,7 @@ def _runestone_services(params):
altrs_cdn_url = services.xpath("/all/cdn-url")[0].text
# single Runestone Services version
altrs_version = services.xpath("/all/version")[0].text
return (altrs_js, altrs_css, altrs_cdn_url, altrs_version)
return (altrs_js, altrs_css, altrs_cdn_url, altrs_version, services_xml)

# todo - rewrite other code that does similar things to use this function?
def get_web_asset(url):
Expand Down Expand Up @@ -3614,7 +3614,7 @@ def html(
if "debug.rs.dev" not in stringparams:
# See if we can get Runestone Services from the Runestone CDN.
# "altrs" = alternate Runestone
altrs_js, altrs_css, altrs_cdn_url, altrs_version = _runestone_services(stringparams)
altrs_js, altrs_css, altrs_cdn_url, altrs_version, services_xml = _runestone_services(stringparams)
# Previous line will raise a fatal error if the Runestone servers
# do not cooperate, so we assume we have good information for
# locating the most recent version of Runestone Services
Expand All @@ -3629,27 +3629,35 @@ def html(
stringparams["rs-version"] = altrs_version

# get all the runestone files and place in tmp dir
# services_file is copy of services xml file
services_file_name = "dist-{}.tgz".format(altrs_version)
output_dir = os.path.join(tmp_dir, "_static")
services_full_path = os.path.join(output_dir, services_file_name)
final_output_path = os.path.join(dest_dir, "_static", services_file_name)
if file_format == "html" and os.path.exists(final_output_path):
# services_record is copy of services xml file
services_record_name = "_runestone-services-{}.xml".format(altrs_version)
services_record_output_path = os.path.join(dest_dir, "_static", services_record_name)
if file_format == "html" and os.path.exists(services_record_output_path):
msg = "Using existing Runestone Services located in {}. Delete Runestone files there to force a fresh download."
log.info(msg.format(os.path.join(dest_dir, '_static')))
os.path.exists(services_full_path)
else:
try:
msg = 'Downloading Runestone Services, version {}'
log.info(msg.format(altrs_version))
download_file(altrs_cdn_url + services_file_name, services_full_path)
log.info("Extracting Runestone Services from archive file")
import tarfile
file = tarfile.open(services_full_path)
file.extractall(output_dir)
file.close()
services_file = tarfile.open(services_full_path)
services_file.extractall(output_dir)
services_file.close()
# once unpacked, archive no longer necessary and we
# don't want to copy it out into produced "_static"
os.remove(services_full_path)
# write the services_record xml file to the output directory for version
# checking next time
services_record = open(services_record_output_path, 'w')
services_record.write(services_xml)
services_record.close()
except Exception as e:
log.warning(e)
log.warning("Failed to download all Runestone Services files")
Expand Down