4
from os.path import join as path_join
5
from os.path import exists as path_exists
7
from juju_deployer import utils
9
from juju_deployer.vcs import Bzr, Git
14
log = logging.getLogger('deployer.charm')
16
def __init__(self, name, path, branch, rev, build, charm_url=""):
21
self._charm_url = charm_url
23
self.vcs = self.get_vcs()
28
if self.branch.startswith('git') or 'github.com' in self.branch:
29
return Git(self.path, self.branch, self.log)
30
elif self.branch.startswith("bzr") or self.branch.startswith('lp:'):
31
return Bzr(self.path, self.branch, self.log)
34
def from_service(cls, name, series_path, d):
35
branch, rev = None, None
36
charm_branch = d.get('branch')
37
if charm_branch is not None:
38
branch, sep, rev = charm_branch.partition('@')
39
name = d.get('charm', name)
40
charm_path = path_join(series_path, name)
41
build = d.get('build', '')
42
store_url = d.get('charm_url', None)
44
if store_url and branch:
46
"Service: %s has both charm url: %s and branch: %s specified",
47
name, store_url, branch)
48
return cls(name, charm_path, branch, rev, build, store_url)
51
return path_exists(self.path)
53
def is_subordinate(self):
54
return self.metadata.get('subordinate', False)
59
return self._charm_url
60
series = os.path.basename(os.path.dirname(self.path))
61
return "local:%s/%s" % (series, self.name)
64
#if self.charm_url.startswith('cs:'):
65
# shutil.copy(urllib.urlopen(CHARM_DL_URL % self.charm_url))
68
self.log.debug("Building charm %s with %s", self.path, self._build)
69
_check_call([self._build], self.path, self.log,
70
"Charm build failed %s @ %s", self._build, self.path)
75
self.log.debug(" Branching charm %s @ %s", self.branch, self.path)
79
def update(self, build=False):
83
self.log.debug(" Updating charm %s from %s", self.path, self.branch)
84
self.vcs.update(self.rev)
88
def is_modified(self):
91
return self.vcs.is_modified()
95
config_path = path_join(self.path, "config.yaml")
96
if not path_exists(config_path):
99
with open(config_path) as fh:
100
return utils.yaml_load(fh.read()).get('options', {})
104
md_path = path_join(self.path, "metadata.yaml")
105
if not path_exists(md_path):
106
if not path_exists(self.path):
107
raise RuntimeError("No charm metadata @ %s", md_path)
108
with open(md_path) as fh:
109
return utils.yaml_load(fh.read())
111
def get_provides(self):
112
p = {'juju-info': [{'name': 'juju-info'}]}
113
for key, value in self.metadata['provides'].items():
115
p.setdefault(value['interface'], []).append(value)
118
def get_requires(self):
120
for key, value in self.metadata['requires'].items():
122
r.setdefault(value['interface'], []).append(value)