- Timestamp:
- Jun 13, 2017 11:48:11 AM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 9d566b2
- Parents:
- d9c1551
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
docs/sphinx-docs/build_sphinx.py
r01f1e17 r0e2d287 21 21 from os import listdir 22 22 23 platform = '.%s-%s'%(get_platform(), sys.version[:3])23 platform = '.%s-%s'%(get_platform(), sys.version[:3]) 24 24 25 25 CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) … … 46 46 SASMODELS_SOURCE_MODELS = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model") 47 47 SASMODELS_SOURCE_IMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "model", "img") 48 SASMODELS_SOURCE_AUTOIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "_build", "html", "_images")48 SASMODELS_SOURCE_AUTOIMG = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "..", "sasmodels", "doc", "_build", "html", "_images") 49 49 ## Don't do assemble-in-place 50 50 ## Assemble the docs in a temporary folder … … 73 73 def inplace_change(filename, old_string, new_string): 74 74 # Thanks to http://stackoverflow.com/questions/4128144/replace-string-within-file-contents 75 s=open(filename).read()76 77 78 s=s.replace(old_string, new_string)79 f=open(filename, 'w')80 81 82 83 84 75 s = open(filename).read() 76 if old_string in s: 77 print('Changing "{old_string}" to "{new_string}"'.format(**locals())) 78 s = s.replace(old_string, new_string) 79 f = open(filename, 'w') 80 f.write(s) 81 f.flush() 82 f.close() 83 else: 84 print('No occurences of "{old_string}" found.'.format(**locals())) 85 85 86 86 def _remove_dir(dir_path): … … 109 109 print("=== Copying Source toctrees ===") 110 110 if os.path.exists(SASVIEW_TOC_SOURCE): 111 print("Found docs folder at", SASVIEW_TOC_SOURCE)112 shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE)111 print("Found docs folder at", SASVIEW_TOC_SOURCE) 112 shutil.copytree(SASVIEW_TOC_SOURCE, SPHINX_SOURCE) 113 113 114 114 def retrieve_user_docs(): … … 147 147 print("=== Including Test Data Docs ===") 148 148 if os.path.exists(SASVIEW_TEST): 149 print("Found docs folder at", SASVIEW_TEST)150 shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST)149 print("Found docs folder at", SASVIEW_TEST) 150 shutil.copytree(SASVIEW_TEST, SPHINX_SOURCE_TEST) 151 151 152 152 print("=== And the Sasmodels Docs ===") 153 153 # Make sure we have the relevant images for the new sasmodels documentation 154 # First(!) we'll make a local reference copy for SasView (/new-models will be cleaned each build) 154 # First(!) we'll make a local reference copy for SasView 155 # (/new-models will be cleaned each build) 155 156 if os.path.exists(SASMODELS_SOURCE_IMG): 156 157 print("Found img folder SASMODELS_SOURCE_IMG at", SASMODELS_SOURCE_IMG) … … 163 164 print("Copying sasmodels model image files...") 164 165 for files in os.listdir(SASMODELS_SOURCE_IMG): 165 fromhere =os.path.join(SASMODELS_SOURCE_IMG,files)166 tohere =os.path.join(SASMODELS_DEST_IMG,files)167 shutil.copy(fromhere, tohere)168 else: 169 print("no source directory", SASMODELS_SOURCE_IMG,"was found")166 fromhere = os.path.join(SASMODELS_SOURCE_IMG, files) 167 tohere = os.path.join(SASMODELS_DEST_IMG, files) 168 shutil.copy(fromhere, tohere) 169 else: 170 print("no source directory", SASMODELS_SOURCE_IMG, "was found") 170 171 171 172 if os.path.exists(SASMODELS_SOURCE_AUTOIMG): … … 177 178 print("Copying sasmodels model auto-generated image files...") 178 179 for files in os.listdir(SASMODELS_SOURCE_AUTOIMG): 179 fromhere =os.path.join(SASMODELS_SOURCE_AUTOIMG,files)180 tohere =os.path.join(SASMODELS_DEST_IMG,files)181 shutil.copy(fromhere, tohere)182 else: 183 print("no source directory", SASMODELS_SOURCE_AUTOIMG ,"was found")180 fromhere = os.path.join(SASMODELS_SOURCE_AUTOIMG, files) 181 tohere = os.path.join(SASMODELS_DEST_IMG, files) 182 shutil.copy(fromhere, tohere) 183 else: 184 print("no source directory", SASMODELS_SOURCE_AUTOIMG, "was found") 184 185 185 186 # And the rst prolog with the unit substitutions … … 191 192 for files in os.listdir(SASMODELS_SOURCE_PROLOG): 192 193 if files.startswith("rst"): 193 fromhere =os.path.join(SASMODELS_SOURCE_PROLOG,files)194 tohere =os.path.join(SASMODELS_DEST_PROLOG,files)195 shutil.copy(fromhere, tohere)196 else: 197 print("no source directory", SASMODELS_SOURCE_PROLOG, "was found")194 fromhere = os.path.join(SASMODELS_SOURCE_PROLOG, files) 195 tohere = os.path.join(SASMODELS_DEST_PROLOG, files) 196 shutil.copy(fromhere, tohere) 197 else: 198 print("no source directory", SASMODELS_SOURCE_PROLOG, "was found") 198 199 199 200 if os.path.exists(SASMODELS_SOURCE_GPU): … … 204 205 for files in os.listdir(SASMODELS_SOURCE_GPU): 205 206 if files.endswith(".rst"): 206 fromhere =os.path.join(SASMODELS_SOURCE_GPU,files)207 tohere =os.path.join(SPHINX_SOURCE_USER,files)208 shutil.copy(fromhere, tohere)209 else: 210 print("no source directory", SASMODELS_SOURCE_GPU,"was found")207 fromhere = os.path.join(SASMODELS_SOURCE_GPU, files) 208 tohere = os.path.join(SPHINX_SOURCE_USER, files) 209 shutil.copy(fromhere, tohere) 210 else: 211 print("no source directory", SASMODELS_SOURCE_GPU, "was found") 211 212 212 213 if os.path.exists(SASMODELS_SOURCE_SESANS): … … 217 218 for files in os.listdir(SASMODELS_SOURCE_SESANS): 218 219 if files.endswith(".rst"): 219 fromhere =os.path.join(SASMODELS_SOURCE_SESANS,files)220 tohere =os.path.join(SPHINX_SOURCE_USER,files)221 shutil.copy(fromhere, tohere)222 else: 223 print("no source directory", SASMODELS_SOURCE_SESANS,"was found")220 fromhere = os.path.join(SASMODELS_SOURCE_SESANS, files) 221 tohere = os.path.join(SPHINX_SOURCE_USER, files) 222 shutil.copy(fromhere, tohere) 223 else: 224 print("no source directory", SASMODELS_SOURCE_SESANS, "was found") 224 225 225 226 if os.path.exists(SASMODELS_SOURCE_MAGNETISM): … … 230 231 for files in os.listdir(SASMODELS_SOURCE_MAGNETISM): 231 232 if files.endswith(".rst"): 232 fromhere =os.path.join(SASMODELS_SOURCE_MAGNETISM,files)233 tohere =os.path.join(SASMODELS_DEST_REF_MODELS,files)234 shutil.copy(fromhere, tohere)235 else: 236 print("no source directory", SASMODELS_SOURCE_MAGNETISM,"was found")233 fromhere = os.path.join(SASMODELS_SOURCE_MAGNETISM, files) 234 tohere = os.path.join(SASMODELS_DEST_REF_MODELS, files) 235 shutil.copy(fromhere, tohere) 236 else: 237 print("no source directory", SASMODELS_SOURCE_MAGNETISM, "was found") 237 238 238 239 if os.path.exists(SASMODELS_SOURCE_MAGIMG): … … 244 245 print("Copying sasmodels mag image files...") 245 246 for files in os.listdir(SASMODELS_SOURCE_MAGIMG): 246 fromhere =os.path.join(SASMODELS_SOURCE_MAGIMG,files)247 tohere =os.path.join(SASMODELS_DEST_MAGIMG,files)248 shutil.copy(fromhere, tohere)249 else: 250 print("no source directory", SASMODELS_SOURCE_MAGIMG ,"was found")247 fromhere = os.path.join(SASMODELS_SOURCE_MAGIMG, files) 248 tohere = os.path.join(SASMODELS_DEST_MAGIMG, files) 249 shutil.copy(fromhere, tohere) 250 else: 251 print("no source directory", SASMODELS_SOURCE_MAGIMG, "was found") 251 252 252 253 if os.path.exists(SASMODELS_SOURCE_SESANSIMG): … … 258 259 print("Copying sasmodels sesans image files...") 259 260 for files in os.listdir(SASMODELS_SOURCE_SESANSIMG): 260 fromhere =os.path.join(SASMODELS_SOURCE_SESANSIMG,files)261 tohere =os.path.join(SASMODELS_DEST_SESANSIMG,files)262 shutil.copy(fromhere, tohere)263 else: 264 print("no source directory", SASMODELS_SOURCE_SESANSIMG ,"was found")261 fromhere = os.path.join(SASMODELS_SOURCE_SESANSIMG, files) 262 tohere = os.path.join(SASMODELS_DEST_SESANSIMG, files) 263 shutil.copy(fromhere, tohere) 264 else: 265 print("no source directory", SASMODELS_SOURCE_SESANSIMG, "was found") 265 266 266 267 if os.path.exists(SASMODELS_SOURCE_REF_MODELS): … … 271 272 for files in os.listdir(SASMODELS_SOURCE_REF_MODELS): 272 273 if files.endswith(".rst"): 273 fromhere =os.path.join(SASMODELS_SOURCE_REF_MODELS,files)274 tohere =os.path.join(SASMODELS_DEST_REF_MODELS,files)275 shutil.copy(fromhere, tohere)274 fromhere = os.path.join(SASMODELS_SOURCE_REF_MODELS, files) 275 tohere = os.path.join(SASMODELS_DEST_REF_MODELS, files) 276 shutil.copy(fromhere, tohere) 276 277 # But need to change the path to the model docs in the tocs 277 278 for files in os.listdir(SASMODELS_DEST_REF_MODELS): … … 279 280 if files.startswith("shape"): 280 281 print("Changing toc paths in", files) 281 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/")282 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/") 282 283 if files.startswith("sphere"): 283 284 print("Changing toc paths in", files) 284 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/")285 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/") 285 286 if files.startswith("custom"): 286 287 print("Changing toc paths in", files) 287 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/")288 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/") 288 289 if files.startswith("structure"): 289 290 print("Changing toc paths in", files) 290 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/")291 else: 292 print("no source directory", SASMODELS_SOURCE_REF_MODELS," was found")291 inplace_change(os.path.join(SASMODELS_DEST_REF_MODELS, files), "../../model/", "models/") 292 else: 293 print("no source directory", SASMODELS_SOURCE_REF_MODELS, " was found") 293 294 294 295 if os.path.exists(SASMODELS_SOURCE_MODELS): … … 299 300 for files in os.listdir(SASMODELS_SOURCE_MODELS): 300 301 if files.endswith(".rst"): 301 fromhere =os.path.join(SASMODELS_SOURCE_MODELS,files)302 tohere =os.path.join(SASMODELS_DEST_MODELS,files)303 shutil.copy(fromhere, tohere)302 fromhere = os.path.join(SASMODELS_SOURCE_MODELS, files) 303 tohere = os.path.join(SASMODELS_DEST_MODELS, files) 304 shutil.copy(fromhere, tohere) 304 305 else: 305 306 print("Missing docs folder SASMODELS_DEST_MODELS at", SASMODELS_DEST_MODELS) … … 311 312 for files in os.listdir(SASMODELS_SOURCE_MODELS): 312 313 if files.endswith(".rst"): 313 fromhere =os.path.join(SASMODELS_SOURCE_MODELS,files)314 tohere =os.path.join(SASMODELS_DEST_MODELS,files)315 shutil.copy(fromhere, tohere)314 fromhere = os.path.join(SASMODELS_SOURCE_MODELS, files) 315 tohere = os.path.join(SASMODELS_DEST_MODELS, files) 316 shutil.copy(fromhere, tohere) 316 317 # No choice but to do this because model files are all coded for images in /models/img 317 318 print("Copying image files for build...") 318 319 for files in os.listdir(SASMODELS_DEST_IMG): 319 fromhere =os.path.join(SASMODELS_DEST_IMG,files)320 tohere =os.path.join(SASMODELS_DEST_BUILDIMG,files)321 shutil.copy(fromhere, tohere)322 else: 323 print("no source directory", SASMODELS_SOURCE_MODELS,"was found.")320 fromhere = os.path.join(SASMODELS_DEST_IMG, files) 321 tohere = os.path.join(SASMODELS_DEST_BUILDIMG, files) 322 shutil.copy(fromhere, tohere) 323 else: 324 print("no source directory", SASMODELS_SOURCE_MODELS, "was found.") 324 325 print("!!!!NO MODEL DOCS WILL BE BUILT!!!!") 325 326
Note: See TracChangeset
for help on using the changeset viewer.