-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmaster.py
More file actions
171 lines (130 loc) · 6.33 KB
/
master.py
File metadata and controls
171 lines (130 loc) · 6.33 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import subprocess, os, shutil, glob, ftp
# Clone the FEBio and FEBioStudio repositories
FBS_GIT = "https://github.com/febiosoftware/FEBioStudio.git"
FEBIO_GIT = "https://github.com/febiosoftware/FEBio.git"
try:
DEV_ONLY = bool(int(os.environ['DEV_ONLY']))
except:
DEV_ONLY = False
FBS_BRANCH = os.environ.get("FBS_BRANCH") or "master"
FEB_BRANCH = os.environ.get("FEB_BRANCH") or "master"
subprocess.call(["git", "clone", "--branch", FBS_BRANCH, "--depth", "1", FBS_GIT])
subprocess.call(["git", "clone", "--branch", FEB_BRANCH, "--depth", "1", FEBIO_GIT])
# Get the version numbers
FBS_VER = os.environ.get('FBS_VER')
if FBS_VER:
FBS_MAJOR = FBS_VER.split('.')[0].strip()
FBS_MINOR = FBS_VER.split('.')[1].strip()
else:
out = subprocess.check_output(["git", "-C", "FEBioStudio", "describe"]).decode("utf-8").replace("v", "").split('.')
FBS_MAJOR = out[0].strip()
FBS_MINOR = out[1].strip()
FEB_VER = os.environ.get('FEB_VER')
if FEB_VER:
FEBIO_MAJOR = FEB_VER.split('.')[0].strip()
FEBIO_MINOR = FEB_VER.split('.')[1].strip()
else:
out = subprocess.check_output(["git", "-C", "FEBio", "describe"]).decode("utf-8").replace("v", "").split('.')
FEBIO_MAJOR = out[0].strip()
FEBIO_MINOR = out[1].strip()
BASEDIR = os.getcwd() + "/"
if not DEV_ONLY:
# Set up the directory structure for lyx to html conversion
LYX_DIR = BASEDIR + "lyx/"
FBS_LYX_DIR = LYX_DIR + "FEBioStudio/"
FU_LYX_DIR = LYX_DIR + "FEBioUser/"
FT_LYX_DIR = LYX_DIR + "FEBioTheory/"
os.mkdir(LYX_DIR)
os.mkdir(FBS_LYX_DIR)
os.mkdir(FU_LYX_DIR)
os.mkdir(FT_LYX_DIR)
shutil.copy("FEBioStudio/Documentation/FEBioStudio_User_Manual.lyx", FBS_LYX_DIR)
shutil.copy("FEBioStudio/Documentation/FEBioStudio.bib", FBS_LYX_DIR)
shutil.copytree("FEBioStudio/Documentation/Figures", FBS_LYX_DIR + "Figures")
shutil.copy("FEBio/Documentation/FEBio_User_Manual.lyx", FU_LYX_DIR)
shutil.copy("FEBio/Documentation/FEBio3.bib", FU_LYX_DIR)
shutil.copytree("FEBio/Documentation/Figures", FU_LYX_DIR + "Figures")
shutil.copy("FEBio/Documentation/FEBio_Theory_Manual.lyx", FT_LYX_DIR)
shutil.copy("FEBio/Documentation/FEBio3.bib", FT_LYX_DIR)
shutil.copytree("FEBio/Documentation/Figures", FT_LYX_DIR + "Figures")
# If elyxer is called more than once in a script, it crashes.
# So we have to call it as a subprocess
os.chdir(FBS_LYX_DIR)
os.system("python3 " + BASEDIR + "buildManual.py")
os.chdir(FU_LYX_DIR)
os.system("python3 " + BASEDIR + "buildManual.py")
os.chdir(FT_LYX_DIR)
os.system("python3 " + BASEDIR + "buildManual.py")
# Set up the directory structure jekyll
JEKYLL_TEMPLATE_DIR = BASEDIR + "JekyllTemplate/"
JEKYLL_DIR = BASEDIR + "jekyll/"
FBS_JEKYLL_DIR = JEKYLL_DIR + "FEBioStudio-" + FBS_MAJOR + "-" + FBS_MINOR + "/"
FU_JEKYLL_DIR = JEKYLL_DIR + "FEBioUser-" + FEBIO_MAJOR + "-" + FEBIO_MINOR + "/"
FT_JEKYLL_DIR = JEKYLL_DIR + "FEBioTheory-" + FEBIO_MAJOR + "-" + FEBIO_MINOR + "/"
os.mkdir(JEKYLL_DIR)
def copyHTMLFiles(srcDir, destDir):
for file in glob.glob(srcDir + "*.html"):
shutil.copy(file, destDir)
shutil.copytree(JEKYLL_TEMPLATE_DIR, FBS_JEKYLL_DIR)
shutil.copy(FBS_LYX_DIR + "FEBioStudio.bib", FBS_JEKYLL_DIR)
shutil.copytree(FBS_LYX_DIR + "Figures", FBS_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "febioLogo.png", FBS_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "FBSIndex.md", FBS_JEKYLL_DIR + "index.md")
copyHTMLFiles(FBS_LYX_DIR, FBS_JEKYLL_DIR)
shutil.copytree(JEKYLL_TEMPLATE_DIR, FU_JEKYLL_DIR)
shutil.copy(FU_LYX_DIR + "FEBio3.bib", FU_JEKYLL_DIR)
shutil.copytree(FU_LYX_DIR + "Figures", FU_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "febioLogo.png", FU_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "FUIndex.md", FU_JEKYLL_DIR + "index.md")
copyHTMLFiles(FU_LYX_DIR, FU_JEKYLL_DIR)
shutil.copytree(JEKYLL_TEMPLATE_DIR, FT_JEKYLL_DIR)
shutil.copy(FT_LYX_DIR + "FEBio3.bib", FT_JEKYLL_DIR)
shutil.copytree(FT_LYX_DIR + "Figures", FT_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "febioLogo.png", FT_JEKYLL_DIR + "Figures")
shutil.copy(BASEDIR + "FTIndex.md", FT_JEKYLL_DIR + "index.md")
copyHTMLFiles(FT_LYX_DIR, FT_JEKYLL_DIR)
# edit the index.md files to include the version numbers
def editIndexFile(indexFile):
with open(indexFile, 'r') as file:
data = file.readlines()
for i in range(len(data)):
data[i] = data[i].replace("${fbs_major}", FBS_MAJOR)
data[i] = data[i].replace("${fbs_minor}", FBS_MINOR)
data[i] = data[i].replace("${feb_major}", FEBIO_MAJOR)
data[i] = data[i].replace("${feb_minor}", FEBIO_MINOR)
with open(indexFile, 'w') as file:
file.writelines(data)
editIndexFile(FBS_JEKYLL_DIR + "index.md")
editIndexFile(FU_JEKYLL_DIR + "index.md")
editIndexFile(FT_JEKYLL_DIR + "index.md")
# Run jekyll
def runJekyll(jekyllDir, baseURL):
os.chdir(jekyllDir)
os.system("bundle install")
os.system("bundle exec jekyll build -b" + baseURL)
runJekyll(FBS_JEKYLL_DIR, "/docs/FEBioStudio-" + FBS_MAJOR + "-" + FBS_MINOR)
runJekyll(FU_JEKYLL_DIR, "/docs/FEBioUser-" + FEBIO_MAJOR + "-" + FEBIO_MINOR)
runJekyll(FT_JEKYLL_DIR, "/docs/FEBioTheory-" + FEBIO_MAJOR + "-" + FEBIO_MINOR)
# Upload the files to the server
FBS_REMOTE_DIR = "docs/FEBioStudio-" + FBS_MAJOR + "-" + FBS_MINOR
FU_REMOTE_DIR = "docs/FEBioUser-" + FEBIO_MAJOR + "-" + FEBIO_MINOR
FT_REMOTE_DIR = "docs/FEBioTheory-" + FEBIO_MAJOR + "-" + FEBIO_MINOR
ftp.putRecursive(FBS_JEKYLL_DIR + "/_site", FBS_REMOTE_DIR)
ftp.putRecursive(FU_JEKYLL_DIR + "/_site", FU_REMOTE_DIR)
ftp.putRecursive(FT_JEKYLL_DIR + "/_site", FT_REMOTE_DIR)
# Run doxygen
DOX_DIR = BASEDIR + "FEBio/Documentation/Doxygen/"
os.chdir(DOX_DIR)
# Update the version number in the Doxyfile
data = []
with open("Doxyfile", "r") as file:
data = file.readlines()
for i in range(len(data)):
line = data[i].strip()
if line.startswith("PROJECT_NUMBER"):
data[i] = "PROJECT_NUMBER = " + FEBIO_MAJOR + "." + FEBIO_MINOR + "\n"
with open("Doxyfile", "w") as file:
file.writelines(data)
os.system("doxygen")
ftp.putRecursive(DOX_DIR + "doc/html", "doxygen/febio" + FEBIO_MAJOR + "." + FEBIO_MINOR)
os.chdir(BASEDIR)