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

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

Moved test_home creation code into the package so that it can be run when
deployed.

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    # At this point it is safe to import the configuration.
29    # get global configuration (this will read /etc/ndg.conf)
30    from ndg.utils.config import config
31   
32    # parse selected test_conf
33    if test_conf:
34        config.read(test_conf)
35    else:
36        fp = pkg_resources.resource_stream('ndg.dx.server.test', 'server.conf')
37        config.readfp(fp)
38       
39    # Set BASEDIR and create the dxs directory
40    config.set('ndg.dx.server', 'basedir', os.path.join(test_home, 'dxs'))
41    makeConfig()
Note: See TracBrowser for help on using the repository browser.