-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy_notebooks_sdf_terminal.py
33 lines (31 loc) · 1.77 KB
/
copy_notebooks_sdf_terminal.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
import sys, os, time
from pathlib import Path
from subprocess import Popen
# This code strips the data from the notebooks, and copies them over for pushing to github.
dirs = [["/sdf/group/rubin/u/cslage/BOT_LSSTCam/notebooks", "/sdf/home/c/cslage/WORK/Notebook_Keeper/bot_notebooks/"], \
["/sdf/group/rubin/u/cslage/AuxTel/notebooks", "/sdf/home/c/cslage/WORK/Notebook_Keeper/auxtel_notebooks/"], \
["/sdf/group/rubin/u/cslage/ComCam/notebooks", "/sdf/home/c/cslage/WORK/Notebook_Keeper/comcam_notebooks/"], \
["/sdf/group/rubin/u/cslage/BOT_LSSTCam/notebooks/reca", "/sdf/home/c/cslage/WORK/Notebook_Keeper/reca_notebooks/"]]
for [get_dir, put_dir] in dirs:
files = os.listdir(get_dir)
filesToStore = []
for file in files:
if file.split(".")[-1] == "ipynb":
thisFile = f"{get_dir}/{file}"
storedFile = f"{put_dir}/{file}"
thisPath = Path(thisFile)
thisLastModified = thisPath.stat().st_mtime
try:
storedPath = Path(storedFile)
storedLastModified = storedPath.stat().st_mtime
except:
filesToStore.append(thisFile)
if thisLastModified > storedLastModified:
filesToStore.append(thisFile)
for thisFile in filesToStore:
print("Stripping and copying ", thisFile)
command = f"jupyter nbconvert --to notebook --ClearOutputPreprocessor.enabled=True \
--output-dir={put_dir} {thisFile}"
strip_and_copy = Popen(command, shell=True)
Popen.wait(strip_and_copy)
print("Done")