def post_metrics(self, kind, layer_name, fetched): if self.hide_metrics: return conf_file = path('~/.config/charm-build.conf').expanduser() if conf_file.exists(): conf = yaml.safe_load(conf_file.text()) cid = conf['cid'] else: conf_file.parent.makedirs_p() cid = str(uuid.uuid4()) conf_file.write_text(yaml.dump({'cid': cid})) try: requests.post(self.METRICS_URL, timeout=10, data={ 'tid': self.METRICS_ID, 'v': 1, 'aip': 1, 't': 'event', 'ds': 'app', 'cid': cid, 'av': format_version(cached_charm_tools_version(), 'long'), 'an': "charm-build", 'ec': kind, 'ea': 'fetch' if fetched else 'local', 'el': layer_name, 'cd1': self.series, }) except requests.exceptions.RequestException: pass
def post_metrics(self, kind, layer_name, fetched): if self.hide_metrics: return conf_file = path('~/.config/charm-build.conf').expanduser() try: conf = yaml.safe_load(conf_file.text()) or {} except (FileNotFoundError, yaml.error.YAMLError): conf = {} if not conf.get('cid'): conf_file.parent.makedirs_p() conf['cid'] = str(uuid.uuid4()) conf_file.write_text(yaml.safe_dump(conf)) cid = conf['cid'] try: requests.post(self.METRICS_URL, timeout=10, data={ 'tid': self.METRICS_ID, 'v': 1, 'aip': 1, 't': 'event', 'ds': 'app', 'cid': cid, 'av': format_version(cached_charm_tools_version(), 'long'), 'an': "charm-build", 'ec': kind, 'ea': 'fetch' if fetched else 'local', 'el': layer_name, 'cd1': self.series, }) except requests.exceptions.RequestException: pass