source: TI03-DataExtractor/branches/repackaging/server/ndg/dx/server/MakeConfig.py @ 1848

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI03-DataExtractor/branches/repackaging/server/ndg/dx/server/MakeConfig.py
Revision 1848, 1.4 KB checked in by spascoe, 14 years ago (diff)

Script hook into the test_suite.

Line 
1"""
2Set up the DX server directory structure inside $NDG_HOME.
3
4@author: Stephen Pascoe
5"""
6
7import os, shutil, pkg_resources
8
9def makeConfig():
10    """If the $NDG_HOME/dxs does not exist create it by copying the default
11    from the egg.
12    """
13    from ndg.utils.config import NDG_HOME
14
15    if os.path.exists(os.path.join(NDG_HOME, 'dxs')):
16        return
17
18    # Get the dxs configuration directory
19    dxsPath = pkg_resources.resource_filename('ndg.dx.server', 'dxs')
20    shutil.copytree(dxsPath, os.path.join(NDG_HOME, 'dxs'))
21    # Clean-up dxsPath if it's been extracted to the cache.
22    pkg_resources.cleanup_resources()
23           
24def makeTestHome(test_home, test_conf=None):
25    # Set NDG_HOME to be picked up by ndg.utils.config
26    os.environ['NDG_HOME'] = test_home
27
28    # Wipe clean self.test_home
29    if os.path.exists(test_home):
30        shutil.rmtree(test_home)
31    os.mkdir(test_home)
32   
33    # At this point it is safe to import the configuration.
34    # get global configuration (this will read /etc/ndg.conf)
35    from ndg.utils.config import config
36   
37    # parse selected test_conf
38    if test_conf:
39        config.read(test_conf)
40    else:
41        fp = pkg_resources.resource_stream('ndg.dx.server.test', 'server.conf')
42        config.readfp(fp)
43       
44    # Set BASEDIR and create the dxs directory
45    config.set('ndg.dx.server', 'basedir', os.path.join(test_home, 'dxs'))
46    makeConfig()
Note: See TracBrowser for help on using the repository browser.