1
# -*- coding: utf-8; Mode: Python; indent-tabs-mode: nil; tab-width: 4 -*-
3
# Copyright (C) 2018 Canonical Ltd.
5
# Functions useful for the final install.py script and for ubiquity
8
# This program is free software; you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation; either version 2 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program; if not, write to the Free Software
20
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29
from ubiquity.misc import raise_privileges
31
START_INSTALL_STAGE_TAG = 'start_install'
35
"""Return a singleton _Telemetry instance."""
36
if _Telemetry._telemetry is None:
37
_Telemetry._telemetry = _Telemetry()
38
return _Telemetry._telemetry
47
self._stages_hist = {}
48
self._start_time = time.time()
49
self.add_stage('start')
50
self._dest_path = '/target/var/log/installer/telemetry'
52
with open('/cdrom/.disk/info') as f:
53
self._metrics['Media'] = f.readline()
54
except FileNotFoundError:
55
self._metrics['Media'] = 'unknown'
57
def add_stage(self, stage_name):
58
"""Record installer stage with current time"""
59
self._stages_hist[int(time.time() - self._start_time)] = stage_name
61
def set_installer_type(self, installer_type):
62
"""Record installer type"""
63
self._metrics['Type'] = installer_type
65
def set_partition_method(self, method):
66
"""Record anynomized partition method"""
67
self._metrics['PartitionMethod'] = method
71
"""Close telemetry collection
73
Set as installation done, add additional info and save to
75
self.add_stage('done')
77
self._metrics['DownloadUpdates'] = db.get('ubiquity/download_updates')
78
self._metrics['Language'] = db.get('localechooser/languagelist')
79
self._metrics['Minimal'] = db.get('ubiquity/minimal_install')
80
self._metrics['RestrictedAddons'] = db.get('ubiquity/use_nonfree')
81
self._metrics['Stages'] = self._stages_hist
83
target_dir = os.path.dirname(self._dest_path)
85
if not os.path.exists(target_dir):
86
os.makedirs(target_dir)
87
with open(self._dest_path, 'w') as f:
88
json.dump(self._metrics, f)
89
os.chmod(self._dest_path,
90
stat.S_IRUSR | stat.S_IWUSR |
91
stat.S_IRGRP | stat.S_IROTH)
93
syslog.syslog(syslog.LOG_ERR,
94
"Exception while storing telemetry data: " + str(e))
96
# vim:ai:et:sts=4:tw=80:sw=4: