~abentley/charms/precise/juju-reports/develop-install

« back to all changes in this revision

Viewing changes to hooks/common.py

  • Committer: j.c.sackett
  • Date: 2014-02-11 20:19:28 UTC
  • Revision ID: jcsackett@canonical.com-20140211201928-iw8z39pmos1augeu
Update ini instead of deleting and reinstalling from template.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from ConfigParser import ConfigParser
 
2
import os
 
3
import subprocess
 
4
 
 
5
 
1
6
CHARM_DIR = os.getcwd()
2
 
 
3
 
 
4
 
PROJECT_DIR = '/home/ubuntu/juju-reports'
5
 
 
6
 
 
 
7
HOME = '/home/ubuntu'
 
8
PROJECT_DIR = os.path.join(HOME, 'juju-reports')
7
9
INI = 'production.ini'
8
10
 
9
11
 
13
15
        fn(*args)
14
16
        os.chdir(CHARM_DIR)
15
17
    return dec_fn
 
18
 
 
19
 
 
20
def update_or_install_ini(mongo_url=None):
 
21
    ini_file = os.path.join(PROJECT_DIR, INI)
 
22
    config = ConfigParser()
 
23
    config.read([ini_file])
 
24
    if mongo_url:
 
25
        config.set('app:main', 'mongo.url', mongo_url)
 
26
    config.write(file(ini_file, 'w'))
 
27
 
 
28
 
 
29
@in_juju_reports
 
30
def restart():
 
31
    env = os.environ.copy()
 
32
    env['HOME'] = HOME
 
33
    subprocess.check_call(['scripts/stop'], env=env)
 
34
    subprocess.check_call(['scripts/run'], env=env)
 
35