Back to home page

OSCL-LXR

 
 

    


0001 # -*- coding: utf-8; mode: python -*-
0002 # pylint: disable=R0903, C0330, R0914, R0912, E0401
0003 
0004 import os
0005 import sys
0006 from sphinx.util.pycompat import execfile_
0007 
0008 # ------------------------------------------------------------------------------
0009 def loadConfig(namespace):
0010 # ------------------------------------------------------------------------------
0011 
0012     u"""Load an additional configuration file into *namespace*.
0013 
0014     The name of the configuration file is taken from the environment
0015     ``SPHINX_CONF``. The external configuration file extends (or overwrites) the
0016     configuration values from the origin ``conf.py``.  With this you are able to
0017     maintain *build themes*.  """
0018 
0019     config_file = os.environ.get("SPHINX_CONF", None)
0020     if (config_file is not None
0021         and os.path.normpath(namespace["__file__"]) != os.path.normpath(config_file) ):
0022         config_file = os.path.abspath(config_file)
0023 
0024         # Let's avoid one conf.py file just due to latex_documents
0025         start = config_file.find('Documentation/')
0026         if start >= 0:
0027             start = config_file.find('/', start + 1)
0028 
0029         end = config_file.rfind('/')
0030         if start >= 0 and end > 0:
0031             dir = config_file[start + 1:end]
0032 
0033             print("source directory: %s" % dir)
0034             new_latex_docs = []
0035             latex_documents = namespace['latex_documents']
0036 
0037             for l in latex_documents:
0038                 if l[0].find(dir + '/') == 0:
0039                     has = True
0040                     fn = l[0][len(dir) + 1:]
0041                     new_latex_docs.append((fn, l[1], l[2], l[3], l[4]))
0042                     break
0043 
0044             namespace['latex_documents'] = new_latex_docs
0045 
0046         # If there is an extra conf.py file, load it
0047         if os.path.isfile(config_file):
0048             sys.stdout.write("load additional sphinx-config: %s\n" % config_file)
0049             config = namespace.copy()
0050             config['__file__'] = config_file
0051             execfile_(config_file, config)
0052             del config['__file__']
0053             namespace.update(config)
0054         else:
0055             config = namespace.copy()
0056             config['tags'].add("subproject")
0057             namespace.update(config)