~ajkavanagh/charms/trusty/mongodb/fix-unit-test-lint-lp1533654

« back to all changes in this revision

Viewing changes to hooks/hooks.py

  • Committer: james.page at ubuntu
  • Date: 2015-04-22 14:14:10 UTC
  • mfrom: (67.1.1 mongodb)
  • Revision ID: james.page@ubuntu.com-20150422141410-pxuh12coj6z8akvb
Ensure yaml library is usable

Newer Ubuntu versions don't have python-yaml installed by default.

Handle this automatically in the charm.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
import subprocess
14
14
import sys
15
15
import time
16
 
import yaml
 
16
 
 
17
try:
 
18
    import yaml  # flake8: noqa
 
19
except ImportError:
 
20
    if sys.version_info.major == 2:
 
21
        subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml'])
 
22
    else:
 
23
        subprocess.check_call(['apt-get', 'install', '-y', 'python3-yaml'])
 
24
    import yaml  # flake8: noqa
17
25
 
18
26
from os import chmod
19
27
from os import remove