~adam-collard/charm-helpers/fix-amulet-utils-validate-services-by-name

« back to all changes in this revision

Viewing changes to charmhelpers/core/hookenv.py

  • Committer: Matthew Bruzek
  • Date: 2015-08-04 21:56:24 UTC
  • mfrom: (421.1.1 charm-helpers)
  • Revision ID: matthew.bruzek@canonical.com-20150804215624-qo2mlp54s8fs62o4
[johnsca] Removed import of cli in hookenv, as it was causing issues when charmhelpers is partially sync'd and CLI not included.

Also removed broken attempt to support **kwargs in cmdline.run()

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
import tempfile
35
35
from subprocess import CalledProcessError
36
36
 
37
 
try:
38
 
    from charmhelpers.cli import cmdline
39
 
except ImportError as e:
40
 
    # due to the anti-pattern of partially synching charmhelpers directly
41
 
    # into charms, it's possible that charmhelpers.cli is not available;
42
 
    # if that's the case, they don't really care about using the cli anyway,
43
 
    # so mock it out
44
 
    if str(e) == 'No module named cli':
45
 
        class cmdline(object):
46
 
            @classmethod
47
 
            def subcommand(cls, *args, **kwargs):
48
 
                def _wrap(func):
49
 
                    return func
50
 
                return _wrap
51
 
    else:
52
 
        raise
53
 
 
54
37
import six
55
38
if not six.PY3:
56
39
    from UserDict import UserDict
91
74
        res = func(*args, **kwargs)
92
75
        cache[key] = res
93
76
        return res
 
77
    wrapper._wrapped = func
94
78
    return wrapper
95
79
 
96
80
 
190
174
    return os.environ.get('JUJU_RELATION', None)
191
175
 
192
176
 
193
 
@cmdline.subcommand()
194
177
@cached
195
178
def relation_id(relation_name=None, service_or_unit=None):
196
179
    """The relation ID for the current or a specified relation"""
216
199
    return os.environ.get('JUJU_REMOTE_UNIT', None)
217
200
 
218
201
 
219
 
@cmdline.subcommand()
220
202
def service_name():
221
203
    """The name service group this unit belongs to"""
222
204
    return local_unit().split('/')[0]
223
205
 
224
206
 
225
 
@cmdline.subcommand()
226
207
@cached
227
208
def remote_service_name(relid=None):
228
209
    """The remote service name for a given relation-id (or the current relation)"""