job.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """Scheduler class"""
  2. import os
  3. import subprocess
  4. import shutil
  5. from datetime import datetime
  6. from app import scheduler
  7. def typeset_add():
  8. """Schedule job"""
  9. job = scheduler.get_job("set")
  10. if job is None:
  11. job = scheduler.add_job(
  12. id="set",
  13. func=typeset_run,
  14. trigger="date",
  15. )
  16. def upgrade_add():
  17. """Schedule job"""
  18. job = scheduler.get_job("set")
  19. if job is None:
  20. job = scheduler.add_job(
  21. id="set",
  22. func=upgrade_run,
  23. trigger="date",
  24. )
  25. def typeset_run():
  26. """Run the job"""
  27. print("Running")
  28. working_dir = os.getcwd()
  29. if os.path.basename(working_dir) != 'rr_tutorial':
  30. os.chdir('rr_tutorial')
  31. subprocess.check_output(['git', 'pull'])
  32. book_toc_size = os.path.getsize('master_book.toc') \
  33. if os.path.isfile('master_book.toc') else 0
  34. article_toc_size = os.path.getsize('master_article.toc') \
  35. if os.path.isfile('master_article.toc') else 0
  36. dist_toc_size = os.path.getsize('master_dist.toc') \
  37. if os.path.isfile('master_dist.toc') else 0
  38. subprocess.check_output(['xelatex', '-halt-on-error', 'master_book.tex'])
  39. subprocess.check_output(['xelatex', '-halt-on-error', 'master_article.tex'])
  40. subprocess.check_output(['./set.sh'])
  41. if book_toc_size != os.path.getsize('master_book.toc'):
  42. subprocess.check_output(['xelatex', '-halt-on-error', 'master_book.tex'])
  43. if article_toc_size != os.path.getsize('master_article.toc'):
  44. subprocess.check_output(['xelatex', '-halt-on-error', 'master_article.tex'])
  45. if dist_toc_size != os.path.getsize('master_dist.toc'):
  46. subprocess.check_output(['./set.sh'])
  47. shutil.copyfile('master_book.pdf', '../app/static/tutorial/book.pdf')
  48. shutil.copyfile('master_article.pdf', '../app/static/tutorial/article.pdf')
  49. shutil.copyfile('master_dist.pdf', '../app/static/tutorial/dist.pdf')
  50. subprocess.check_output(['./convert.sh'])
  51. shutil.copyfile('master_dist.png', '../app/static/tutorial/dist.png')
  52. shutil.copyfile('master_article.png', '../app/static/tutorial/article.png')
  53. def upgrade_run():
  54. """Upgrade to new version"""
  55. subprocess.check_output(['git', 'pull'])
  56. subprocess.check_output(['pipenv', 'sync'])
  57. subprocess.check_output(['touch', 'flask.wsgi'])
  58. if __name__ == "__main__":
  59. typeset_run.__module__ = "scheduler"
  60. upgrade_run.__module__ = "scheduler"