3535
3636# Build a Runestone Book
3737# ----------------------
38- def _build_runestone_book (course , click = click ):
38+ def _build_runestone_book (config , course , click = click ):
3939 """
4040 Parameters:
4141 course: the name of the course to build.
@@ -92,12 +92,12 @@ def _build_runestone_book(course, click=click):
9292 olfile .write (res .stderr )
9393 if resd .returncode == 0 :
9494 click .echo ("Success! Book deployed" )
95- return True
9695 else :
9796 click .echo ("Deploy failed, check the log to see what went wrong." )
9897 return False
9998
10099 update_library (config , "" , course , click , build_system = "Runestone" )
100+ return True
101101
102102
103103# Build a PreTeXt Book
@@ -255,9 +255,9 @@ def update_library(
255255 else :
256256 try :
257257 config_vars = {}
258- exec (open ("config .py" ).read (), config_vars )
258+ exec (open ("conf .py" ).read (), config_vars )
259259 except Exception as e :
260- print (f"Error adding book { book } to library list: { e } " )
260+ print (f"Error adding book { course } to library list: { e } " )
261261 return
262262 subtitle = ""
263263 if "navbar_title" in config_vars :
@@ -270,10 +270,10 @@ def update_library(
270270 title = "Runestone Book"
271271 # update course description if found in the book's conf.py
272272 if "course_description" in config_vars :
273- description = config_vars ["course_description) " ]
273+ description = config_vars ["course_description" ]
274274 # update course key_words if found in book's conf.py
275275 if "key_words" in config_vars :
276- key_words = config_vars ["key_words) " ]
276+ key_words = config_vars ["key_words" ]
277277
278278 if "shelf_section" in config_vars :
279279 shelf = config_vars ["shelf_section" ]
@@ -288,16 +288,29 @@ def update_library(
288288 click .echo ("Missing library table? You may need to run an alembic migration." )
289289 return False
290290
291- build_time = str (datetime .datetime .utcnow ())
291+ build_time = datetime .datetime .utcnow ()
292+ click .echo ("BUILD time is {build_time}" )
292293 if res .rowcount == 0 :
293294 eng .execute (
294- f"""insert into library
295- (title, subtitle, description, shelf_section, basecourse,
296- build_system, main_page, last_build )
297- values('{ title } ', '{ subtitle } ', '{ description } ', '{ shelf } ', '{ course } ',
295+ f"""insert into library
296+ (title, subtitle, description, shelf_section, basecourse,
297+ build_system, main_page, last_build )
298+ values('{ title } ', '{ subtitle } ', '{ description } ', '{ shelf } ', '{ course } ',
298299 '{ build_system } ', '{ main_page } ', '{ build_time } ') """
299300 )
300301 else :
302+ # If any values are missing or null do not override them here.
303+ #
304+ res = res .first ()
305+ if not title :
306+ title = res .title or ""
307+ if not subtitle :
308+ subtitle = res .subtitle or ""
309+ if not description :
310+ description = res .description or ""
311+ if not shelf :
312+ shelf = res .shelf_section or "Misc"
313+ click .echo ("Updating library" )
301314 eng .execute (
302315 f"""update library set
303316 title = '{ title } ',
@@ -345,9 +358,11 @@ def populate_static(config, mpath: Path, course: str, click=click):
345358 # Do not download if the versions already match.
346359 if version != current_version :
347360 click .echo (f"Fetching { version } files to { sdir } " )
361+ # remove the old files, but keep the lunr-pretext-search-index.js file if it exists
348362 for f in os .listdir (sdir ):
349363 try :
350- os .remove (sdir / f )
364+ if "lunr-pretext" not in f :
365+ os .remove (sdir / f )
351366 except :
352367 click .echo (f"ERROR - could not delete { f } " )
353368 # call wget non-verbose, recursive, no parents, no hostname, no directoy copy files to sdir
0 commit comments