~landscape/landscape-bundles/trunk

« back to all changes in this revision

Viewing changes to update-charm-revisions

  • Committer: Adam Collard
  • Date: 2019-04-05 10:38:41 UTC
  • Revision ID: adam.collard@canonical.com-20190405103841-lqm7dqtwl1ixyqrs
Revert r48

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
import argparse
4
4
import fileinput
5
 
from glob import glob
6
 
import json
7
5
import re
8
 
import subprocess
9
6
import sys
 
7
from urllib.request import urlopen
 
8
from yaml import load
 
9
from glob import glob
10
10
 
11
11
 
12
12
class Charm(object):
16
16
        @param charm_name: name of charm
17
17
        """
18
18
        reference = "cs:{}/{}".format(series, charm_name)
19
 
        json_info = subprocess.check_output(
20
 
            ["charm", "show", "--format=json", reference, "id"])
21
 
        charm_data = json.loads(json_info)
22
 
        self.revision = charm_data.get("id", {}).get("Revision")
23
 
        if self.revision is None:
24
 
            raise IOError("{}: {}".format(charm_name, charm_data))
 
19
        base_url = "https://store.juju.ubuntu.com/charm-info?charms="
 
20
        url = "{}{}".format(base_url, reference)
 
21
        response = urlopen(url)
 
22
        self.charm_data = load(response)[reference]
25
23
        self.name = charm_name
26
 
        self.store_url = charm_data.get("id", {}).get("Id")
 
24
        if "errors" in self.charm_data:
 
25
            raise IOError("{}: {}".format(
 
26
                charm_name, self.charm_data["errors"]))
 
27
        self.revision = self.charm_data["revision"]
 
28
        self.store_url = "cs:{}/{}-{}".format(series, self.name, self.revision)
27
29
 
28
30
 
29
31
def _get_charm(charm_name, series):
90
92
    for filename in glob("*.jinja2"):
91
93
        replace_in_config(filename, charms, series=options.series)
92
94
 
 
95
    sys.exit(0)
93
96
 
94
97
if __name__ == "__main__":
95
 
    sys.exit(main())
 
98
    main()