Przeglądaj źródła

Add check if file exists

JoostSijm 6 lat temu
rodzic
commit
c37d9bf01a
1 zmienionych plików z 6 dodań i 4 usunięć
  1. 6 4
      app/flaskr.py

+ 6 - 4
app/flaskr.py

@@ -51,9 +51,12 @@ def typeset():
     if os.path.basename(working_dir) == 'rr':
         os.chdir('rr_tutorial')
 
-    book_toc_size = os.path.getsize('master_book.toc')
-    article_toc_size = os.path.getsize('master_article.toc')
-    dist_toc_size = os.path.getsize('master_dist.toc')
+    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'])
@@ -68,7 +71,6 @@ def typeset():
     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')