|
1 | 1 | # ********* |
2 | 2 | # |docname| |
3 | 3 | # ********* |
| 4 | + |
| 5 | +from runestone import cmap |
4 | 6 | import sys |
5 | 7 | import os |
6 | 8 | import shutil |
|
9 | 11 | import click |
10 | 12 | import pathlib |
11 | 13 | import re |
| 14 | +import subprocess |
12 | 15 | from paver.easy import sh |
13 | 16 | from pkg_resources import resource_string, resource_filename, require |
14 | 17 | from .pretext.chapter_pop import manifest_data_to_db |
@@ -191,10 +194,14 @@ def build(all, wd): |
191 | 194 | paver_main(args=myargs) |
192 | 195 |
|
193 | 196 |
|
194 | | -@cli.command() |
| 197 | +@cli.command(short_help="preview the book in a minimal server (NO API support)") |
195 | 198 | @click.option("--port", default=8000, help="port for server to listen on") |
196 | 199 | @click.option("--listen", default="", help="address for server to listen on") |
197 | | -def serve(port, listen): |
| 200 | +def preview(port, listen): |
| 201 | + _preview(port, listen) |
| 202 | + |
| 203 | + |
| 204 | +def _preview(port, listen): |
198 | 205 | click.echo("Note: this is a minimal static server without templates or a database.") |
199 | 206 | click.echo("For many use cases this is fine.") |
200 | 207 | click.echo( |
@@ -246,6 +253,15 @@ def serve(port, listen): |
246 | 253 | httpd.serve_forever() |
247 | 254 |
|
248 | 255 |
|
| 256 | +# configure preview as an alias for serve |
| 257 | +@cli.command(short_help="Deprecated - use preview") |
| 258 | +@click.option("--port", default=8000, help="port for server to listen on") |
| 259 | +@click.option("--listen", default="", help="address for server to listen on") |
| 260 | +def serve(port, listen): |
| 261 | + click.echo("The serve command is deprecated, use runestone preview") |
| 262 | + _preview(port, listen) |
| 263 | + |
| 264 | + |
249 | 265 | @cli.command() |
250 | 266 | @click.option("--dest", default="", help="destination for deploy") |
251 | 267 | def deploy(dest): |
@@ -286,7 +302,57 @@ def deploy(dest): |
286 | 302 | sh("rsync -rav --delete {} {}".format(pavement.serving_dir, dest)) |
287 | 303 |
|
288 | 304 |
|
289 | | -from runestone import cmap |
| 305 | +@cli.command(short_help="Run sphinx build to convert RST to PreTeXt") |
| 306 | +@click.option("--course", default=None, help="Unique name of the book") |
| 307 | +@click.option("--sourcedir", default="_sources", help="Where is the source Luke?") |
| 308 | +@click.option("--outdir", default="build", help="Where is the source Luke?") |
| 309 | +def rs2ptx(course, sourcedir, outdir): |
| 310 | + """ |
| 311 | + Assemble and run a sphinx command similar to the following: |
| 312 | +
|
| 313 | + .. code-block:: bash |
| 314 | +
|
| 315 | + sphinx-build -b xml -d ./build/overview/doctrees -c . -Acourse_id=overview -Alogin_required=false -Aappname=runestone -Aloglevel=10 -Acourse_url=https://runestone.academy -Adynamic_pages=True -Ause_services=true -Abasecourse=overview -Apython3=true -Adownloads_enabled=true -Aallow_pairs=false -Aenable_chatcodes=false -Arunestone_version=5.7.1 -Abuild_info=unknown . ./build/xml |
| 316 | +
|
| 317 | + This command demonstrates a step toward independence from paver and the pavement.py file. |
| 318 | + This is kind of moot in a future where we rely on pretext to be the authoring language. But it **would** |
| 319 | + be easy to move the key variables and template_args from pavement.py to conf.py and update the build |
| 320 | + command to work like this... |
| 321 | + """ |
| 322 | + os.chdir(findProjectRoot()) |
| 323 | + sys.path.insert(0, os.getcwd()) |
| 324 | + try: |
| 325 | + import pavement |
| 326 | + except: |
| 327 | + click.echo("Could not read pavement.py file, aborting") |
| 328 | + sys.exit(1) |
| 329 | + |
| 330 | + if not course: |
| 331 | + if pavement.project_name: |
| 332 | + course = pavement.project_name |
| 333 | + else: |
| 334 | + course = click.prompt("Name of Course ", default="rsbook") |
| 335 | + |
| 336 | + if pavement.template_args: |
| 337 | + tdict = pavement.template_args |
| 338 | + else: |
| 339 | + tdict = {"course_id": course} |
| 340 | + |
| 341 | + cmd_start = ["sphinx-build", "-E", "-b", "xml", |
| 342 | + "-d", f"./build/{course}/doctrees", "-c", "."] |
| 343 | + tplate_val = [f"-A{key}={val}" for key, val in tdict.items()] |
| 344 | + cmd_end = [f"{sourcedir}", f"./{outdir}/xml"] |
| 345 | + cmd = " ".join(cmd_start + tplate_val + cmd_end) |
| 346 | + click.echo(cmd) |
| 347 | + try: |
| 348 | + cp = subprocess.run( |
| 349 | + cmd , shell=True, check=True |
| 350 | + ) |
| 351 | + except subprocess.CalledProcessError as e: |
| 352 | + click.echo(f"{e.stderr or ''}{e.stdout or ''}") |
| 353 | + raise |
| 354 | + |
| 355 | + # TODO: Run the xsltproc command after a successful runestone convert |
290 | 356 |
|
291 | 357 |
|
292 | 358 | @cli.command(short_help="type runestone doc directive to get help on directive") |
|
0 commit comments