-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_jb_build.py
67 lines (51 loc) · 1.59 KB
/
run_jb_build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/Users/yinfu/opt/miniconda3/bin python3
# -*- coding: utf-8 -*-
"""
Use jupyter-book generate html automatically.
1. Download Chrome-driver Plug-in for selenium package from https://chromedriver.chromium.org/
2. Make sure the project have 'dev' branch
3. Run this script in the root directory of book-project
@Author: Fu Yin || Fri Jul 22 21:59:08 2022
"""
import os
import time
import subprocess
from selenium import webdriver
#%% Functions
def jb_build(driver,book):
print("Start:", time.ctime())
os.system(f"jb build {book}")
driver.refresh()
def git_status():
cmd_git = subprocess.Popen(['git status -s'], shell = True, \
stdin = subprocess.PIPE, stdout = subprocess.PIPE, cwd = "./")
cmd_out_raw = cmd_git.stdout.read()
cmd_git.wait()
cmd_git.stdout.close()
cmd_out = cmd_out_raw.decode()
out = cmd_out.split("\n")
return out
def git_commit():
os.system(""" git add . """)
os.system(""" git commit -m "auto" """)
def main():
driver= webdriver.Chrome()
driver.get(url)
# os.system("git switch dev")
jb_build(driver, book)
while True:
time.sleep(sleep_time)
out = git_status()
if len(out) != 1:
print("Change number = ", len(out))
jb_build(driver, book)
git_commit()
else:
print("No change and continue...")
continue
#%% Main
url = "file:///Users/yinfu/src/Programming_Notebook/book/_build/html/intro.html"
book= "./book" # jupyter-book build ./book
sleep_time = 0.1 # unit/s
if __name__ == '__main__':
main()