@@ -351,18 +351,19 @@ def addcourse(
351351
352352
353353@cli .command ()
354- @click .option (
355- "--course" , help = "The name of a course that should already exist in the DB"
356- )
357354@click .option ("--clone" , default = None , help = "clone the given repo before building" )
358355@click .option ("--ptx" , is_flag = True , help = "Build a PreTeXt book" )
359356@click .option (
360357 "--gen" , is_flag = True , help = "Build PreTeXt generated assets (a one time thing)"
361358)
362359@click .option ("--manifest" , default = "runestone-manifest.xml" , help = "Manifest file" )
360+ @click .argument ("course" , nargs = 1 )
363361@pass_config
364- def build (config , course , clone , ptx , gen , manifest ):
365- """Build the book for an existing course"""
362+ def build (config , clone , ptx , gen , manifest , course ):
363+ """
364+ rsmanage build [options] COURSE
365+ Build the book for an existing course
366+ """
366367 os .chdir (findProjectRoot ()) # change to a known location
367368 eng = create_engine (config .dburl )
368369 res = eng .execute (
@@ -393,102 +394,110 @@ def build(config, course, clone, ptx, gen, manifest):
393394 click .echo ("Switching to book dir {}" .format (course ))
394395 os .chdir (course )
395396 if ptx :
396- if not os .path .exists ("project.ptx" ):
397- click .echo ("PreTeXt books need a project.ptx file" )
398- sys .exit (1 )
399- else :
400- main_file = check_project_ptx ()
401- tree = ET .parse (main_file )
402- root = tree .getroot ()
403- ElementInclude .include (
404- root , base_url = main_file
405- ) # include all xi:include parts
406- if gen :
407- res = subprocess .call ("pretext generate web" )
408- if res != 0 :
409- click .echo ("Failed to build" )
410- # build the book
411- res = subprocess .call ("pretext build runestone" , shell = True )
412- if res != 0 :
413- click .echo ("Building failed" )
414- sys .exit (1 )
415- # process the manifest
416- click .echo ("processing manifest..." )
417- el = root .find ("./docinfo/document-id" )
418- if el is not None :
419- cname = el .text
420- if cname != course :
421- click .echo (
422- f"Error course: { course } does not match document-id: { cname } "
423- )
424- sys .exit (1 )
425- else :
426- click .echo ("Missing document-id please add to <docinfo>" )
427- sys .exit (1 )
428- mpath = Path (os .getcwd (), "published" , cname , manifest )
429- if os .path .exists (mpath ):
430- manifest_data_to_db (cname , mpath )
431- else :
432- raise IOError (
433- f"You must provide a valid path to a manifest file: { mpath } does not exist."
434- )
435-
436- # Fetch and copy the runestone components release as advertised by the manifest
437- # - Use wget to get all the js files and put them in _static
438- click .echo ("populating with the latest runestone files" )
439- populate_static (config , mpath , course )
440- # update the library page
441- click .echo ("updating library..." )
442- update_library (config , mpath , course )
397+ _build_ptx_book (config , gen , manifest , course )
443398
444399 else :
445- try :
446- if os .path .exists ("pavement.py" ):
447- sys .path .insert (0 , os .getcwd ())
448- from pavement import options , dest , project_name
449- else :
450- click .echo (
451- "I can't find a pavement.py file in {} you need that to build" .format (
452- os .getcwd ()
453- )
454- )
455- exit (1 )
456- except ImportError as e :
457- click .echo ("You do not appear to have a good pavement.py file." )
458- print (e )
459- exit (1 )
400+ _build_runestone_book (course )
401+
460402
461- if project_name != course :
403+ def _build_runestone_book (course ):
404+ try :
405+ if os .path .exists ("pavement.py" ):
406+ sys .path .insert (0 , os .getcwd ())
407+ from pavement import options , dest , project_name
408+ else :
462409 click .echo (
463- "Error: {} and {} do not match. Your course name needs to match the project_name in pavement.py " .format (
464- course , project_name
410+ "I can't find a pavement.py file in {} you need that to build " .format (
411+ os . getcwd ()
465412 )
466413 )
467414 exit (1 )
415+ except ImportError as e :
416+ click .echo ("You do not appear to have a good pavement.py file." )
417+ print (e )
418+ exit (1 )
468419
469- res = subprocess .call ("runestone build --all" , shell = True )
470- if res != 0 :
471- click .echo (
472- "building the book failed, check the log for errors and try again"
473- )
474- exit (1 )
475- click .echo ("Build succeedeed... Now deploying to published" )
476- if dest != "./published" :
477- click .echo (
478- "Incorrect deployment directory. dest should be ./published in pavement.py"
420+ if project_name != course :
421+ click .echo (
422+ "Error: {} and {} do not match. Your course name needs to match the project_name in pavement.py" .format (
423+ course , project_name
479424 )
480- exit (1 )
425+ )
426+ exit (1 )
481427
482- res = subprocess .call ("runestone deploy" , shell = True )
483- if res == 0 :
484- click .echo ("Success! Book deployed" )
428+ res = subprocess .call ("runestone build --all" , shell = True )
429+ if res != 0 :
430+ click .echo ("building the book failed, check the log for errors and try again" )
431+ exit (1 )
432+ click .echo ("Build succeedeed... Now deploying to published" )
433+ if dest != "./published" :
434+ click .echo (
435+ "Incorrect deployment directory. dest should be ./published in pavement.py"
436+ )
437+ exit (1 )
438+
439+ res = subprocess .call ("runestone deploy" , shell = True )
440+ if res == 0 :
441+ click .echo ("Success! Book deployed" )
442+ else :
443+ click .echo ("Deploy failed, check the log to see what went wrong." )
444+
445+
446+ def _build_ptx_book (config , gen , manifest , course ):
447+ if not os .path .exists ("project.ptx" ):
448+ click .echo ("PreTeXt books need a project.ptx file" )
449+ sys .exit (1 )
450+ else :
451+ main_file = check_project_ptx ()
452+ tree = ET .parse (main_file )
453+ root = tree .getroot ()
454+ ElementInclude .include (root , base_url = main_file ) # include all xi:include parts
455+ if gen :
456+ res = subprocess .call ("pretext generate web" )
457+ if res != 0 :
458+ click .echo ("Failed to build" )
459+ # build the book
460+ res = subprocess .call ("pretext build runestone" , shell = True )
461+ if res != 0 :
462+ click .echo ("Building failed" )
463+ sys .exit (1 )
464+ # process the manifest
465+ el = root .find ("./docinfo/document-id" )
466+ if el is not None :
467+ cname = el .text
468+ if cname != course :
469+ click .echo (
470+ f"Error course: { course } does not match document-id: { cname } "
471+ )
472+ sys .exit (1 )
485473 else :
486- click .echo ("Deploy failed, check the log to see what went wrong." )
474+ click .echo ("Missing document-id please add to <docinfo>" )
475+ sys .exit (1 )
476+
477+ mpath = Path (os .getcwd (), "published" , cname , manifest )
478+ process_manifest (cname , mpath )
479+ # Fetch and copy the runestone components release as advertised by the manifest
480+ # - Use wget to get all the js files and put them in _static
481+ click .echo ("populating with the latest runestone files" )
482+ populate_static (config , mpath , course )
483+ # update the library page
484+ click .echo ("updating library..." )
485+ update_library (config , mpath , course )
487486
488487
489488import pdb
490489
491490
491+ def process_manifest (cname , mpath ):
492+ click .echo ("processing manifest..." )
493+ if os .path .exists (mpath ):
494+ manifest_data_to_db (cname , mpath )
495+ else :
496+ raise IOError (
497+ f"You must provide a valid path to a manifest file: { mpath } does not exist."
498+ )
499+
500+
492501def check_project_ptx ():
493502 tree = ET .parse ("project.ptx" )
494503 targ = tree .find (".//target[@name='runestone']" )
@@ -529,7 +538,12 @@ def update_library(config: Config, mpath, course):
529538 description = extract_docinfo (docinfo , "blurb" )
530539 shelf = extract_docinfo (docinfo , "shelf" )
531540 click .echo (f"{ title } : { subtitle } " )
532- res = eng .execute (f"select * from library where basecourse = '{ course } '" )
541+ try :
542+ res = eng .execute (f"select * from library where basecourse = '{ course } '" )
543+ except :
544+ click .echo ("Missing library table? You may need to run an alembic migration." )
545+ sys .exit ()
546+
533547 if res .rowcount == 0 :
534548 eng .execute (
535549 f"""insert into library
0 commit comments