"""Scheduler class""" import os import subprocess import shutil from datetime import datetime from app import scheduler def typeset_add(): """Schedule job""" job = scheduler.get_job("set") if job is None: job = scheduler.add_job( id="set", func=typeset_run, trigger="date", ) def upgrade_add(): """Schedule job""" job = scheduler.get_job("set") if job is None: job = scheduler.add_job( id="set", func=upgrade_run, trigger="date", ) def typeset_run(): """Run the job""" print("Running") working_dir = os.getcwd() if os.path.basename(working_dir) != 'rr_tutorial': os.chdir('rr_tutorial') subprocess.check_output(['git', 'pull']) book_toc_size = os.path.getsize('master_book.toc') \ if os.path.isfile('master_book.toc') else 0 article_toc_size = os.path.getsize('master_article.toc') \ if os.path.isfile('master_article.toc') else 0 dist_toc_size = os.path.getsize('master_dist.toc') \ if os.path.isfile('master_dist.toc') else 0 subprocess.check_output(['xelatex', '-halt-on-error', 'master_book.tex']) subprocess.check_output(['xelatex', '-halt-on-error', 'master_article.tex']) subprocess.check_output(['./set.sh']) if book_toc_size != os.path.getsize('master_book.toc'): subprocess.check_output(['xelatex', '-halt-on-error', 'master_book.tex']) if article_toc_size != os.path.getsize('master_article.toc'): subprocess.check_output(['xelatex', '-halt-on-error', 'master_article.tex']) if dist_toc_size != os.path.getsize('master_dist.toc'): subprocess.check_output(['./set.sh']) shutil.copyfile('master_book.pdf', '../app/static/tutorial/book.pdf') shutil.copyfile('master_article.pdf', '../app/static/tutorial/article.pdf') shutil.copyfile('master_dist.pdf', '../app/static/tutorial/dist.pdf') subprocess.check_output(['./convert.sh']) shutil.copyfile('master_dist.png', '../app/static/tutorial/dist.png') shutil.copyfile('master_article.png', '../app/static/tutorial/article.png') def upgrade_run(): """Upgrade to new version""" subprocess.check_output(['git', 'pull']) subprocess.check_output(['pipenv', 'sync']) subprocess.check_output(['touch', 'flask.wsgi']) if __name__ == "__main__": typeset_run.__module__ = "scheduler" upgrade_run.__module__ = "scheduler"