Beispiel #1
0
    def test_get_vars_ignores_unexported_vars(self):
        with tempscript("""export VAR1=1
VAR2=2
export VAR3=3
""") as f:
            vars = shellvars.get_vars(f.name)
            self.assertEqual(vars, {'VAR1': '1', 'VAR3': '3'})
    def test_get_vars_ignores_unexported_vars(self):
        with tempscript("""export VAR1=1
VAR2=2
export VAR3=3
""") as f:
            vars = shellvars.get_vars(f.name)
            self.assertEqual(vars, {'VAR1':'1', 'VAR3':'3'})
    def test_get_multiline_value(self):
        with tempscript("""#!/bin/bash
# this is an example shell script
export VAR1=1

export VAR2="This
is

an example of a multiline var which contains an equation
VAR1=not_1"

export VAR3=123
        """) as f:
            vars = shellvars.get_vars(f.name)
            self.assertEqual(vars, {
                'VAR1': '1',
                'VAR2': """This
is

an example of a multiline var which contains an equation
VAR1=not_1""",
                'VAR3': '123'
            })
Beispiel #4
0
    def test_get_multiline_value(self):
        with tempscript("""#!/bin/bash
# this is an example shell script
export VAR1=1

export VAR2="This
is

an example of a multiline var which contains an equation
VAR1=not_1"

export VAR3=123
        """) as f:
            vars = shellvars.get_vars(f.name)
            self.assertEqual(
                vars, {
                    'VAR1': '1',
                    'VAR2': """This
is

an example of a multiline var which contains an equation
VAR1=not_1""",
                    'VAR3': '123'
                })
current_directory = os.path.dirname(os.path.abspath(__file__))

## vars
ACTIVATE_FILE = os.path.abspath( u'%s/../../env_min_djng/bin/activate_this.py' % current_directory )
PROJECT_DIR = os.path.abspath( u'%s/../../django_template_project' % current_directory )
PROJECT_ENCLOSING_DIR = os.path.abspath( u'%s/../..' % current_directory )
SETTINGS_MODULE = u'config.settings'
SITE_PACKAGES_DIR = os.path.abspath( u'%s/../../env_min_djng/lib/python2.7/site-packages' % current_directory )

## virtualenv
execfile( ACTIVATE_FILE, dict(__file__=ACTIVATE_FILE) )

## sys.path additions
for entry in [PROJECT_DIR, PROJECT_ENCLOSING_DIR, SITE_PACKAGES_DIR]:
 if entry not in sys.path:
   sys.path.append( entry )

## environment additions
os.environ[u'DJANGO_SETTINGS_MODULE'] = SETTINGS_MODULE  # so django can access its settings

## load up env vars
SETTINGS_FILE = os.environ['DJANGO_TEMPLATE__SETTINGS_PATH']  # set in activate_this.py, and activated above
import shellvars
var_dct = shellvars.get_vars( SETTINGS_FILE )
for ( key, val ) in var_dct.items():
    os.environ[key] = val

## gogogo
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
Beispiel #6
0
from sys import path

SITE_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SETTINGS_MODULE = u'iip_config.settings'

## update path
path.append(SITE_ROOT)

## activate venv
activate_this = os.path.join(os.path.dirname(SITE_ROOT),
                             'env_iip/bin/activate_this.py')
execfile(activate_this, dict(__file__=activate_this))

## reference django settings
os.environ[
    u'DJANGO_SETTINGS_MODULE'] = SETTINGS_MODULE  # so django can access its settings

## load up env vars
SETTINGS_FILE = os.environ[
    'IIP__SETTINGS_PATH']  # set in activate_this.py, and activated above
import shellvars

var_dct = shellvars.get_vars(SETTINGS_FILE)
for (key, val) in var_dct.items():
    os.environ[key] = val

## gogogo
from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()
#!/usr/bin/env python

import os
from collections import OrderedDict
import shellvars
try:
    from ConfigParser import RawConfigParser
except ImportError:  # ver. < 3.0
    from ConfigParser import RawConfigParser


vars = shellvars.get_vars('grange-env.sh')
cfg=vars["GRANGE_SERVER_CONFIG"]

# instantiate
class MultiOrderedDict(OrderedDict):
    def __setitem__(self, key, value):
        if isinstance(value, list) and key in self:
            self[key].extend(value)
        else:
            super(OrderedDict, self).__setitem__(key, value)

config = RawConfigParser(dict_type=MultiOrderedDict)

# parse existing file
config.read(cfg)

section="rangeserver"

# read values from a section
loglevel = config.get(section, 'loglevel')