Skip to content
This repository was archived by the owner on Jun 7, 2023. It is now read-only.

Commit f7107d3

Browse files
committed
Add: populate-static-files sub command
This is really for Rob and my development ease
1 parent 5501ef7 commit f7107d3

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

runestone/__main__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from .pretext.chapter_pop import manifest_data_to_db
1818
import codecs
1919
from runestone.server import get_dburl
20-
from runestone.server.utils import update_library
20+
from runestone.server.utils import update_library, populate_static
2121

2222
if len(sys.argv) == 2:
2323
if "--version" in sys.argv:
@@ -447,6 +447,17 @@ def process_manifest(course, manifest):
447447
raise IOError("You must provide a valid path to a manifest file")
448448

449449

450+
@cli.command(short_help="Fetch Javascript/CSS from CDN and copy to _static")
451+
@click.option("--course", help="Name of the course (base course)")
452+
def fetch_latest_static(course):
453+
config = type("config", (object,), {})()
454+
config.dburl = get_dburl()
455+
os.chdir(findProjectRoot())
456+
manifest = "runestone-manifest.xml"
457+
mpath = pathlib.Path(os.getcwd(), "published", course, manifest)
458+
populate_static(config, mpath, course)
459+
460+
450461
def main(args=None):
451462
sys.dont_write_bytecode = True
452463
if not args:
@@ -469,6 +480,8 @@ def findProjectRoot():
469480
while start != prevdir:
470481
if os.path.exists(os.path.join(start, "pavement.py")):
471482
return start
483+
if os.path.exists(os.path.join(start, "project.ptx")):
484+
return start
472485
prevdir = start
473486
start = os.path.dirname(start)
474487
raise IOError("You must be in a runestone project to run runestone")

runestone/server/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,13 @@ def populate_static(config, mpath: Path, course: str, click=click):
355355
current_version = tree.find("./version").text
356356
else:
357357
sdir.mkdir(mode=0o775, exist_ok=True) # NB mode must be in Octal!
358-
tree = ET.parse(mpath)
359-
el = tree.find("./runestone-services[@version]")
360-
version = el.attrib["version"].strip()
358+
if mpath.exists():
359+
tree = ET.parse(mpath)
360+
el = tree.find("./runestone-services[@version]")
361+
version = el.attrib["version"].strip()
362+
else:
363+
click.echo("Error: missing runestone-manifest.xml file")
364+
return False
361365
# Do not download if the versions already match.
362366
if version != current_version:
363367
click.echo(f"Fetching {version} files to {sdir} ")

0 commit comments

Comments
 (0)