~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:37:14 UTC
  • Revision ID: adam.collard@canonical.com-20190405103714-4jc62zibnrygxrw9
Minor clean-up

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
5
7
import re
 
8
import subprocess
6
9
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
 
        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]
 
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))
23
25
        self.name = charm_name
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)
 
26
        self.store_url = charm_data.get("id", {}).get("Id")
29
27
 
30
28
 
31
29
def _get_charm(charm_name, series):
92
90
    for filename in glob("*.jinja2"):
93
91
        replace_in_config(filename, charms, series=options.series)
94
92
 
95
 
    sys.exit(0)
96
93
 
97
94
if __name__ == "__main__":
98
 
    main()
 
95
    sys.exit(main())